redis的安装
redis的安装包可以上官网下载
server1 172.25.13.1
server2 172.25.13.2
tar zxf redis-5.0.3.tar.gz #解压
yum install gcc -y #源码编译需要依赖
cd redis-5.0.3
make && makeinstall #安装
cd utils/
./install_server.sh #启动脚本
netstat -tnlp #查看端口
redis主从复制
server1:
vim /etc/redis/6379.conf #修改70行
systemctl restart redis_6379 #重启服务
netstat -tnlp #查看端口
server2:
vim /etc/redis/6379.conf #修改文件
systemctl restart redis_6379
netstat -tnlp
测试:
server1:
server2:
哨兵模式
Redis 的 Sentinel 系统用于管理多个 Redis 服务器(instance), 该系统执行以下三个任务:
监控(Monitoring): Sentinel 会不断地检查你的主服务器和从服务器是否运作正常。
提醒(Notification): 当被监控的某个 Redis 服务器出现问题时, Sentinel 可以通过 API 向管理员或者其他应用程序发送通知。
自动故障迁移(Automatic failover): 当一个主服务器不能正常工作时, Sentinel 会开始一次自动故障迁移操作, 它会将失效主服务器的其中一个从服务器升级为新的主服务器, 并让失效主服务器的其他从服务器改为复制新的主服务器; 当客户端试图连接失效的主服务器时, 集群也会向客户端返回新主服务器的地址, 使得集群可以使用新主服务器代替失效服务器。
Redis Sentinel 是一个分布式系统, 你可以在一个架构中运行多个 Sentinel 进程(progress), 这些进程使用流言协议(gossip protocols)来接收关于主服务器是否下线的信息, 并使用投票协议(agreement protocols)来决定是否执行自动故障迁移, 以及选择哪个从服务器作为新的主服务器。
虽然 Redis Sentinel 释出为一个单独的可执行文件 redis-sentinel , 但实际上它只是一个运行在特殊模式下的 Redis 服务器, 你可以在启动一个普通 Redis 服务器时通过给定 –sentinel 选项来启动 Redis Sentinel 。
配置主机172.25.13.3
修改配置文件
/etc/init.d/redis_6379 restart #重启服务
server1:
cd redis-5.0.3
vim sentinel.conf #修改哨兵模式配置文件84和 113
cp sentinel.conf /etc/redis/ #将配置文件移动到主配置文件下
cd /etc/redis/
scp sentinel.conf server2:/etc/redis/ #将配置文件发给server2和server3
scp sentinel.conf server3:/etc/redis/
redis-server /etc/redis/sentinel.conf --sentinel #开启哨兵模式
redis-server /etc/redis/sentinel.conf --sentinel server2 #开启哨兵模式
redis-server /etc/redis/sentinel.conf --sentinel server3 #开启哨兵模式
server1:
server2:
server3:
重新打开一个对话框查看server1为master节点
测试:在新的对话框redis-cli 输入shutdown
查看server1节点信息
Server2:成为新的master:
Server1关闭之后重新打开的需要添加配置文件,
vim /etc/redis/6379.conf
将server1添加到server2 开启服务
/etc/init.d/redis_6379 start
server2:查看
来源:CSDN
作者:房渊
链接:https://blog.csdn.net/fangyuan1997/article/details/104226815