环境:
[root@server1 ~]# tar zxf redis-5.0.3.tar.gz
[root@server1 ~]# ls
redis-5.0.3 redis-5.0.3.tar.gz
[root@server1 ~]#
yum install -y gcc
[root@server1 ~]# cd redis-5.0.3/
[root@server1 redis-5.0.3]# ls
00-RELEASENOTES INSTALL runtest tests
BUGS Makefile runtest-cluster utils
CONTRIBUTING MANIFESTO runtest-sentinel
COPYING README.md sentinel.conf
deps redis.conf src
[root@server1 redis-5.0.3]# make
[root@server1 ~]# cd src/
[root@server1 src]# make install
[root@server1 redis-5.0.3]# cd utils/
[root@server1 utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
[root@server1 utils]# vim /etc/redis/6379.conf
=====================
70 bind 0.0.0.0
========================
[root@server1 utils]# /etc/init.d/redis_6379 restart
Stopping ...
Redis stopped
Starting Redis server...
#查看端口
[root@server1 utils]# netstat -antlupe | grep 6379
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 0 100152 7413/redis-server 0
[root@server1 ~]# scp -r redis-5.0.3 root@server2:
[root@server1 ~]# scp -r redis-5.0.3 root@server3:
[root@server2 redis-5.0.3]# cd src/
[root@server2 src]# make install
[root@server2 src]# cd ../utils/
[root@server2 utils]# ./install_server.sh
[root@server2 utils]# vim /etc/redis/6379.conf
===============================================
70 bind 0.0.0.0
1379 slaveof 172.25.70.1 6379
=================================================
[root@server2 utils]# /etc/init.d/redis_6379 restart
#在server1上查看主从状态
[root@server1 redis-5.0.3]# redis-cli
127.0.0.1:6379> info
'''
# Replication
role:master
connected_slaves:2
slave0:ip=172.25.70.2,port=6379,state=online,offset=630,lag=1
slave1:ip=172.25.70.3,port=6379,state=online,offset=630,lag=1
server3操作同server2
server1上再次查看主从
[root@server1 ~]# cd redis-5.0.3/
[root@server1 redis-5.0.3]# cp sentinel.conf /etc/redis/
vim /etc/redis/sentinel.conf
====================================================
84 sentinel monitor mymaster 172.25.70.1 6379 2
...
113 sentinel down-after-milliseconds mymaster 10000
[root@server1 redis-5.0.3]# cd /etc/redis/
[root@server1 redis]# scp sentinel.conf server2:/etc/redis/
sentinel.conf 100% 9712 9.5KB/s 00:00
[root@server1 redis]# scp sentinel.conf server3:/etc/redis/
sentinel.conf 100% 9712 9.5KB/s 00:00
[root@server1 redis]#
[root@server1 redis]# redis-server /etc/redis/sentinel.conf --sentinel
[root@server2 utils]# redis-server /etc/redis/sentinel.conf --sentinel
[root@server3 utils]# redis-server /etc/redis/sentinel.conf --sentinel
可以看到信息,server1为master,server2-3都是slave节点。
1.重新开启一个终端远程连接server1查看端口发现哨兵26379进程开启:
[root@server1 ~]# netstat -antulpe
[root@server1 ~]# redis-cli -p 26379
注意:此时显示主是server1,sentinels=3表示成功
3.将server1的redis-cli关闭
[root@server1 ~]# redis-cli
127.0.0.1:6379> SHUTDOWN
not connected>
4.查看哨兵状态
我们可以看到此时哨兵为我们挑选了server3作为新的master