redis服务--主从部署

1,在主机A上关闭防火墙和selinux

[root@localhost ~] systemctl stop firewalld.service 
[root@localhost ~] setenforce 0

2,在主机A上做主部署,

#安装redis
[root@localhost ~] yum -y install gcc gcc-c++ #依赖
[root@localhost ~] tar -zxf redis-3.2.11.tar.gz 
[root@localhost ~] cd redis-3.2.11 
[root@localhost redis-3.2.11 ] make

3,启动redis,修改配置,做后台启动

[root@localhost redis-3.2.11 ] cd src/
[root@localhost src ] ./redis-server  #为前台启动

新开一个主机A的终端

[root@localhost ~] cp /root/redis-3.2.11/redis.conf /etc/
[root@localhost ~] vim /etc/redis.conf 

daemonize yes #修改为yes
port 6379
bind 192.168.59.145
[root@localhost ~] ./redis-server /etc/redis.conf #后台启动器

做软链接,简化启动过程

[root@localhost ~] ln -s /root/redis-3.2.11/src/redis-server  /usr/bin/
[root@localhost ~] ln -s /root/redis-3.2.11/src/redis-cli  /usr/bin/

4,在主机B上,做从的服务配置

[root@localhost ~] yum -y install gcc gcc-c++
[root@localhost ~] tar -zxf redis-3.2.11.tar.gz 
[root@localhost ~] cd redis-3.2.11
[root@localhost redis-3.2.11] make
[root@localhost redis-3.2.11 ] cd src/
[root@localhost src ] ./redis-server  #为前台启动

新开一个主机B的终端

[root@localhost ~] cp /root/redis-3.2.11/redis.conf /etc/
[root@localhost ~] vim /etc/redis.conf 

daemonize yes #修改为yes
slaveof 192.168.59.145 6379 #指定主redis的ip及端口
port 6380		#从redis的端口设为6380
bind 192.168.59.146
[root@localhost ~] ./redis-server /etc/redis.conf #后台启动器

做软链接

[root@localhost ~] ln -s /root/redis-3.2.11/src/redis-server  /usr/bin/
[root@localhost ~] ln -s /root/redis-3.2.11/src/redis-cli  /usr/bin/

5,测试

[root@localhost ~] redis-cli -h 192.168.59.145 -p 6379
192.168.59.145:6379> set hello 123
ok
192.168.59.145:6379> get hello
"123"
192.168.59.145:6379>
[root@localhost ~] redis-cli -h 192.168.59.146 -p 6380
192.168.59.145:6380> get hello
"123"
192.168.59.145:6380>
发布了56 篇原创文章 · 获赞 65 · 访问量 2008

猜你喜欢

转载自blog.csdn.net/xiaohuai0444167/article/details/105231236
今日推荐