美文网首页
redis主备搭建以及测试

redis主备搭建以及测试

作者: 斜月86 | 来源:发表于2018-11-26 16:20 被阅读0次

0 redis下载

yum -y install gcc automake autoconf libtool make

wget http://download.redis.io/releases/redis-4.0.11.tar.gz
tar -xvf redis-4.0.11.tar.gz
cd redis-4.0.11
make 

1、需要准备的文件如下

mkdir conf 放入配置文件
## redis 配置文件
redis-6379.conf  
redis-6380.conf  
redis-6381.conf 
## sentinel配置文件
sentinel-26379.conf  
sentinel-26380.conf  
sentinel-26381.conf

## start

## 启动redis
./redis-4.0.11/src/redis-server conf/redis-6379.conf
./redis-4.0.11/src/redis-server conf/redis-6380.conf
./redis-4.0.11/src/redis-server conf/redis-6381.conf 

## 启动sentinel
./redis-4.0.11/src/redis-sentinel conf/sentinel-26379.conf
./redis-4.0.11/src/redis-sentinel conf/sentinel-26380.conf 
./redis-4.0.11/src/redis-sentinel conf/sentinel-26381.conf 

redis-6379 配置内容

protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile "/var/run/redis_6379.pid"
loglevel notice
logfile "6379.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump-6379.rdb"
dir "/root"
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
##连接密码
requirepass foobared
masterauth foobared
appendonly no
appendfilename "appendonly-6379.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

redis-6380.conf配置

protected-mode no
port 6380
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile "/var/run/redis_6380.pid"
loglevel notice
logfile "6380.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump-6380.rdb"
dir "/root"
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename "appendonly-6380.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
slaveof 192.168.101.79 6381
requirepass "foobared"
masterauth "foobared"

redis-6381.conf

protected-mode no
port 6381
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile "/var/run/redis_6381.pid"
loglevel notice
logfile "6381.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump-6381.rdb"
dir "/root"
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename "appendonly-6381.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
requirepass "foobared"
masterauth "foobared"

sentinel-26379.conf

port 26379
dir "/tmp"
daemonize yes
protected-mode no
logfile "26379.log"
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster 192.168.101.79 6379 2
sentinel down-after-milliseconds mymaster 10000
sentinel auth-pass mymaster foobared

sentinel-26380.conf

port 26380
dir "/tmp"
daemonize yes
protected-mode no
logfile "26380.log"
sentinel monitor mymaster 192.168.101.79 6379 2
sentinel down-after-milliseconds mymaster 10000
sentinel auth-pass mymaster foobared

sentinel-26381.conf

port 26381
dir "/tmp"
daemonize yes
protected-mode no
logfile "26381.log"
sentinel monitor mymaster 192.168.101.79 6379 2
sentinel down-after-milliseconds mymaster 10000
sentinel auth-pass mymaster foobared

2 java 连接测试


        JedisPoolConfig pool = new JedisPoolConfig();
        pool.setTestOnReturn(true);
        pool.setMaxWaitMillis(10000);
        pool.setMaxIdle(3);
        pool.setMaxWaitMillis(10000);
        pool.setMaxTotal(200);

        //声明一个set 存放哨兵集群的地址和端口
        Set<String> sentinels = new HashSet<String>();
        sentinels.add("192.168.101.79:26379");
        sentinels.add("192.168.101.79:26380");
        sentinels.add("192.168.101.79:26381");
        // 名称 sentinel pool timeout auth
        JedisSentinelPool sentinelPool = new JedisSentinelPool("mymaster", sentinels, pool,2000,"foobared");
        // 使用sentinelPool获取jedis对象
        Jedis jedis = sentinelPool.getResource();
        jedis.set("dddddd","fffff");
        System.out.println(jedis.get("dddddd"));

相关文章

  • redis主备搭建以及测试

    0 redis下载 1、需要准备的文件如下 redis-6379 配置内容 redis-6380.conf配置 r...

  • Redis 主备搭建

    Redis 主备搭建 在之前的文章中已经描述怎么样来搭建 redis 的高可用服务,但是在实际使用中由于 spri...

  • 二十一周作业

    1、搭建redis,实现redis的复制管理 测试环境: 所有机器均为centos7.6 Redis主:172.1...

  • 第二十二周

    1、搭建redis,实现redis的复制管理 测试环境: 所有机器均为centos7.6 Redis主:172.1...

  • 主备和集群

    今天来聊聊,什么是主备,什么是集群,什么是节点 主备主备多用来数据库场景,比如:mysql主备,redis主备等等...

  • mysql(mariadb)数据库主备同步

    笔者搭建mysql(mariadb)主从复制服务,测试主备同步正常。 主机master是windows 7 系统,...

  • Docker Redis Sentinel 高可用部署实践

    一、Redis Sentinel 介绍 1、Sentinel 数据库环境搭建,从单机版到主备、再到多数据库集群,我...

  • redis系列(十一):实战

    本公司redis使用一主一备多从读写分离 一主一备是什么 备就是主的从库。正常情况下备是没有流量的。当主挂掉了,备...

  • redis5.0 3主6从集群搭建

    redis5.0 --- 3主6从集群搭建 redis下载: https://redis.io/download ...

  • Redis主备节点

    Redis主备节点,怎么样防止数据不一致 从节点启动后,会向主节点发送slaveof命令,会进行一次全量同步: 1...

网友评论

      本文标题:redis主备搭建以及测试

      本文链接:https://www.haomeiwen.com/subject/cuvbqqtx.html