背景:
隨着業務上漲,有可能會因為機器資源緊張,從而導致單個Redis服務器不夠用,往往需要在同一台機器中部署兩個Redis或者Sentinel服務來保障更穩定的集群架構。
1.多個Redis部署
第一個Redis服務6379端口的安裝配置這里不作介紹。
可以參考我的前幾篇隨筆中的介紹(https://www.cnblogs.com/zyf98/p/15664985.html)
第二個Redis服務6380端口的部署與配置:
(主要是注意持久化文件的路徑和文件名不能和第一個Redis服務沖突)
sudo mkdir -p /etc/redis6380 //創建6380的配置文件目錄
sudo cp 原來的redis.conf 新的redis6380.conf //copy一份配置文件
sudo chown -R 用戶:用戶 /etc/redis6380 //修改文件權限與原來一致
sudo vim /etc/redis6380/redis6380.conf //修改6380的配置文件port 6380 //修改端口
redis6380.conf修改部分如下,其余部分不做修改:
logfile "/redis6380/redis6380.log" //修改日志文件路徑 dir "/redis6380" //修改持久化文件路徑 appendfilename "appendonly6380.aof" //不管開不開啟aof,先重命名下aof持久化文件 dbfilename "dump6380.rdb" //rdb持久化文件名
sudo mkdir -p /mnt/redis6380 //創建6380持久化文件目錄 sudo chown -R 用戶:用戶 /mnt/redis6380 //修改文件權限 cd /usr/lib/systemd/system/ sudo cp redis.service redis6380.service //copy systemd 文件 sudo vim redis6380.service //修改托管文件
redis6380.service文件修改如下,其余配置不做修改:(原來的redis.service具體配置可以參考我的前幾篇文章(https://www.cnblogs.com/zyf98/p/15664985.html))
ExecStart=/usr/local/bin/redis-server /etc/redis6380/redis6380.conf ExecStop=/usr/local/bin/redis-cli -h 本機IP -p 6380 shutdown
啟動Redis6380服務:
sudo systemctl start redis6380 //啟動redis6380
2.多個哨兵部署
原sentinel.conf配置文件參考:
port 26379 bind 本機IP dir "/redis" logfile "/redis/sentinel.log" daemonize yes loglevel notice sentinel deny-scripts-reconfig yes maxclients 4064 protected-mode no pidfile "/var/run/redis.pid" sentinel monitor mymaster 主服務IP 6379 2 sentinel down-after-milliseconds mymaster 20000
Sentinel26380部署與配置:
sudo cp 原sentinel.conf 新sentinel26380.conf //copy一份配置文件 vim sentinel26380.conf //編輯修改一下
sentinel26380.conf 修改如下,其余不做修改:
port 26380 dir "/redis6380" logfile "/redis6380/sentinel26380.log"
配置systemd啟動文件
cd /usr/lib/systemd/system/ sudo cp redis-sentinel.service redis-sentinel26380.service vim redis-sentinel26380.service
修改 部分redis-sentinel26380.service 文件,其余部分不做修改:
ExecStart=/usr/local/bin/redis-sentinel /redis6380/sentinel26380.conf ExecStop=/usr/local/bin/redis-cli -h 本機IP -p 26380 shutdown
啟動Sentinel26380:
sudo systemctl start redis-sentinel26380