-----------------跳过了安装redis的过程---------------------------
主 | 192.168.25.129 |
从 | 192.168.25.130 |
从 | 192.168.25.133 |
redis主从复制环境,基本上都是在从服务器上修改相关的配置
1、在俩台从服务器分别给 reids.conf文件添加master主配置信息
#主服务器的ip和端口
replicaof 192.168.25.129 6379
#配置只读 在新版是replica-read-only 旧版本是slave-read-only
replica-read-only yes
# 如果你的redis主有密码 就在从节点reids,conf配置文件里面找到关键字masterauth开打注释添加密码
# masterauth <master-password>
2、然后把主redis先启动运行
[root@k8s-129 redis]# ./bin/redis-server conf/redis.conf &
[1] 10312
[root@k8s-129 redis]#
[1]+ Done ./bin/redis-server conf/redis.conf
[root@k8s-129 redis]# tailf log/redis_6363.log
bin/ conf/ data/ log/ run/
[root@k8s-129 redis]# tailf log/redis_6363.log
10313:C 05 Jul 2024 14:32:13.895 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
10313:C 05 Jul 2024 14:32:13.897 # Redis version=6.2.12, bits=64, commit=00000000, modified=0, pid=10313, just started
10313:C 05 Jul 2024 14:32:13.897 # Configuration loaded
10313:M 05 Jul 2024 14:32:13.898 * Increased maximum number of open files to 10032 (it was originally set to 1024).
10313:M 05 Jul 2024 14:32:13.898 * monotonic clock: POSIX clock_gettime
10313:M 05 Jul 2024 14:32:13.899 * Running mode=standalone, port=6379.
10313:M 05 Jul 2024 14:32:13.899 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
10313:M 05 Jul 2024 14:32:13.899 # Server initialized
10313:M 05 Jul 2024 14:32:13.916 * DB loaded from append only file: 0.011 seconds
10313:M 05 Jul 2024 14:32:13.916 * Ready to accept connections
3、启动其它俩台从服务器,主的redis日志会刷新从节点连接
10313:M 05 Jul 2024 14:32:31.472 * Replica 192.168.25.130:6379 asks for synchronization
10313:M 05 Jul 2024 14:32:31.474 * Full resync requested by replica 192.168.25.130:6379
10313:M 05 Jul 2024 14:32:31.474 * Replication backlog created, my new replication IDs are '347a6808b596806c52e9c1ae71426e0753cfd5bb' and '0000000000000000000000000000000000000000'
10313:M 05 Jul 2024 14:32:31.474 * Starting BGSAVE for SYNC with target: disk
10313:M 05 Jul 2024 14:32:31.475 * Background saving started by pid 10434
10434:C 05 Jul 2024 14:32:31.557 * DB saved on disk
10434:C 05 Jul 2024 14:32:31.558 * RDB: 0 MB of memory used by copy-on-write
10313:M 05 Jul 2024 14:32:31.563 * Background saving terminated with success
10313:M 05 Jul 2024 14:32:31.564 * Synchronization with replica 192.168.25.130:6379 succeeded10313:M 05 Jul 2024 14:32:43.317 * Replica 192.168.25.133:6379 asks for synchronization
10313:M 05 Jul 2024 14:32:43.326 * Full resync requested by replica 192.168.25.133:6379
10313:M 05 Jul 2024 14:32:43.327 * Starting BGSAVE for SYNC with target: disk
10313:M 05 Jul 2024 14:32:43.327 * Background saving started by pid 10447
10447:C 05 Jul 2024 14:32:43.420 * DB saved on disk
10447:C 05 Jul 2024 14:32:43.420 * RDB: 0 MB of memory used by copy-on-write
10313:M 05 Jul 2024 14:32:43.546 * Background saving terminated with success
10313:M 05 Jul 2024 14:32:43.555 * Synchronization with replica 192.168.25.133:6379 succeeded
4、命令确认节点配置成功
[root@k8s-129 ~]# redis-cli -p 6379 info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.25.130,port=6379,state=online,offset=992,lag=1
slave1:ip=192.168.25.133,port=6379,state=online,offset=1006,lag=1
master_failover_state:no-failover
master_replid:347a6808b596806c52e9c1ae71426e0753cfd5bb
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:1006
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:1006
[root@k8s-129 ~]#
5、在主服务器验证数据同步
主
root@k8s-129 ~]# redis-cli
127.0.0.1:6379> set name vV
OK
127.0.0.1:6379> exit
从
[root@k8s-130 redis]# redis-cli
127.0.0.1:6379> get name
"vV"
127.0.0.1:6379> exit[root@localhost redis]# redis-cli
127.0.0.1:6379> get name
"vV"
6、验证主服务器
1、问题,在连接主服务器连接被拒绝
1、确保主配置文件的 bind 0.0.0.0 可以任何ip进行访问