主頁(yè) > 知識(shí)庫(kù) > Docker下redis的主從配置教程詳解

Docker下redis的主從配置教程詳解

熱門標(biāo)簽:咸陽(yáng)穩(wěn)定外呼系統(tǒng)公司 漯河電銷外呼系統(tǒng)價(jià)格 ec外呼系統(tǒng)怎么樣 蕪湖呼叫中心外呼系統(tǒng)哪家強(qiáng) 電銷機(jī)器人怎么錄音 貴陽(yáng)語(yǔ)音電銷機(jī)器人 天津外呼系統(tǒng)運(yùn)營(yíng)商 征服者快捷酒店地圖標(biāo)注 貴港市機(jī)器人外呼系統(tǒng)團(tuán)隊(duì)

1、拉取redis鏡像

docker pull redis

2、啟動(dòng)3個(gè)redis容器服務(wù),分別使用到6379、6380、6381端口

docker run --name redis-6379 -p 6379:6379 -d redis
docker run --name redis-6380 -p 6380:6379 -d redis
docker run --name redis-6381 -p 6381:6379 -dredis

3、查看容器

[tcy@tcy1 ~]$ docker ps -a
CONTAINER ID  IMAGE      COMMAND    CREATED    STATUS    PORTS     NAMES
a9fa77adc598  daocloud.io/library/redis "docker-entrypoint.s 2 hours ago   Up 2 hours   0.0.0.0:6381->6379/tcp redis-6381   
6ee2f2f007e6  daocloud.io/library/redis "docker-entrypoint.s 2 hours ago   Up 2 hours   0.0.0.0:6380->6379/tcp redis-6380   
ab54741166e1  daocloud.io/library/redis "docker-entrypoint.s 3 hours ago   Up 3 hours   0.0.0.0:6379->6379/tcp redis-6379

4、測(cè)試容器,成功

docker exec -it ab54741166e1 redis-cli:進(jìn)入容器
[root@tcy1 tcy]# docker exec -it ab54741166e1 redis-cli
127.0.0.1:6379> set b tcy
OK
127.0.0.1:6379> get b
"tcy"
127.0.0.1:6379> quit[root@tcy1 tcy]#

5、開始redis集群配置

5.1、看容器內(nèi)網(wǎng)的ip地址

[root@tcy1 tcy]# docker inspect a9fa77adc598

3個(gè)redis的內(nèi)網(wǎng)ip地址為:

redis-6379:172.17.0.1:6379
redis-6380:172.17.0.2:6379
redis-6381:172.17.0.3:6379

5.2、進(jìn)入docker容器內(nèi)部,查看當(dāng)前redis角色(主還是從)

[root@tcy1 tcy]# docker exec -it ab54741166e1 /bin/bash
root@ab54741166e1:/data# redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:0
master_replid:d43d1ae8cde6cb084220e18b926aba79e0bb2504
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
127.0.0.1:6379> quit
root@ab54741166e1:/data# exit 
exit

目前三個(gè)都是master狀態(tài)

5.3、使用redis-cli命令修改redis-6380、redis-6381的主機(jī)為172.17.0.1:6379

[root@tcy1 tcy]# docker exec -it a9fa77adc598 /bin/bash  //redis-6380
root@a9fa77adc598:/data# redis-cli
127.0.0.1:6379> SLAVEOF 172.17.0.1 6379
OK
127.0.0.1:6379> quit
root@a9fa77adc598:/data# exit
exit
[root@tcy1 tcy]# docker exec -it 6ee2f2f007e6 /bin/bash //redis-6381
root@6ee2f2f007e6:/data# redis-cli
127.0.0.1:6379> SLAVEOF 172.17.0.1 6379
OK
127.0.0.1:6379> quit

5.4、查看redis-6379是否已經(jīng)擁有2個(gè)從機(jī),connected_slaves:2,是的

[root@tcy1 tcy]# docker exec -it ab54741166e1 /bin/bash
root@ab54741166e1:/data# redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=172.17.0.3,port=6379,state=online,offset=378,lag=1
slave1:ip=172.17.0.2,port=6379,state=online,offset=378,lag=0
master_replid:ce193b15cfd57f7dc3ccfbf2a4aef6156b131e6d
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:378
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:378
127.0.0.1:6379> quit
root@ab54741166e1:/data# exit
exit

5.5、配置Sentinel哨兵

進(jìn)入3臺(tái)redis容器內(nèi)部進(jìn)行配置,在容器根目錄里面創(chuàng)建sentinel.conf文件

文件內(nèi)容為: sentinel monitor mymaster 172.17.0.1 6379 1

[root@tcy1 tcy]# docker exec -it a9fa77adc598 /bin/bash
root@a9fa77adc598:/data# cd / && touch sentinel.conf 
root@a9fa77adc598:/# vim /sentinel.conf

如果出現(xiàn):bash: vim: command not found

解決:1、apt-get update 2、apt-get install vim

最后,啟動(dòng)Redis哨兵:

root@a9fa77adc598:/# redis-sentinel /sentinel.conf
342:X 24 Jun 11:37:58.934 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
342:X 24 Jun 11:37:58.957 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=342, just started
342:X 24 Jun 11:37:58.958 # Configuration loaded
342:X 24 Jun 11:37:58.959 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
342:X 24 Jun 11:37:58.959 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
342:X 24 Jun 11:37:58.960 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
        _._                         
      _.-``__ ''-._                       
   _.-``  `. `_. ''-._      Redis 4.0.10 (00000000/0) 64 bit
 .-`` .-```. ```\/  _.,_ ''-._                  
 (  '   ,    .-` | `,  )   Running in sentinel mode
 |`-._`-...-` __...-.``-._|'` _.-'|   Port: 26379
 |  `-._  `._  /   _.-'  |   PID: 342
 `-._  `-._ `-./ _.-'  _.-'                  
 |`-._`-._  `-.__.-'  _.-'_.-'|                 
 |  `-._`-._    _.-'_.-'  |      http://redis.io    
 `-._  `-._`-.__.-'_.-'  _.-'                  
 |`-._`-._  `-.__.-'  _.-'_.-'|                 
 |  `-._`-._    _.-'_.-'  |                 
 `-._  `-._`-.__.-'_.-'  _.-'                  
   `-._  `-.__.-'  _.-'                    
     `-._    _.-'                      
       `-.__.-'                        
 
342:X 24 Jun 11:37:59.068 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
342:X 24 Jun 11:37:59.089 # Sentinel ID is dfd5a5bfe1036b1df3395c4ba858329034fc5b7e
342:X 24 Jun 11:37:59.091 # +monitor master mymaster 172.17.0.1 6379 quorum 1
342:X 24 Jun 11:37:59.110 * +slave slave 172.17.0.3:6379 172.17.0.3 6379 @ mymaster 172.17.0.1 6379
342:X 24 Jun 11:37:59.115 * +slave slave 172.17.0.2:6379 172.17.0.2 6379 @ mymaster 172.17.0.1 6379
 
342:X 24 Jun 11:39:27.601 * +sentinel sentinel ba9b0d0539d8273edfcbd922fe138f50daa78bbb 172.17.0.2 26379 @ mymaster 172.17.0.1 6379
342:X 24 Jun 11:41:59.144 * +sentinel sentinel f0510f8582b72c056531f219397ed8826683e665 172.17.0.1 26379 @ mymaster 172.17.0.1 6379

便于觀察,開多個(gè)窗口。

Sentinel哨兵配置完畢

5.6、測(cè)試

關(guān)閉Master

[tcy@tcy1 ~]$ docker stop ab54741166e1
ab54741166e1

這時(shí),剩余的2個(gè)從機(jī),會(huì)自動(dòng)選舉產(chǎn)生新的主機(jī),這里選舉172.17.0.2為主機(jī)。

查看172.17.0.2,變成了主機(jī)。

[root@tcy1 /]# docker exec -it 6ee2f2f007e6 /bin/bash
root@6ee2f2f007e6:/data# redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=172.17.0.3,port=6379,state=online,offset=66906,lag=1
master_replid:5a7489c8181ddf0d73d418d30d6a4c8e039198ba
master_replid2:ce193b15cfd57f7dc3ccfbf2a4aef6156b131e6d
master_repl_offset:67041
second_repl_offset:65534
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:85
repl_backlog_histlen:66957
127.0.0.1:6379> 

總結(jié)

以上所述是小編給大家介紹的Docker下redis的主從配置,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!

標(biāo)簽:濰坊 東營(yíng) 香港 西藏 怒江 攀枝花 淮北 西寧

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Docker下redis的主從配置教程詳解》,本文關(guān)鍵詞  Docker,下,redis,的,主從,配置,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Docker下redis的主從配置教程詳解》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Docker下redis的主從配置教程詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章