配置Redis主从服务器

配置Redis主从服务器

问题

本案例要求先快速搭建好两台Redis服务器,实现两台服务器之间自动数据同步,具体要求如下:
1)主服务器IP为192.168.4.10
2)从服务器IP为192.168.4.20
3)主服务器认证密码为password
4)测试主从数据是否正常通过

方案

通过修改Redis配置文件,实现两台服务器之间的自动主从同步功能,方案拓扑如图所示。
在这里插入图片描述

步骤

实现此案例需要按照如下步骤进行。
步骤一:配置主从服务器设置
1)主服务器安装Redis

[root@svr10 ~]# tar -xzf redis-3.0.6.tar.gz 
[root@svr10 ~]# cd redis-3.0.6
[root@svr10 ~]# make
[root@svr10 ~]# make install
[root@svr10 ~]# cd utils/
[root@svr10 ~]#./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

2)从服务器安装Redis

[root@svr20 ~]# tar -xzf redis-3.0.6.tar.gz 
[root@svr20 ~]# cd redis-3.0.6
[root@svr20 ~]# make
[root@svr20 ~]# make install
[root@svr20 ~]# cd utils/
[root@svr20 ~]#./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

步骤二:配置主从服务器设置
1)修改主服务器/etc/redis/6379.conf配置文件

[root@svr10 ~]# vim /etc/redis/6379.conf
requirepass redis123							//设置服务器密码
[root@svr10 ~]# /etc/init.d/redis_6379 restart	//重启服务

2)修改从服务器/etc/redis/6379.conf配置文件

[root@svr20 ~]# vim /etc/redis/6379.conf
slaveof 192.1684.10 6379
masterauth redis123
[root@svr20 ~]# /etc/init.d/redis_6379 restart

步骤三:客户端验证效果

[root@client ~]# redis-cli –h 192.168.4.10 –a redis123	//登录主服务器设置数据
192.168.4.10:6379> set test 123456
OK
[root@client ~]# redis-cli –h 192.168.4.20			//登录主服务器查看数据同步效果
192.168.4.20:6379> set test
“123456”
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值