鍦╠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
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
/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
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 绔彛
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
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
鎺ㄨ崘涓€涓浂閰嶇疆寮€绠卞嵆鐢ㄧ殑React/Vue搴旂敤鑷姩鍖栨瀯寤鸿剼鎵嬫灦锛屼笉寮哄ぇ浣犳潵鎵炬垜
鍩轰簬SpringBoot鎼缓涓€涓甫鏁版嵁搴撹闂殑WEB椤圭洰(璁板綍鎵€闇€鐨勪緷璧?閰嶇疆,椹卞姩瀹夎绛夋敞鎰忎簨椤?