REDIS 单机多实例+哨兵模式

1 下载安装包

cd /usr/local/src
wget http://download.redis.io/releases/redis-5.0.2.tar.gz

2 解压

tar zxvf redis-5.0.2.tar.gz

3 安装依赖包

yum -y install gcc gcc-c++

4 编译安装

cd redis-5.0.2

make MALLOC=libc && make install

5 配置redis 一主两从

[root@localhost redis-5.0.2]# cp redis.conf /etc/redis_6379.conf
[root@localhost redis-5.0.2]# cp redis.conf /etc/redis_6380.conf
[root@localhost redis-5.0.2]# cp redis.conf /etc/redis_6381.conf
主配置修改:redis_6379.conf

bind 0.0.0.0
replicaof 192.168.208.146

daemonize yes 后台守护
port 6379
从配置修改

=redis_6380.conf==

bind 0.0.0.0

daemonize yes 后台守护

port 6380
replicaof 192.168.208.146

replicaof 192.168.10.131 6379

replica-priority 100 优先级

redis_6381.conf

bind 0.0.0.0

daemonize yes 后台守护

port 6381
replicaof 192.168.208.146

replicaof 192.168.10.131 6379

replica-priority 90 优先级

6 运行服务
[root@localhost ~]# redis-server  /etc/redis_6379.conf
28308:C 18 Nov 2019 01:54:16.096 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
28308:C 18 Nov 2019 01:54:16.096 # Redis version=5.0.2, bits=64, commit=00000000, modified=0, pid=28308, just started
28308:C 18 Nov 2019 01:54:16.096 # Configuration loaded
[root@localhost ~]# redis-server  /etc/redis_6380.conf
28313:C 18 Nov 2019 01:54:23.078 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
28313:C 18 Nov 2019 01:54:23.078 # Redis version=5.0.2, bits=64, commit=00000000, modified=0, pid=28313, just started
28313:C 18 Nov 2019 01:54:23.078 # Configuration loaded
[root@localhost ~]# redis-server  /etc/redis_6381.conf
28320:C 18 Nov 2019 01:54:26.226 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
28320:C 18 Nov 2019 01:54:26.226 # Redis version=5.0.2, bits=64, commit=00000000, modified=0, pid=28320, just started
28320:C 18 Nov 2019 01:54:26.226 # Configuration loaded
28320:S 18 Nov 2019 01:54:26.230 # Creating Server TCP listening socket 0.0.0.0:6379: bind: Address already in use

7 验证主从

[root@localhost ~]# redis-cli -p 6379
127.0.0.1:6379> set wg01 xxoo
OK
从上取key 为wg01的信息
[root@localhost ~]# redis-cli -p 6380
127.0.0.1:6380> get wg01
“xxoo”
127.0.0.1:6380>
8 配置哨兵模式
[root@localhost redis-5.0.2]# pwd
/usr/local/src/redis-5.0.2
[root@localhost redis-5.0.2]# cp sentinel.conf /etc/sentinel_26379.conf
[root@localhost redis-5.0.2]# cp sentinel.conf /etc/sentinel_26380.conf
[root@localhost redis-5.0.2]# cp sentinel.conf /etc/sentinel_26381.conf
删除已#号开头的 :g/^#/d

删除空行 :g/^$/d

vim /etc/sentinel_26379.conf

port 26379
daemonize yes
pidfile /var/run/redis-sentinel.pid
logfile “/var/log/redis/sentinel_26379.log”
dir /tmp
sentinel monitor mymaster 192.168.10.131 6379 2#告诉sentinel去监听地址为ip:port的一个master,这里的master-name可以自定义,quorum是一个数字,指明当有多少个sentinel认为一个master失效时,#master才算真正失效
1
sentinel down-after-milliseconds mymaster 30000#这个配置项指定了需要多少失效时间,一个master才会被这个sentinel主观地认为是不可用的。 单位是毫秒,默认为30秒sentinel parallel-syncs mymaster 1 #这个配置项指定了在发生failover主备切换时最多可以有多少个slave同时对新的master进行 同步。#这个数字越小,完成failover所需的时间就越长,但是如果这个数字越大,就意味着越 多的slave因为replication而不可用。#可以通过将这个值设为 1 来保证每次只有一个slave 处于不能处理命令请求的状态。sentinel failover-timeout mymaster 180000 #当进行failover故障转移时,配置所有slaves指向新的master所需的最大时间sentinel deny-scripts-reconfig yes#避免脚本重置,默认值yes
vim /etc/sentinel_26380.conf
port 26380
daemonize no
pidfile /var/run/redis-sentinel_26380.pid
logfile “/var/log/redis/sentinel_26380.log”
dir /tmp
sentinel monitor mymaster 192.168.10.131 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
vim /etc/sentinel_26381.conf
port 26381
daemonize yes
pidfile /var/run/redis-sentinel_26381.pid
logfile “/var/log/redis/sentinel_26381.log”
dir /tmp
sentinel monitor mymaster 192.168.10.131 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
mkdir /var/log/redids

9 开启哨兵

redis-server /etc/sentinel_26379.conf --sentinel

redis-server /etc/sentinel_26380.conf --sentinel

redis-server /etc/sentinel_26381.conf --sentinel

10 验证
[root@localhost redis-5.0.2]# redis-cli -p 26379 info Sentinel
Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=192.168.10.131:6379,slaves=2,sentinels=3
kill 掉 6379端口

主成功转移
[root@localhost redis-5.0.2]# redis-cli -p 26379 info Sentinel
#Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=192.168.10.131:6381,slaves=2,sentinels=3

你可能感兴趣的:(REDIS 单机多实例+哨兵模式)