1停掉所有主从redis,然后删除从里面免密钥登录文件
127.0.0.1:6379> shutdown not connected> [root@db03 ~]# cd /root/.ssh/ [root@db03 .ssh]# ls id_rsa.pub [root@db03 .ssh]# rm -rf ./* [root@db03 .ssh]# ls [root@db03 .ssh]#
2从新拷贝密钥至从库:
[root@db01 ~]# scp -r /root/.ssh/id_rsa.pub root@10.0.0.202:/root/.ssh/
root@10.0.0.202‘s password:
id_rsa.pub 100% 391 68.6KB/s 00:00
[root@db01 ~]# scp -r /root/.ssh/id_rsa.pub root@10.0.0.203:/root/.ssh/
root@10.0.0.203‘s password:
id_rsa.pub 100% 391 130.6KB/s 00:00
[root@db01 ~]#
3分别将从库接收到的密钥id_rsa.pub添加至/.ssh/authorized_keys 中,至此两台从机器就与主机器建立了互信
[root@db02 .ssh]# pwd
/root/.ssh
[root@db02 .ssh]# ls
id_rsa.pub
[root@db02 .ssh]# cat id_rsa.pub >authorized_keys
[root@db02 .ssh]# ls
authorized_keys id_rsa.pub
4在主库中分别登录两个从库看看是否能成功
[root@db01 ~]# ssh root@10.0.0.202
Last login: Sat Apr 10 16:42:00 2021 from 10.0.0.1
[root@db02 ~]# exit
登出
Connection to 10.0.0.202 closed.
[root@db01 ~]# ssh root@10.0.0.203
Last login: Sat Apr 10 16:49:45 2021 from 10.0.0.1
[root@db03 ~]# exit
登出
Connection to 10.0.0.203 closed.
[root@db01 ~]#
5检查域名解析文件中是否都把三台机器的ip配置上了
[root@db03 .ssh]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@db03 .ssh]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.201 db01
10.0.0.201 db02
10.0.0.203 db03
6分别启动一主两从,并在两台从redis中执行复制语句:
[root@db03 .ssh]# redis-server /opt/redis_cluster/redis_6379/conf/redis_6379.conf
[root@db03 .ssh]# redis-cli
127.0.0.1:6379> get k1
"xiaohong"
127.0.0.1:6379> slaveof 10.0.0.201 6379
OK
127.0.0.1:6379> get k1
"va"
127.0.0.1:6379>
7查看三台机器的配置文件是否含有哨兵(哨兵自动生成的配置不要碰):
[root@db03 ~]# cat /opt/redis_cluster/redis_26379/conf/redis_26379.conf
bind 10.0.0.203
port 26379
daemonize yes
logfile "/opt/redis_cluster/redis_26379/logs/redis_26379.log"
dir "/data/redis_cluster/redis_26379"
sentinel myid ed81a1b04c2c9d94cd9fbbab3bd8a843acc0b226
sentinel monitor mymaster 10.0.0.201 6379 2
sentinel down-after-milliseconds mymaster 3000
sentinel failover-timeout mymaster 18000
# Generated by CONFIG REWRITE
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 10.0.0.202 6379
sentinel known-slave mymaster 10.0.0.203 6379
sentinel known-sentinel mymaster 10.0.0.201 26379 32683a0682eb6db5bbb180b825fed609ed46c5c8
sentinel known-sentinel mymaster 10.0.0.202 26379 c935a3cf1827195dbf9437ec1f12fba40194d0c8
sentinel current-epoch 0
[root@db03 ~]#
8分别启动哨兵:
[root@db03 ~]# redis-sentinel /opt/redis_cluster/redis_26379/conf/redis_26379.conf
[root@db03 ~]# ps -ef|grep redis
root 1278 1248 0 16:51 pts/1 00:00:00 tail -f /opt/redis_cluster/redis_6379/logs/redis_6379.log
root 1530 1 0 17:14 ? 00:00:01 redis-server 10.0.0.203:6379
root 1543 1 1 17:22 ? 00:00:00 redis-sentinel 10.0.0.203:26379 [sentinel]
root 1547 1219 0 17:23 pts/0 00:00:00 grep --color=auto redis
[root@db03 ~]#
Error condition on socket for SYNC: Connection refused
原文:https://www.cnblogs.com/tyjs09/p/14639555.html