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 从服务器添加
1 | masterauth 你的主密码<br><br><br> |
正常日志
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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2020-12-07 -bash: fork: Cannot allocate memory 问题的处理