导读:一、配置哨兵服务.1、哨兵服务介绍.监视 master 服务器,发现 master 宕机后,将 slave 服务器提升为 master 服务器.主配置文件:sentinel.conf.模板文件:redis-4.0.8/sentinel.conf.哨兵服务:类似于mha的管理节点,
监视 master 服务器,发现 master 宕机后,将 slave 服务器提升为 master 服务器
主配置文件:sentinel.conf
模板文件:redis-4.0.8/sentinel.conf
哨兵服务:类似于mha的管理节点,会监视 master 服务器的状态,当发现 master 宕机后,将 slave 服务器提升为 master 服务器,继续提供对外服务
主从是8系统,哨兵服务器是7的系统
主服务器 主机名:Master IP地址:192.168.11.101/24
从服务器 主机名:node01 IP地址:192.168.11.102/24
从服务器 主机名:node02 IP地址:192.168.11.103/24
哨兵服务器 主机名:redis IP地址:192.168.11.110/24
root@Master:~# wget -c http://download.redis.io/releases/redis-4.0.8.tar.gz
root@Master:~# tar xf redis-4.0.8.tar.gz -C /usr/local/
root@Master:~# yum install gcc make -y
root@Master:~# cd /usr/local/redis-4.0.8/
root@Master:/usr/local/redis-4.0.8# ls
00-RELEASENOTES deps README.md runtest-sentinel utils
BUGS INSTALL redis.conf sentinel.conf
CONTRIBUTING Makefile runtest src
COPYING MANIFESTO runtest-cluster tests
root@Master:/usr/local/redis-4.0.8# make && make install
root@Master:/usr/local/redis-4.0.8/utils# yum update
root@Master:/usr/local/redis-4.0.8# make PREFIX=/usr/local install -d
[root@redis ~]# redis-cli
127.0.0.1:6379>
# 找到redis.conf配置文件,并使用vim命令打开并修改里面的配置,将daemonize no 修改为daemonize yes,这样默认在后台启动运行
root@Master:/usr/local/redis-4.0.8# pwd
/usr/local/redis-4.0.8
root@Master:/usr/local/redis-4.0.8# vim redis.conf
daemonize yes
# 开启服务
root@Master:/usr/local/redis-4.0.8# cd /usr/local/bin/
root@Master:/usr/local/bin# redis-server /usr/local/redis-4.0.8/redis.conf
53240:C 19 Apr 10:03:57.072 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
53240:C 19 Apr 10:03:57.072 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=53240, just started
53240:C 19 Apr 10:03:57.072 # Configuration loaded
root@Master:~# cd /usr/local/redis-4.0.8/utils/
root@Master:/usr/local/redis-4.0.8/utils# ./install_server.sh
root@Master:/usr/local/redis-4.0.8/utils# ss -lntup |grep 6379
tcp LISTEN 0 128 127.0.0.1:6379 0.0.0.0:* users:(("redis-server",pid=53241,fd=6))
root@Master:/usr/local/redis-4.0.8/utils# /etc/init.d/redis_6379 stopStopping ...
Redis stopped
root@Master:/usr/local/redis-4.0.8/utils# /etc/init.d/redis_6379 start
root@Master:~# /etc/init.d/redis_6379 stop
Stopping ...
Redis stopped
root@Master:~# find / -name 6379.conf
/etc/redis/6379.conf
/tmp/6379.conf
root@Master:~# vim /etc/redis/6379.conf
bind 192.168.11.101
root@Master:~# /etc/init.d/redis_6379 start
Starting Redis server...
root@Master:~# ss -lntup | grep 6379
tcp LISTEN 0 128 192.168.11.101:6379 0.0.0.0:* users:(("redis-server",pid=5932,fd=6))
root@Master:~# redis-cli -h 192.168.11.101 -p 6379
192.168.11.101:6379> ping
PONG
192.168.11.101:6379> MSET x 777 y 888 z 999
OK
192.168.11.101:6379> KEYS *
1) "x"
2) "z"
3) "y"
# 查看当前服务器的主从信息
192.168.11.101:6379> INFO replication
# Replication
role:master # 主服务器
connected_slaves:0
master_replid:411c9094667d6e89f596641bd0f360b7c729cd6f
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
192.168.11.101:6379>
root@node01:~# /etc/init.d/redis_6379 stop
Stopping ...
Redis stopped
root@node01:~# vim /etc/redis/6379.conf
bind 192.168.11.102
slaveof 192.168.11.101 6379
root@node01:~# /etc/init.d/redis_6379 start
Starting Redis server...
root@node01:~# redis-cli -h 192.168.11.102
192.168.11.102:6379> ping
PONG
192.168.11.102:6379>
# 查看主服务器上的数据是否同步
192.168.11.102:6379> KEYS *
1) "x"
2) "z"
3) "y"
192.168.11.102:6379> INFO replication
# Replication
role:slave # 从服务器
master_host:192.168.11.101 # 指定主服务器的地址
master_port:6379 # 指定主服务器端口
master_link_status:down # 和主服务器的连接状态,up
root@node02:~# /etc/init.d/redis_6379 stop
Stopping ...
Redis stopped
root@node02:~# vim /etc/redis/6379.conf
bind 192.168.11.103
slaveof 192.168.11.101 6379
# 重启
root@node02:~# /etc/init.d/redis_6379 start
Starting Redis server...
# 连接
root@node02:~# redis-cli -h 192.168.11.103
192.168.11.103:6379> ping
PONG
192.168.11.103:6379> KEYS *
192.168.11.103:6379> INFO replication
# Replication
role:slave
master_host:192.168.11.101
master_port:6379
master_link_status:down
PS:无效告终
root@Master:~# firewall-cmd --permanent --add-port=6379/tcp
success
root@Master:~# firewall-cmd --reload
success
PS:无效告终
root@Master:~# redis-cli
127.0.0.1:6379> config set client-output-buffer-limit "slave 8589934592 2147483648 0"
OK
127.0.0.1:6379> config rewrite
OK
127.0.0.1:6379>
[root@redis ~]# /etc/init.d/redis_6379 stop
[root@redis ~]# ls redis-4.0.8/sentinel.conf
[root@redis ~]# vim /etc/sentinel.conf #创建哨兵服务的配置文件,进行修改
bind 192.168.11.110
sentinel monitor redisserver 192.168.11.101 6379 1
[root@redis ~]# redis-sentinel /etc/sentinel.conf
[root@master ~]# redis-cli -h 192.168.11.101 -p 6379 shutdown
192.168.11.102:6379> info replication
[root@redis ~]# redis-sentinel /etc/sentinel.conf
[root@node01 ~]# redis-cli -h 192.168.11.102
192.168.11.102:6379> mset v1 1 v2 2 v3 3
192.168.11.102:6379> info replication
[root@master ~]# /etc/init.d/redis_6379 start
[root@master ~]# redis-cli -h 192.168.11.101 -p 6379
192.168.11.101:6379> keys *
上一篇:软件工程快速入门(下)
下一篇:质量保障体系建设演进案例