码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-05-31 16:25:12      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:color   服务   magedu   主机   package   写入   sla   bin   root   

预配

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
[root@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做示例:
[root@redis-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;

目前已经配置主从复制

 

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

标签:color   服务   magedu   主机   package   写入   sla   bin   root   

原文地址:https://www.cnblogs.com/topass123/p/13019130.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!