2台机器安装Redis主从

2台机器安装Redis主从

 

1. 配置redis.conf(主)

bind 127.0.0.1 #注释掉

protected-mode no #关闭保护模式

daemonize yes #开启后台守护进程

logfile "/var/log/redis/redis.log" #日志文件路径

2.配置redis.conf(从)

bind 127.0.0.1 #注释掉

protected-mode no #关闭保护模式

daemonize yes #开启后台守护进程

logfile "/var/log/redis/redis.log" #日志文件路径

slaveof 192.168.1.202 6379#主redis的ip地址与端口

 

 

3. 配置sentinel.conf(主)

sentinel monitor mymaster 192.168.1.202 6379 2 #改成主redis的ip与端口

daemonize yes #开启后台守护进程

protected-mode no #关闭保护模式

logfile "/var/log/redis/sentinel.log" #日志文件路径

4. 配置sentinel.conf(从)

sentinel monitor mymaster 192.168.1.202 6379 2 #改成主redis的ip与端口

daemonize yes #开启后台守护进程

 

protected-mode no #关闭保护模式

logfile "/var/log/redis/sentinel.log" #日志文件路径

配置成功后重新启动服务器

5. 启动主机

启动主redis

[root@hadoop2 ~]# /usr/local/bin/redis-server /etc/redis6379.conf

[root@hadoop2 ~]# /usr/local/bin/redis-sentinel /etc/sentinel6379.conf

[root@hadoop2 ~]# redis-cli

启动从redis

[root@hadoop3 ~]# /usr/local/bin/redis-server /etc/redis6379.conf

[root@hadoop3 ~]# /usr/local/bin/redis-sentinel /etc/sentinel6379.conf

[root@hadoop3 ~]# redis -cli

主redis设置key value 

 

从redis get key

 

 6.查看信息info

主redis信息

127.0.0.1:6379> info

 

 

 

 

 从redis信息

127.0.0.1:6379> info 

 

 

 

从服务器的redis

tail -f /var/log/redis/redis.conf 

如果出现

错误日志

24421:S 07 Dec 2023 13:50:58.320 * (Non critical) Master does not understand REPLCONF listening-port: -NOAUTH Authentication required.
24421:S 07 Dec 2023 13:50:58.346 * (Non critical) Master does not understand REPLCONF capa: -NOAUTH Authentication required.
24421:S 07 Dec 2023 13:50:58.346 * Partial resynchronization not possible (no cached master)
24421:S 07 Dec 2023 13:50:58.371 # Unexpected reply to PSYNC from master: -NOAUTH Authentication required.
24421:S 07 Dec 2023 13:50:58.371 * Retrying with SYNC...
24421:S 07 Dec 2023 13:50:58.396 # MASTER aborted replication with an error: NOAUTH Authentication required.
24421:S 07 Dec 2023 13:50:58.396 * Reconnecting to MASTER 47.105.44.226:6379 after failure
24421:S 07 Dec 2023 13:50:58.396 * MASTER <-> REPLICA sync started
24421:S 07 Dec 2023 13:50:58.410 * Non blocking connect for SYNC fired the event.
24421:S 07 Dec 2023 13:50:58.424 * Master replied to PING, replication can continue...

 

需要再 redis.conf  从服务器添加

 

masterauth 你的主密码


正常日志 
7663:S 07 Dec 2023 13:55:58.393 * MASTER <-> REPLICA sync: Flushing old data
7663:S 07 Dec 2023 13:55:58.393 * MASTER <-> REPLICA sync: Loading DB in memory
7663:S 07 Dec 2023 13:55:58.401 * Loading RDB produced by version 7.0.12
7663:S 07 Dec 2023 13:55:58.401 * RDB age 8 seconds
7663:S 07 Dec 2023 13:55:58.401 * RDB memory usage when created 9.51 Mb
7663:S 07 Dec 2023 13:55:58.420 * Done loading RDB, keys loaded: 2733, keys expired: 0.
7663:S 07 Dec 2023 13:55:58.420 * MASTER <-> REPLICA sync: Finished with success

 

posted @ 2023-12-07 11:15  不会游泳的鱼丶  阅读(72)  评论(0编辑  收藏  举报