redis的主從和哨兵模式(一主二從)
阿新 • • 發佈:2018-12-27
Redis的主從及哨兵模式的搭建(一主二從)
一.搭建主從模式
- 首先在linux中安裝好redis(這裡就不詳細介紹)
- 然後複製redis.conf複製出兩份(我們這裡用16379,26379作為從節點
cp redis.conf redis-16379.conf
cp redis.conf redis-26379.conf
- 修改redis-16379.conf檔案
vi redis-16379.conf bind 127.0.0.1 伺服器ip daemonize yes pidfile "/var/run/redis16379.pid" port 16379 從redis埠 logfile "16379.log" dbfilename "dump16379.rdb" # Generated by CONFIG REWRITE dir "/tpsys/redis-409/conf" slaveof 127.0.0.1 6379 主節點
(修改redis-26379.conf同上,對應的日誌檔案要名字要做修改,然後啟動即完成配置,使用redis-cli -p 6379 -h 127.0.0.1進入對應的埠後使用info命令可檢視是否配置成功)
二.哨兵模式
1.建立sentinel-6379.conf檔案
2.編輯sentinel-6379.conf
daemonize yes bind 127.0.0.1 port 6389 dir "/tpsys/redis-409/conf" sentinel monitor mymaster 127.0.0.1 6379 1 mymaster:哨兵監控的master名 127.0.0.1 6379:主節點
3.複製出sentinel-6399.conf和sentinel-6309.conf
編輯sentinel-6399.conf
daemonize yes
bind 127.0.0.1
port 6399
dir "/tpsys/redis-409/conf"
sentinel monitor mymaster 127.0.0.1 6379 1
(編輯sentinel-6309.conf同上)
以上就是redis的主從和哨兵模式搭建的詳細過程,如有疑問請留言。