docker啓動redis集羣(不考慮持久化)

(一)用docker啓動6個REDIS,3主3從,操做前先拉取redis鏡像node

sudo docker run -p 9379:9379 -p 19379:19379 --network=host --name redis-20180909_01 -v /home/jdx100424/dockerInfo/redisCluster/:/etc/redis/ -d redis redis-server /etc/redis/redis1.confredis

sudo docker run -p 9380:9380 -p 19380:19380 --network=host --name redis-20180909_02 -v /home/jdx100424/dockerInfo/redisCluster/:/etc/redis/ -d redis redis-server /etc/redis/redis2.confdocker

sudo docker run -p 9381:9381 -p 19381:19381 --network=host --name redis-20180909_03 -v /home/jdx100424/dockerInfo/redisCluster/:/etc/redis/ -d redis redis-server /etc/redis/redis3.confruby

sudo docker run -p 9382:9382 -p 19382:19382 --network=host --name redis-20180909_04 -v /home/jdx100424/dockerInfo/redisCluster/:/etc/redis/ -d redis redis-server /etc/redis/redis4.confbash

sudo docker run -p 9383:9383 -p 19383:19383 --network=host --name redis-20180909_05 -v /home/jdx100424/dockerInfo/redisCluster/:/etc/redis/ -d redis redis-server /etc/redis/redis5.confui

sudo docker run -p 9384:9384 -p 19384:19384 --network=host --name redis-20180909_06 -v /home/jdx100424/dockerInfo/redisCluster/:/etc/redis/ -d redis redis-server /etc/redis/redis6.confserver

注:dockerfile

(1)因爲redis.conf須要修改,因此須要把文件設置映射,除了修改端口外,文件要加上如下內容(把註釋#去掉)it

cluster-enabled  yes                      //開啓集羣
cluster-config-file  nodes.conf     
cluster-node-timeout  5000 io

而後把bind註釋掉(docker好像不能用這個,用了好像會不能啓動容器)

(2)docker啓動run要增長-p 19379:19379 --network=host,19379是本身定義的端口+10000,network也要加,不然在創建集羣關係時候,會跑去172.17.0.1去尋找的

 

(二)建立ruby鏡像,且鏡像包含相關的配置

下載redis-trib.rb,地址:

http://download.redis.io/redis-stable/src/redis-trib.rb  

 

dockerfile,

FROM docker.io/ruby:latest

RUN gem install redis #ruby使用redis

COPY redis-trib.rb /usr/local/  #redis-trib.rb是開啓集羣用的,須要從宿主機複製一份過去

建立鏡像,操做前先拉取ruby鏡像

sudo docker build -t ruby-redis:1.0.0-SNAPSHOT  /home/jdx100424/dockerInfo/redisCluster --no-cache

 

(三)使用如下方式建立容器啓動

sudo docker run -itd ruby-redis:1.0.0-SNAPSHOT /bin/bash 

要使用it,由於等下要進去處理集羣

 

(四)進入容器使用集羣

/usr/local/redis-trib.rb create --replicas 1 192.168.196.137:9379 192.168.196.137:9380 192.168.196.137:9381 192.168.196.137:9382 192.168.196.137:9383 192.168.196.137:9384

前面3個是主,後面3個是從

相關文章
相關標籤/搜索