CentOS7配置redis主从复制

规划

ip				port 		role		
192.168.1.31	6379		master
192.168.1.32	6379		slave
192.168.1.33	6379		slave

0.关闭防火墙

systemctl stop firewald.service 
systemctl disable firewald.service

1.安装启动redis

yum install epel-release -y 
yum install redis -y 
systemctl start redis 
systemctl enable redis 

2.master配置

#vim /etc/my.cnf 
bind 0.0.0.0 				//修改监听ip
port 6379					//监听端口
daemonize yes 				//后台运行		
requirepass redhat  		//配置登录密码

3.slave配置

vim /etc/my.cnf 
bind 0.0.0.0 
port 6379
daemonize yes 
masterauth redhat 				//如果master配置了requiress登录密码,需要配置masterauth认证
slaveof 192.168.1.31 6379 		//指定master节点的ip和端口	
slave-read-only yes				//从节点只读

4.master 和slave端 验证

redis-cli -h 192.168.1.31 -a redhat info replication
redis-cli -h 192.168.1.31 -a redhat set ip 1.1.1.1 
redis-cli -h 192.168.1.31 -a redhat set port 8080 


slave验证

redis-cli -h 192.168.1.33 -a redhat 
> keys * 
redis-cli -h 192.168.1.32 -a redhat
> keys *  

posted @ 2018-05-24 11:45  你很棒  阅读(386)  评论(0编辑  收藏  举报