部署redis主从复制
转载:https://www.cnblogs.com/yanyanqaq/p/12695598.html
1.环境规划
主机名 | 角色 | IP地址 |
---|---|---|
db01 | Redis master | 172.16.1.51 |
db02 | Redis slave | 172.16.1.52 |
db03 | Redis slave | 172.16.1.53 |
cd /soft/
wget http://download.redis.io/releases/redis-3.2.12.tar.gz
2.Redis安装并添加配置文件
tar xzf redis-3.2.12.tar.gz
mv redis-3.2.12 /etc/redis
cd /etc/redis
make
vim /etc/redis/redis.conf
daemonize yes
port 6379
dbfilename dump.rdb
protected-mode no
save 900 1
save 300 10
save 60 10000
3.启动Redis服务
redis-server /etc/redis/redis.conf &
4.在从库上开启主从
redis-cli
127.0.0.1:6379> SLAVEOF 172.16.1.51 6379
set get delete
5.在从库上检查主从复制的状态
redis-cli
127.0.0.1:6379> info replication
6.在主库上检查主从复制的状态
redis-cli
127.0.0.1:6379> info replication
7.添加环境变量
vim /etc/profile
export PATH=/etc/redis/src:$PATH
source /etc/profile