Redis 3.2.8 集群模式+Sentinel多Master部署
来源:互联网 发布:新疆行知实验学校学费 编辑:程序博客网 时间:2024/05/21 18:41
环境准备
CentOS 7.3
redis1 172.18.1.101:7001 master
redis2 172.18.1.102:7002 master
redis3 172.18.1.103:7003 master
redis4 172.18.1.104:7004 slave
redis5 172.18.1.105:7005 slave
redis6 172.18.1.106:7006 slave
停止防火墙(有可能还需要iptables加规则)
systemctl stop firewalld.service
systemctl disable firewalld.service
修改内核参数
vi /etc/sysctl.conf
vm.overcommit_memory = 1
查看效果
sysctl -p
安装必要的软件包
yum -y install gcc automake autoconf libtool make telnet ruby-devel ruby-irb ruby-libs ruby-rdoc ruby rubygems-devel rubygems
gem install redis #忘了这一步会导致使用redis-trib.rb创建集群的时候报错
编译安装Redis
cd ~
wget http://download.redis.io/releases/redis-3.2.8.tar.gz
tar -zxf redis-3.2.8.tar.gz;cd redis-3.2.8;make
make install PREFIX=/usr/local/redis
mkdir /usr/local/redis/etc;mkdir /usr/local/redis/db;cp redis.conf /usr/local/redis/etc/;cp ./src/redis-trib.rb /usr/local/redis/bin/
修改配置文件,密码为password
vi /usr/local/redis/etc/redis.conf
#bind 127.0.0.1 #这里注释掉,否则会导致其它节点无法与本节点通信
protected-mode yes
port 7001 #不同机器端口不一样,我们用7001-7006 #如果用一样的端口,创建集群会出问题
daemonize yes
pidfile /var/run/redis_7001.pid #不同机器PID文件不一样,我们用7001-7006 #可以用同一个,但是为了统一还是建议改成不同的
logfile "/var/log/redis.log"
dir /usr/local/redis/db/
masterauth password
requirepass password
appendonly yes
cluster-enabled yes
cluster-config-file nodes-7001.conf #不同机器nodes.conf文件不一样,我们用7001-7006 #原因同pidfile
cluster-node-timeout 15000
启动Redis测试能否正常启动,注意看一下端口
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
备份Redis配置文件,未来如果改了其他设置除了问题,可以留作比对
cp -p redis.conf redis.conf.bak
查看日志
tail -100f /var/log/redis.log
修改ruby脚本,否则无法创建集群
vi /usr/local/share/gems/gems/redis-3.3.3/lib/redis/client.rb
修改DEFAULTS里面的password一项,我们这里用的是"password",一定要加引号
创建集群,这里一定要用IP和端口,不能用hostname
/usr/local/redis/bin/redis-trib.rb create --replicas 1 172.18.1.101:7001 172.18.1.102:7002 172.18.1.103:7003 172.18.1.104:7004 172.18.1.105:7005 172.18.1.106:7006
查看哪些Redis实例被定为Master
/usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 7001
cluster nodes
拷贝sentinel.conf到etc下
cp /root/redis-3.2.8/sentinel.conf /usr/local/redis/etc
编辑sentinel.conf
vi /usr/local/redis/etc/sentinel.conf
protected-mode no
port 27001 #不同Sentinel端口不一样,我们用27001-27003
sentinel monitor mymaster1 172.18.1.101 7001 2
sentinel monitor mymaster2 172.18.1.102 7002 2
sentinel monitor mymaster3 172.18.1.103 7003 2
sentinel down-after-milliseconds mymaster1 10000
sentinel down-after-milliseconds mymaster2 10000
sentinel down-after-milliseconds mymaster3 10000
sentinel parallel-syncs mymaster1 1
sentinel parallel-syncs mymaster2 1
sentinel parallel-syncs mymaster3 1
sentinel failover-timeout mymaster1 15000
sentinel failover-timeout mymaster2 15000
sentinel failover-timeout mymaster3 15000
daemonize yes
logfile "/var/log/sentinel.log"
备份Sentinel配置文件,未来如果改了其他设置除了问题,可以留作比对
cp -p sentinel.conf sentinel.conf.bak
启动Sentinel
/usr/local/redis/bin/redis-sentinel /usr/local/redis/etc/sentinel.conf
常用命令
ps -ef | grep redis
tail -100f /var/log/redis.log
tail -100f /var/log/sentinel.log
/usr/local/redis/bin/redis-cli -h 172.18.1.101 -p 7001 -a password
kill $(ps -ef | grep redis | grep -v grep | awk '{print $2}')
常见问题:
搭建redis集群时报错“create ERR Slot 9838 is already busy (Redis::CommandError)”
解决方法:用redis-cli登录到每个节点执行flushall和cluster reset就可以了
- Redis 3.2.8 集群模式+Sentinel多Master部署
- Redis 3.2.8 集群模式+Sentinel多Master部署
- redis+sentinel集群部署
- redis-3.2.8-Sentinel集群安装和部署
- redis master/slave+sentinel 集群配置
- Redis(Sentinel)监控集群安装部署
- redis集群部署sentinel--两台实现
- Redis 3.2.6 Sentinel部署
- Redis-sentinel哨兵模式集群方案配置
- Redis-sentinel哨兵模式集群方案配置
- Redis-sentinel哨兵模式集群方案配置
- Spring+SpringMVC做Redis集群(Sentinel模式)
- Redis-sentinel哨兵模式集群方案配置
- Redis Master Slave + sentinel
- Redis主从加Sentinel模式部署
- 安装部署master加密的redis集群
- redis主从集群搭建及容灾部署(哨兵sentinel)
- redis主从集群搭建及容灾部署(哨兵sentinel)
- C++笔记
- C语言历史
- 董付国老师6本Python系列教材被北大、复旦等近百所高校选作教材
- 易知大学“大数据挖掘与分析(Python)”免费学习平台
- cocos2dx 设置搜索路径问题
- Redis 3.2.8 集群模式+Sentinel多Master部署
- php 使用 ffmpeg 转换视频,截图,并生成缩略图
- CyberLink PowerDirector Ultimate 16(威力导演视频处理工具)官方中文版V16.0.2406.0下载 | 威力导演16中文破解版
- Android 5.0 Headup形式的Notification消息通知
- JDBC规范——(4)概览
- linux开源邮箱服务器搭建
- 实时搜索引擎Elasticsearch(2)——Rest API的使用
- TCP协议中的三次握手和四次挥手(图解)
- 解决:target\surefire-reports for the individual test results