Redis主从 + 哨兵模式
Redis-6.2.1 主从和哨兵模式配置
Centos 7.4
master:192.168.80.130
salve0:192.168.80.131
slave1:192.168.80.161
公共操作部分:
wget https://download.redis.io/releases/redis-6.2.1.tar.gz
yum install -y gcc gcc-c++
tar xf redis-6.2.1.tar.gz
mv redis-6.2.1 /home/redis
cd /home/redis
make
cd src
make install
cd ..
mkdir etc
mkdir bin
cp redis.conf etc
cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server redis-sentinel ../bin/
iptables -I INPUT -p tcp --dport 6379 -j ACCEPT
iptables -I INPUT -p tcp --dport 26379 -j ACCEPT
/etc/init.d/iptables save
配置master redis.conf
原有配置基础上修改以下内容:
bind 0.0.0.0
port 6379
protected-mode no
daemonize yes
logfile "./redis.log "
requirepass "pwdtest@163.com"
masterauth "pwdtest@163.com "
配置 slave主机的redis.conf
原有配置基础上修改以下内容:
bind 0.0.0.0
port 6379
protected-mode no
daemonize yes
logfile "./redis.log "
requirepass "pwdtest@163.com"
masterauth "pwdtest@163.com "
replicaof 192.168.80.130 6379
启动3台主机的redis服务
cd bin/
./redis-server /home/redis/etc/redis.conf
验证:master主机创建值 其他主机能够同步得到
master:
redis-cli -p 6379 -a pwdtest@163.com
set name hhhhahaha
get name
set name01 jjjyyy
get name01
slave:
redis-cli -p 6379 -a pwdtest@163.com
get name
getname01
哨兵模式:
部署三个哨兵,每台服务器一个哨兵,配置方式相同,如下
cd /home/redis
cp sentinel.conf etc/
vi sentinel.conf 原有配置不变 修改以下内容:
port 26379
protected-mode no
daemonize yes
logfile ./sentinel.log
sentinel monitor mymaster 192.168.80.130 6379 2
sentinel auth-pass mymaster pwdtest@163.com
sentinel down-after-milliseconds mymaster 300
snetinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
启动3台机器的哨兵:
cd /home/redis/bin
redis-sentinel /home/redis/etc/sentinel.conf
redis-cli -p 26379
info sentinel
验证:
关闭master主机的redis服务
redis-cli -p 6379 -a pwdtest@163.com
>shutdown
>quit
到其他机器登录查看验证:
redis-cli -p 6379 -a pwdtest@163.com
>info replication
查看日志:
tail -f sentinel.log
tail -f redis.log
============================================================================================
End