1. 集群说明
192.168.0.69 Master
192.168.0.70 Slave1
192.168.0.71 Slave2
2. 主从复制 Replication
Master操作:
cd /data/Redis/
wget http://download.redis.io/releases/redis-5.0.2.tar.gz
tar xzf redis-5.0.2.tar.gz
cd redis-5.0.2
make
make PREFIX=/data/Redis/redis-5.0.2 install
#修改redis.conf
vim redis.conf
bind 192.168.0.69
daemonize yes #后台启动
port 5379
requirepass bim123456
logfile /var/log/redis/redis.log
mkdir -p /var/log/redis #redis不会自动创建文件
./bin/redis-server ./redis.conf #启动redis
Slave1操作:
cd /data/Redis/
wget http://download.redis.io/releases/redis-5.0.2.tar.gz
tar xzf redis-5.0.2.tar.gz
cd redis-5.0.2
make
make PREFIX=/data/Redis/redis-5.0.2 install
#修改redis_slave1.conf
vim redis_slave1.conf
bind 192.168.0.70
daemonize yes #后台启动
port 5380
requirepass bim123456
logfile /var/log/redis/redis.log
masterauth bim123456 #主库master要求密码验证
mkdir -p /var/log/redis #redis不会自动创建文件
./bin/redis-server ./redis_slave1.conf #启动redis
Slave2操作:
cd /data/Redis/
wget http://download.redis.io/releases/redis-5.0.2.tar.gz
tar xzf redis-5.0.2.tar.gz
cd redis-5.0.2
make
make PREFIX=/data/Redis/redis-5.0.2 install
#修改redis_slave2.conf
vim redis_slave2.conf
bind 192.168.0.70
daemonize yes #后台启动
port 5380
requirepass bim123456
logfile /var/log/redis/redis.log
masterauth bim123456 #主库master要求密码验证
mkdir -p /var/log/redis #redis不会自动创建文件
./bin/redis-server ./redis_slave2.conf #启动redis
检查集群状态:
cd /data/Redis/redis-5.0.2/
./bin/redis-cli -h 192.168.0.69 -p 5379
auth bim123456
info Replication
{
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.0.70,port=5380,state=online,offset=770,lag=0
slave1:ip=192.168.0.71,port=5381,state=online,offset=770,lag=0
master_replid:384fdbed276789ca55115f93b0535e5fa16b8755
master_replid2:0000000000000000000000000000000000000000
}
3. 哨兵sentinel
Master节点操作:
cd /data/Redis/redis-5.0.2/
vim sentinel.conf
protected-mode no
daemonize yes
port 26379
sentinel monitor mymaster 192.168.0.69 5379 1
sentinel auth-pass mymaster bim123456
#5秒内master6800没有响应,就认为SDOWN
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 15000
logfile /var/log/redis/sentinel.log
./bin/redis-sentinel ./sentinel.conf #启动哨兵