您好,登錄后才能下訂單哦!
這篇文章主要講解了“docker如何搭建redis主從哨兵集群”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“docker如何搭建redis主從哨兵集群”吧!
docker pull redis:6.2.7
cd /opt/docker/redis vi docker-compose.yml
docker-compose.yml的內(nèi)容如下
version: '3' services: master: image: redis:6.2.7 ## 鏡像 container_name: redis-master command: redis-server /etc/redis/redis.conf --requirepass 123456 --masterauth 123456 volumes: - /opt/docker/redis/data/redis_data1:/data - /opt/docker/redis/conf/redis1.conf:/etc/redis/redis.conf network_mode: "host" slave1: image: redis:6.2.7 ## 鏡像 container_name: redis-slave-1 volumes: - /opt/docker/redis/data/redis_data2:/data - /opt/docker/redis/conf/redis2.conf:/etc/redis/redis.conf command: redis-server /etc/redis/redis.conf --slaveof redis-master 6379 --requirepass 123456 --masterauth 123456 depends_on: - master network_mode: "host" slave2: image: redis:6.2.7 ## 鏡像 container_name: redis-slave-2 volumes: - /opt/docker/redis/data/redis_data3:/data - /opt/docker/redis/conf/redis3.conf:/etc/redis/redis.conf command: redis-server /etc/redis/redis.conf --slaveof redis-master 6379 --requirepass 123456 --masterauth 123456 depends_on: - master network_mode: "host" sentinel1: image: redis:6.2.7 ## 鏡像 container_name: redis-sentinel-1 command: redis-sentinel /usr/local/etc/redis/sentinel.conf volumes: - /opt/docker/redis/conf/sentinel1.conf:/usr/local/etc/redis/sentinel.conf network_mode: "host" depends_on: - master - slave1 - slave2 sentinel2: image: redis:6.2.7 ## 鏡像 container_name: redis-sentinel-2 command: redis-sentinel /usr/local/etc/redis/sentinel.conf volumes: - /opt/docker/redis/conf/sentinel2.conf:/usr/local/etc/redis/sentinel.conf network_mode: "host" depends_on: - master - slave1 - slave2 sentinel3: image: redis:6.2.7 ## 鏡像 container_name: redis-sentinel-3 command: redis-sentinel /usr/local/etc/redis/sentinel.conf volumes: - /opt/docker/redis/conf/sentinel3.conf:/usr/local/etc/redis/sentinel.conf network_mode: "host" depends_on: - master - slave1 - slave2
查看配置文件的目錄樹(shù)
cd /opt/docker/redis tree ./
結(jié)構(gòu)如下
redis1.conf,redis2.conf,redis3.conf配置如下
#redis1.conf bind 0.0.0.0 port 6379 protected-mode no slave-read-only no #redis2.conf bind 0.0.0.0 port 6380 protected-mode no slave-read-only no #redis3.conf bind 0.0.0.0 port 6381 protected-mode no slave-read-only no
sentinel1.conf,sentinel1.conf,sentinel1.conf配置:
#sentinel1.conf port 26379 dir /tmp sentinel monitor mymaster 192.168.18.131 6379 2 sentinel auth-pass mymaster 123456 sentinel down-after-milliseconds mymaster 30000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 10000 sentinel deny-scripts-reconfig yes #sentinel2.conf port 26380 dir /tmp sentinel monitor mymaster 192.168.18.131 6379 2 sentinel auth-pass mymaster 123456 sentinel down-after-milliseconds mymaster 30000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 10000 sentinel deny-scripts-reconfig yes #sentinel3.conf port 26381 dir /tmp sentinel monitor mymaster 192.168.18.131 6379 2 sentinel auth-pass mymaster 123456 sentinel down-after-milliseconds mymaster 30000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 10000 sentinel deny-scripts-reconfig yes
說(shuō)明:
【sentinel monitor mymaster 192.168.18.131 6379 2】192.168.18.131為服務(wù)器的IP地址,6379為redis master的端口號(hào)
【sentinel auth-pass mymaster 123456 】設(shè)置主節(jié)點(diǎn)的密碼
【sentinel down-after-milliseconds mymaster 30000】表示在一段時(shí)間范圍內(nèi)sentinel向master發(fā)送的心跳PING沒(méi)有回復(fù)則認(rèn)為master不可用了。
【sentinel parallel-syncs mymaster 1】的parallel-syncs表示設(shè)置在故障轉(zhuǎn)移之后,同時(shí)可以重新配置使用新master的slave的數(shù)量。數(shù)字越低,更多的時(shí)間將會(huì)用故障轉(zhuǎn)移完成,但是如果slaves配置為服務(wù)舊數(shù)據(jù),你可能不希望所有的slave同時(shí)重新同步master。因?yàn)橹鲝膹?fù)制對(duì)于slave是非阻塞的,當(dāng)停止從master加載批量數(shù)據(jù)時(shí)有一個(gè)片刻延遲。通過(guò)設(shè)置選項(xiàng)為1,確信每次只有一個(gè)slave是不可到達(dá)的。
【sentinel failover-timeout mymaster 10000 】表示10秒內(nèi)mymaster還沒(méi)活過(guò)來(lái),則認(rèn)為master宕機(jī)了。
redis_data1, redis_data2,redis_data3為空文件夾,用于存放redis數(shù)據(jù)文件
docker-compose up #或者,后臺(tái)啟動(dòng) docker-compose up -d
docker exec -it 主節(jié)點(diǎn)容器id或者容器名稱 bash redis-cli -p 6379 info replication
感謝各位的閱讀,以上就是“docker如何搭建redis主從哨兵集群”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)docker如何搭建redis主從哨兵集群這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。