1.环境准备:
三台centeros7系统 192.168.1.208 192.168.1.209 192.168.1.220
2.分别安装redis:
# wget http://download.redis.io/releases/redis-6.0.6.tar.gz
# tar xzf redis-6.0.6.tar.gz
# cd redis-6.0.6
# make
# make install PREFIX=/usr/local/redis
# cd /usr/local/redis/bin/
# cp /usr/local/redis-6.0.6/redis.conf /usr/local/redis/bin/
# vi redis.conf
修改 服务器192.168.1.208 redis.conf
bind 192.168.1.208
protected-mode yes
port 6379
daemonize yes
pidfile /var/run/redis_6379.pid
logfile "/var/log/redis.log"
dir /var/redis/
requirepass 123456
修改 服务器192.168.1.209 redis.conf
bind 192.168.1.209
protected-mode yes
port 6379
daemonize yes
pidfile /var/run/redis_6379.pid
logfile "/var/log/redis.log"dir /var/redis/
replicaof 192.168.1.208 6379 #配置为master的从
masterauth 123456 #配置主的密码
修改 服务器192.168.1.220 redis.conf
bind 192.168.1.220
protected-mode yes
port 6379
daemonize yes
pidfile /var/run/redis_6379.pid
logfile "/var/log/redis.log"dir /var/redis/
replicaof 192.168.1.208 6379 #配置为master的从
masterauth 123456 #配置主的密码
保存配置文件后,进入192.168.1.208启动
# ./redis-server redis.conf
3.设置开机启动:
# vi /etc/systemd/system/redis.service
添加下面的内容
[Unit]Description=redis-serverAfter=network.target[Service]Type=forkingExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.confPrivateTmp=true[Install]WantedBy=multi-user.target
# systemctl daemon-reload
# systemctl start redis.service
# systemctl enable redis.service
服务操作命令
systemctl start redis.service #启动redis服务
systemctl stop redis.service #停止redis服务
systemctl restart redis.service #重新启动服务
systemctl status redis.service #查看服务当前状态
systemctl enable redis.service #设置开机自启动
systemctl disable redis.service #停止开机自启动
4.配置sentinel:
分别在192.168.1.208 209 220 三台服务器上配置
# cd /usr/local/redis/bin/
# vi sentinel.conf
添加下面内容
port 26379
daemonize yes
pidfile "/var/run/redis-sentinel.pid"
logfile "/var/log/sentinel.log"
sentinel monitor mymaster 192.168.1.208 6379 2
sentinel auth-pass mymaster 123456
保存后启动
# redis-sentinel sentinel.conf
#redis-cli -p 26379
127.0.0.1:26379> sentinel slaves mymaster
1) 1) "name"
2) "192.168.1.209:6379"
3) "ip"
4) "192.168.1.209"
5) "port"
6) "6379"
7) "runid"
8) "631d1a0385e9eaececb6b37e3ba8a04528e56557"
9) "flags"
10) "slave"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "87"
19) "last-ping-reply"
20) "87"
21) "down-after-milliseconds"
22) "30000"
23) "info-refresh"
24) "2006"
25) "role-reported"
26) "slave"
27) "role-reported-time"
28) "704509"
29) "master-link-down-time"
30) "0"
31) "master-link-status"
32) "ok"
33) "master-host"
34) "192.168.1.208"
35) "master-port"
36) "6379"
37) "slave-priority"
38) "100"
39) "slave-repl-offset"
40) "112962"
2) 1) "name"
2) "192.168.1.220:6379"
3) "ip"
4) "192.168.1.220"
5) "port"
6) "6379"
7) "runid"
8) "949b1199a119dad3e0f22ed0be8e235fc5007c66"
9) "flags"
10) "slave"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "641"
19) "last-ping-reply"
20) "641"
21) "down-after-milliseconds"
22) "30000"
23) "info-refresh"
24) "1950"
25) "role-reported"
26) "slave"
27) "role-reported-time"
28) "42196"
29) "master-link-down-time"
30) "0"
31) "master-link-status"
32) "ok"
33) "master-host"
34) "192.168.1.208"
35) "master-port"
36) "6379"
37) "slave-priority"
38) "100"
39) "slave-repl-offset"
40) "112962"
显示上面内容说明已经按转发成功
网友评论