標籤:daemon 監控 127.0.0.1 append bsp -name cond failover ast
源碼樣本下載
連結: https://pan.baidu.com/s/1eTA63T4 密碼: un96
實現目標:
windows 下安裝 一台master服務 一台salve redis伺服器 並且哨兵模式監控實現主從切換
本次在兩台伺服器上分別部署一個sentinel 哨兵
windows https://github.com/MicrosoftArchive/redis/releases
A 10.55.8.110 B 10.55.8.111 兩台windows 伺服器
1、首先下載 windows 版本redis並解壓(官網是沒有windows版本)
A B 伺服器上個各方一份
#修改A伺服器上面的redis.windows.conf檔案
port 6379
bind 10.55.8.110
#日誌存放
logfile "C:/Users/Administrator/Desktop/Redis/redis-6379.log"
#資料庫存放
dir "C:\\Users\\Administrator\\Desktop\\Redis"
#client 串連需要的密碼
requirepass abc12345!
#slave伺服器串連需要的密碼
masterauth abc12345!
appendonly yes
maxmemory 8gb
修改B伺服器上面的redis.windows.conf檔案
port 6379
bind 10.55.8.111
logfile "C:/Users/Administrator/Desktop/Redis/redis-6379.log"
dir "C:\\Users\\Administrator\\Desktop\\Redis"
requirepass abc12345!
masterauth abc12345!
appendonly yes
#串連到主伺服器
slaveof 10.55.8.110 6379
#slave 唯讀
slave-read-only yes
maxmemory 8gb
#A B 伺服器上分別建立兩個26379的檔案夾
#建立 sentinel.conf 設定檔,並配置如下
port 26379
#master01
daemonize yes
sentinel monitor master01 10.55.8.110 6379 1
#sentinel認定為master失效的時間
sentinel down-after-milliseconds master01 30000
sentinel auth-pass master01 abc12345!
sentinel config-epoch master01 3
dir "C:\\Users\\Administrator\\Desktop\\Redis\\26379"
logfile "C:/Users/Administrator/Desktop/Redis/26379/sentinel-26379.log"
過程中常使用的命令
server redis-server.exe redis.windows.conf 啟動伺服器
client redis-cli.exe -h 127.0.0.1 -p 6379 啟動用戶端
redis-server.exe c:\redis\26379\sentinel.conf --sentinel 啟動哨兵
info replication 查看主從裝置狀況
安裝成服務
redis-server.exe --service-install --service-name redis6379service redis.windows.conf //安裝
redis-server --service-start --service-name redis6379service //啟動
redis-server --service-stop --service-name redis6379service redis.windows.conf //停止
redis-server.exe --service-uninstall --service-name redis6379service redis.windows.conf //卸載
總結和坑 :
1、瞭解redis的基本配置介紹 (https://www.cnblogs.com/qq78292959/archive/2013/09/21/3331032.html)
2、整個配置過程 注意兩台伺服器互連
3、設定檔時 如加slaveof 10.55.8.110 6379 需要去除slaveof前面的空格
不然redis識別不了
4、密碼驗證要注意,不然會無法通過
另外 目前主機A 當掉之後,哨兵監控會自動切換到B ,B變成master
哨兵的設定檔自動變為監控B
但是A重新啟動之後 ,還不能重新變為master,預設變為B的從屬
想要讓A重新變為主伺服器 執行
redis-cli.exe -h 10.55.8.110 -p 26379
sentinel failover master01
Redis 部署主從哨兵 C#使用,實現自動擷取redis緩衝 執行個體1