CentOS6 单节点安装Redis Sentinel
来源:互联网 发布:fifo算法c语言实现 编辑:程序博客网 时间:2024/06/08 10:03
Redis Sentinel模式简介
Redis-Sentinel是官方推荐的高可用解决方案,当redis在做master-slave的高可用方案时,假如master宕机了,redis本身(以及其很多客户端)都没有实现自动进行主备切换,而redis-sentinel本身也是独立运行的进程,可以部署在其他与redis集群可通讯的机器中监控redis集群
- 主要功能有一下几点
1、不时地监控redis是否按照预期良好地运行;
2、如果发现某个redis节点运行出现状况,能够通知另外一个进程(例如它的客户端);
3、能够进行自动切换。当一个master节点不可用时,能够选举出master的多个slave(如果有超过一个slave的话)中的一个来作为新的master,其它的slave节点会将它所追随的master的地址改为被提升为master的slave的新地址。
4、哨兵为客户端提供服务发现,客户端链接哨兵,哨兵提供当前master的地址然后提供服务,如果出现切换,也就是master挂了,哨兵会提供客户端一个新地址。
Redis Sentinel 安装
- 环境准备:
192.168.0.106 CentOS6.9
安装Redis
参考:http://blog.csdn.net/wh211212/article/details/52817923
CentOS6 单节点安装Redis Sentinel
- 下载redis
virsh attach-disk kvm-6 /dev/vg_shkvm3/kvm-6-data vdb –driver qemu –mode shareable
wget http://download.redis.io/releases/redis-3.2.8.tar.gz -P /usr/local/src
- 解压、指定目录
tar xvf redis-3.2.8.tar.gz -C /usr/local/cd /usr/local/ln -sv redis-3.2.8 redis
- 设置系统内核参数
echo 512 > /proc/sys/net/core/somaxconnsysctl vm.overcommit_memory=1
- 编译
yum groupinstall -y "Development Tools"yum -y install tcl # 安装tcl依赖防止make test报错
解决办法:
1,只用单核运行 make test:
taskset -c 1 sudo make test
2,更改 tests/integration/replication-psync.tcl 文件:
vi tests/integration/replication-psync.tcl
把对应报错的那段代码中的 after后面的数字,从100改成 500。我个人觉得,这个参数貌似是等待的毫秒数。
cd redis && make && make test
- 为多实例redis配置启动环境
mkdir -pv /data/redis-sentinel/{9000,9001,9002}cp src/{redis-server,redis-sentinel} /data/redis-sentinel/9000/cp src/{redis-server,redis-sentinel} /data/redis-sentinel/9001/cp src/{redis-server,redis-sentinel} /data/redis-sentinel/9002/cp redis.conf sentinel.conf /data/redis-sentinel/9000/cp redis.conf sentinel.conf /data/redis-sentinel/9001/cp redis.conf sentinel.conf /data/redis-sentinel/9002/
- 修改配置文件
# vim /data/redis-sentinel/9000/redis.confbind 192.168.0.106protected-mode noport 9000daemonize yesappendonly yes# \cp /data/redis-sentinel/9000/redis.conf /data/redis-sentinel/9001/redis.conf# \cp /data/redis-sentinel/9000/redis.conf /data/redis-sentinel/9002/redis.confsed -i 's/9000/9001/g' /data/redis-sentinel/9001/redis.conf# vim /data/redis-sentinel/9001/redis.confport 9001slaveof 192.168.0.106 9000# vim /data/redis-sentinel/9002/redis.confsed -i 's/9000/9002/g' /data/redis-sentinel/9002/redis.confport 9002slaveof 192.168.0.106 9000
- 啟動三個redis實例
# cd /data/redis-sentinel/9000/# ./redis-server redis.conf# cd ../9001/# ./redis-server redis.conf# cd ../9002/# ./redis-server redis.conf# ps -ef | grep redisroot 4218 1 0 17:03 ? 00:00:00 ./redis-server 192.168.0.106:9000root 4238 1 0 17:03 ? 00:00:00 ./redis-server 192.168.0.106:9001root 4252 1 0 17:03 ? 00:00:00 ./redis-server 192.168.0.106:9002
- 查看主从状态
# /usr/local/redis/src/redis-cli -h 192.168.0.106 -p 9000192.168.0.106:9000> set name aniuOK192.168.0.106:9000> get name"aniu"192.168.0.106:9000> info replication# Replication192.168.0.106:9000> info replication# Replicationrole:masterconnected_slaves:2slave0:ip=192.168.0.106,port=9001,state=online,offset=1121,lag=0slave1:ip=192.168.0.106,port=9002,state=online,offset=1121,lag=1master_repl_offset:1121repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:2repl_backlog_histlen:1120
部署sentinel
- 部署sentinel 1
# cd /data/redis-sentinel/9000# vim sentinel.confprotected-mode noport 29000daemonize yesdir /data/redis-sentinel/9000/logssentinel monitor mymaster 192.168.0.106 9000 2# mkdir logs# ./redis-sentinel sentinel.conf# \cp sentinel.conf ../9001/# \cp sentinel.conf ../9002/
- 部署sentinel 2
# cd ../9001/port 29001dir "/data/redis-sentinel/9001/logs"# mkdir logs# ./redis-sentinel sentinel.conf- 部署sentinel 3# cd ../9002/# vim sentinel.confport 29002dir "/data/redis-sentinel/9002/logs"# mkdir logs# ./redis-sentinel sentinel.conf
- 验证
# /usr/local/redis/src/redis-cli -h 192.168.0.106 -p 29000[root@sh-kvm-3-6 9002]# /usr/local/redis/src/redis-cli -h 192.168.0.106 -p 29000192.168.0.106:29000> sentinel masters1) 1) "name" 2) "mymaster" 3) "ip" 4) "192.168.0.106" 5) "port" 6) "9000" 7) "runid" 8) "03427a4cd4f22401f55d07952424ba4b31144b57" 9) "flags" 10) "master" 11) "link-pending-commands" 12) "0" 13) "link-refcount" 14) "1" 15) "last-ping-sent" 16) "0" 17) "last-ok-ping-reply" 18) "542" 19) "last-ping-reply" 20) "542" 21) "down-after-milliseconds" 22) "30000" 23) "info-refresh" 24) "3335" 25) "role-reported" 26) "master" 27) "role-reported-time" 28) "515500" 29) "config-epoch" 30) "0" 31) "num-slaves" 32) "2" 33) "num-other-sentinels" 34) "0" 35) "quorum" 36) "2" 37) "failover-timeout" 38) "180000" 39) "parallel-syncs" 40) "1"192.168.0.106:29000> sentinel slaves mymaster1) 1) "name" 2) "192.168.0.106:9002" 3) "ip" 4) "192.168.0.106" 5) "port" 6) "9002" 7) "runid" 8) "42ec153d250bf9aff05765346e0fdc2ee33d1257" 9) "flags" 10) "slave" 11) "link-pending-commands" 12) "0" 13) "link-refcount" 14) "1" 15) "last-ping-sent" 16) "0" 17) "last-ok-ping-reply" 18) "510" 19) "last-ping-reply" 20) "510" 21) "down-after-milliseconds" 22) "30000" 23) "info-refresh" 24) "6271" 25) "role-reported" 26) "slave" 27) "role-reported-time" 28) "548469" 29) "master-link-down-time" 30) "0" 31) "master-link-status" 32) "ok" 33) "master-host" 34) "192.168.0.106" 35) "master-port" 36) "9000" 37) "slave-priority" 38) "100" 39) "slave-repl-offset" 40) "57920"2) 1) "name" 2) "192.168.0.106:9001" 3) "ip" 4) "192.168.0.106" 5) "port" 6) "9001" 7) "runid" 8) "afdc283bae3f48fb0ceb6f8dd9af8248928406ec" 9) "flags" 10) "slave" 11) "link-pending-commands" 12) "0" 13) "link-refcount" 14) "1" 15) "last-ping-sent" 16) "0" 17) "last-ok-ping-reply" 18) "510" 19) "last-ping-reply" 20) "510" 21) "down-after-milliseconds" 22) "30000" 23) "info-refresh" 24) "6271" 25) "role-reported" 26) "slave" 27) "role-reported-time" 28) "548486" 29) "master-link-down-time" 30) "0" 31) "master-link-status" 32) "ok" 33) "master-host" 34) "192.168.0.106" 35) "master-port" 36) "9000" 37) "slave-priority" 38) "100" 39) "slave-repl-offset" 40) "57920"
jedis中使用哨兵
Redis常用安全设置
- 设置密码
requirepass yourpassword
- 禁用高危命令
rename-command FLUSHALL ""rename-command FLUSHDB ""rename-command KEYS ""
- CentOS6 单节点安装Redis Sentinel
- CentOS6 脚本自动安装redis sentinel
- 单节点redis安装
- redis-单节点规范安装
- Redis & Sentinel 安装脚本
- Redis Sentinel 安装部署
- redis-sentinel安装配置
- redis-sentinel安装部署
- redis-sentinel集群安装
- centos6.5 redis sentinel主从模式配置
- redis学习(-) 单节点编译安装
- 1,redis单节点的安装
- linux上安装redis(单节点)
- Redis分布式缓存安装(单节点)
- redis安装和部署(单节点)
- CentOS7-源码安装redis单节点
- 单节点redis的安装与配置
- Redis Sentinel实现集群节点故障转移
- Mr. Kitayuta's Colorful Graph
- c#窗口操作-句柄操控全解
- Maven常用命令以及Nexus私服配置
- 获取系统传感器
- POJ2155 Matrix <树套树/二维树状数组>
- CentOS6 单节点安装Redis Sentinel
- [Usaco2005 nov]Asteroids 穿越小行星群
- 【SSLGZ 2673】2017年8月9日提高组T1 水题
- Oracle 数据库的连接方式实现方法
- MVG读书笔记——射影变换的校正(二)
- 【C++】【LeetCode】101. Symmetric Tree
- 设置Lazarus组件包的版本信息
- kvm虚拟机挂载lvm卷
- 单链表的基本操作