centos配置redis的主从复制(1)

预配

1. 准备好4台机器
vim /etc/hosts
192.168.42.150 redis-node1 #主
192.168.42.151 redis-node2 #从 
192.168.42.152 redis-node3 #从
192.168.42.153 redis-node4 #从
2.将主机解析写入hosts文件,分发至每台机器
scp -r /etc/hosts redis-node2:192.168.42.151/etc/hosts
scp -r /etc/hosts redis-node2:192.168.42.152/etc/hosts
scp -r /etc/hosts redis-node2:192.168.42.153/etc/hosts

安装redis与配置

(1) 4台机器,分别安装redis
cd /usr/local/src
wget http://192.168.42.26/install_package/down/redis-3.2.3-1.el7.x86_64.rpm
yum install redis-3.2.3-1.el7.x86_64.rpm -y

(2) 4台机分别配置好,配置文件,做好备份
cp /etc/redis.conf{,.back}
vim redis.conf
daemonize yes
bind 192.168.42.150  #改为各个节点的IP

(3) 依照上面设定的从主机,在从主机配置文件中开启从配置(需要配置3台机器,都是自己的ip)。redis主机,注释此行即可
# slaveof <masterip> <masterport>
slaveof  192.168.42.150 6379

(4) 启动redis-server(4台同时启动)
redis-server /etc/redis.conf

(5) 在主机器上登录redis
[-node1 ~]# redis-cli -h 192.168.42.150
192.168.42.150:6379&gt; 
192.168.42.150:6379&gt; keys *
1) "magedu"
192.168.42.150:6379&gt; 
192.168.42.150:6379&gt; set ok "verygood!!!"
OK
192.168.42.150:6379&gt; get ok
"verygood!!!"
192.168.42.150:6379&gt;
登录其他3台从服务器

redis-cli -h 192.168.42.151
redis-cli -h 192.168.42.152
redis-cli -h 192.168.42.153
拿153做示例:
[-node4 src]# redis-cli -h 192.168.42.153
192.168.42.153:6379&gt; keys *
1) "magedu"
192.168.42.153:6379&gt; 
192.168.42.153:6379&gt; get ok
"verygood!!!"
192.168.42.153:6379&gt;

目前已经配置主从复制

相关推荐