鍦╠ocker涓儴缃瞨edis涓讳粠閰嶇疆

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鍦╠ocker涓儴缃瞨edis涓讳粠閰嶇疆相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/link' title='link'>link   online   format   nec   data   ubunt   鍚姩   first   ports   

鐜璇存槑锛?/p>

  • 闃块噷浜戞湇鍔″櫒
  • Ubuntu 16.04
  • docker

 

1銆佹媺鍙朢edis闀滃儚

docker pull redis

 

 

2銆侀厤缃甊edis鍚姩閰嶇疆鏂囦欢锛屾澶勬垜鍒涘缓涓€涓笓鐢ㄧ洰褰曪紝瀛樻斁Redis鐩稿叧鏁版嵁鍙婇厤缃?/h3>
mkdir /docker/redis

鍦ㄦ鐩綍涓嬩笅杞芥湇鍔″惎鍔ㄩ厤缃枃浠?/p>

wget http://download.redis.io/redis-stable/redis.conf

涓嬭浇鍚庯紝杩涘叆鏂囦欢淇敼涓嬮潰3涓弬鏁帮紙鍦ㄩ潪缂栬緫鐘舵€佷笅锛岄噰鐢?/bind 鏉ユ悳绱㈠瓧绗︿覆浣嶇疆 锛?/p>

vim  /docker/redis/redis.conf 
# 淇敼涓嬮潰涓変釜閰嶇疆鍙傛暟 #bind
127.0.0.1 #濡傛灉bind閫夐」涓虹┖鐨勮瘽锛屽垯鍏佽鎵€鏈夋潵鑷簬鍙敤缃戠粶鎺ュ彛鐨勮繛鎺?protected-mode no #淇濇姢妯″紡锛岃嫢涓簓es锛屽彧鍏佽鏈湴瀹㈡埛绔繛鎺?appendonly yes #寮€鍚悗锛孯edis浼氭妸姣忔鍐欏叆鐨勬暟鎹湪鎺ユ敹鍚庨兘鍐欏叆 appendonly.aof 鏂囦欢锛屾瘡娆″惎鍔ㄦ椂Redis閮戒細鍏堟妸杩欎釜鏂囦欢鐨勬暟鎹鍏ュ唴瀛橀噷

 

 

3銆佸湪姝ょ洰褰曚笅鏂板缓Master锛坮edis6379锛夋枃浠跺す锛屽苟澶嶅埗涓婅堪conf鏂囦欢鑷虫枃浠跺す涓紝 Master鐨?conf 鏂囦欢璺緞涓?/h3>
/docker/redis/redis6379/redis.conf

 

 

4銆佸埄鐢?conf 鍒涘缓 Master 瀹瑰櫒

# --restart always (docker鍚姩鏃讹紝鏈暅鍍忎篃鑷姩鍚姩) 
# --name 瀹瑰櫒鍚嶄负 redis-6379
# -p 鏄犲皠鏈湴绔彛 6379 鑷冲鍣ㄧ鍙?6379
# -v 缁戝畾Master鐩綍 /docker/redis/redis6379 鏄犲皠鑷?docker 涓殑 /data
# -d 鍚庡彴杩愯瀹瑰櫒锛屽苟杩斿洖瀹瑰櫒ID
# 鎸囧畾闀滃儚 redis
# 鍒╃敤 conf 鍚姩鏈嶅姟 redis-server /data/redis.conf

docker run --restart always --name redis-6379 -p 6379:6379 -v /docker/redis/redis6379:/data -d redis redis-server /data/redis.conf

 

 

5銆佹煡鐪嬪鍣ㄥ惎鍔ㄦ儏鍐?/h3>
root@iZ282zj76jqZ:/docker/redis/redis6379# docker ps |grep redis-6379
792067d225e6        redis               "docker-entrypoint.s…"   2 hours ago         Up 2 hours          0.0.0.0:6379->6379/tcp              redis-6379

鏌ョ湅 Master 瀹瑰櫒鐨処P锛岀敤浜庨厤缃?Salve 涓殑鍙傛暟

# 鏌ョ湅 Master 瀹瑰櫒 IP,
# docker inspect redis-6379 鏌ョ湅 NetworkSettings 閰嶇疆涓?IPAdress docker inspect
--format=鈥?/span>{{.NetworkSettings.IPAddress}}鈥?/span> redis-6379 # 192.168.0.4

 

 

6銆佸垱寤?Salve 鏂囦欢澶癸紙redis6380 銆乺edis6381 銆?redis6382锛夛紝澶嶅埗涓婅堪 redis.conf 鏂囦欢鍒嗗埆鑷充笁涓す涓紝骞充慨鏀归厤缃?/h3>
vim  /docker/redis/redis.conf 

# 淇敼涓嬮潰鍥涗釜閰嶇疆鍙傛暟
#bind 127.0.0.1        #濡傛灉bind閫夐」涓虹┖鐨勮瘽锛屽垯鍏佽鎵€鏈夋潵鑷簬鍙敤缃戠粶鎺ュ彛鐨勮繛鎺?protected-mode no      #淇濇姢妯″紡锛岃嫢涓簓es锛屽彧鍏佽鏈湴瀹㈡埛绔繛鎺?appendonly yes         #寮€鍚悗锛孯edis浼氭妸姣忔鍐欏叆鐨勬暟鎹湪鎺ユ敹鍚庨兘鍐欏叆 appendonly.aof 鏂囦欢锛屾瘡娆″惎鍔ㄦ椂Redis閮戒細鍏堟妸杩欎釜鏂囦欢鐨勬暟鎹鍏ュ唴瀛橀噷

# replicaof <master ip> <master port>
replicaof 192.168.0.4 6379 #Redis涓绘満(Master)IP 绔彛

鍚姩涓変釜 Salve 鏈嶅姟

docker run --restart always --name redis-6380 -p 6380:6379 -v /docker/redis/redis6380:/data -d redis redis-server /data/redis.conf
docker run --restart always --name redis-6381 -p 6381:6379 -v /docker/redis/redis6381:/data -d redis redis-server /data/redis.conf
docker run --restart always --name redis-6382 -p 6382:6379 -v /docker/redis/redis6382:/data -d redis redis-server /data/redis.conf

 

 

7銆佹煡鐪嬪鍣ㄦ湇鍔?/h3>
root@iZ282zj76jqZ:/docker/redis# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
43488a8c668c        redis               "docker-entrypoint.s…"   3 seconds ago       Up 1 second         0.0.0.0:6382->6379/tcp              redis-6382
ca3caaa77f4a        redis               "docker-entrypoint.s…"   2 hours ago         Up About an hour    0.0.0.0:6381->6379/tcp              redis-6381
792067d225e6        redis               "docker-entrypoint.s…"   2 hours ago         Up 2 hours          0.0.0.0:6379->6379/tcp              redis-6379
979318c633be        redis               "docker-entrypoint.s…"   2 hours ago         Up About an hour    0.0.0.0:6380->6379/tcp              redis-6380

杩涘叆 Master 瀹瑰櫒鎿嶄綔 Redis

root@iZ282zj76jqZ:/docker/redis# docker exec -it redis-6379 /bin/bash
root@792067d225e6:/data# redis-cli
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:3
slave0:ip=192.168.0.3,port=6379,state=online,offset=7129,lag=1
slave1:ip=192.168.0.6,port=6379,state=online,offset=7129,lag=0
slave2:ip=192.168.0.5,port=6379,state=online,offset=7129,lag=0
master_replid:09e8f31f23d920034b8f5e20749489ffff3fec17
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:7143
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:6892
repl_backlog_histlen:252
127.0.0.1:6379> dbsize
(integer) 3

杩涘叆Salve 瀹瑰櫒鎿嶄綔Redis

root@iZ282zj76jqZ:~# docker exec -it redis-6381 /bin/bash
root@ca3caaa77f4a:/data# redis-cli
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:192.168.0.4
master_port:6379
master_link_status:down
master_last_io_seconds_ago:-1
master_sync_in_progress:0
slave_repl_offset:6891
master_link_down_since_seconds:8
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:7d6ef858609048f3210a178772ea98ac20446c9e
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:6891
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1027
repl_backlog_histlen:5865
127.0.0.1:6379> dbsize
(integer) 3

 

 

8銆佷篃鍙互鐩存帴鐢╠ocker鍛戒护鎿嶄綔Redis

# -it 涓哄鍣ㄩ噸鏂板垎閰嶄竴涓吉杈撳叆缁堢锛屼互浜や簰妯″紡杩愯瀹瑰櫒
# 瀹瑰櫒鍚?redis-6379
# redis-cli set  Key Value 
docker exec -it redis-6379 redis-cli set name tomkluas

 

 

以上是关于鍦╠ocker涓儴缃瞨edis涓讳粠閰嶇疆的主要内容,如果未能解决你的问题,请参考以下文章

MySQL涓讳粠澶辫触鎶ラ敊璇細 Got fatal error 1236

閰嶇疆鏂囦欢瑙e喅JSON涓枃涔辩爜

鎺ㄨ崘涓€涓浂閰嶇疆寮€绠卞嵆鐢ㄧ殑React/Vue搴旂敤鑷姩鍖栨瀯寤鸿剼鎵嬫灦锛屼笉寮哄ぇ浣犳潵鎵炬垜

鍩轰簬SpringBoot鎼缓涓€涓甫鏁版嵁搴撹闂殑WEB椤圭洰(璁板綍鎵€闇€鐨勪緷璧?閰嶇疆,椹卞姩瀹夎绛夋敞鎰忎簨椤?

mariadb涓讳粠

mysql涓讳粠澶嶅埗