2019-04-03 09:15:14
李明
|
redis
搭建集群 应用IP地址服务配置安装应用安装方式docker-mysql192.168.66.101docker-redis-cluster双核 8g内存docker-redis-clusterdocker (1). 虚拟机vagrant讲述安装的步骤 vagrant up (2).机器window/mac开通远程登录root用户下 su - # 密码 vagrant #设置 PasswordAuthentication yes vi /etc/ssh/sshd_configsudo systemctl restart sshd
mkdir redis-clustercd redis-clustermkdir r1cd r1vi redis.confmkdir datacd ~
直接看github我提交的源码吧 一共要创建6个redis集群
docker run -it -d \-v /root/redis-cluster/r1/redis.conf:/etc/redis/redis.conf \--name r1 -p 5001:6379 \--net=net2 \--ip 172.19.0.2 \zhugeaming1314/redis bash
docker exec -it r1 bashcd /usr/redis/src./redis-server /etc/redis/redis.conf
docker run -it -d \-v /root/redis-cluster/r2/redis.conf:/etc/redis/redis.conf \--name r2 -p 5002:6379 \--net=net2 \--ip 172.19.0.3 \zhugeaming1314/redis bash
docker exec -it r2 bashcd /usr/redis/src./redis-server /etc/redis/redis.conf
docker run -it -d \-v /root/redis-cluster/r3/redis.conf:/etc/redis/redis.conf \--name r3 -p 5003:6379 \--net=net2 \--ip 172.19.0.4 \zhugeaming1314/redis bash
docker exec -it r3 bashcd /usr/redis/src./redis-server /etc/redis/redis.conf
docker run -it -d \-v /root/redis-cluster/r4/redis.conf:/etc/redis/redis.conf \--name r4 -p 5004:6379 \--net=net2 \--ip 172.19.0.5 \zhugeaming1314/redis bash
docker exec -it r4 bashcd /usr/redis/src./redis-server /etc/redis/redis.conf
docker run -it -d \-v /root/redis-cluster/r5/redis.conf:/etc/redis/redis.conf \--name r5 -p 5005:6379 \--net=net2 \--ip 172.19.0.6 \zhugeaming1314/redis bash
docker exec -it r5 bashcd /usr/redis/src./redis-server /etc/redis/redis.conf
docker run -it -d \-v /root/redis-cluster/r6/redis.conf:/etc/redis/redis.conf \--name r6 -p 5006:6379 \--net=net2 \--ip 172.19.0.7 \zhugeaming1314/redis bash
docker exec -it r6 bashcd /usr/redis/src./redis-server /etc/redis/redis.conf redis-trib.rb
docker exec -it r1 bashcd /usr/redismkdir clustercd srccp redis-trib.rb ../clustercd ../cluster./redis-trib.rb create --replicas 1 172.19.0.2:6379 172.19.0.3:6379 172.19.0.4:6379 172.19.0.5:6379 172.19.0.6:6379 172.19.0.7:6379 image.png
docker exec -it r1 bash/usr/redis/src/redis-cli -ccluster nodes !/upload-images.jianshu.io/upload_images/11223715-0123418e8224c25c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
redis集群密码设置
masterauth idig8.comrequirepass idig8.com 说明:这种方式需要重新启动各节点
./redis-cli -c -p 6379 config set masterauth idig8.comconfig set requirepass idig8.com config rewrite 之后分别使用./redis-cli -c -p 6379,./redis-cli -c -p 6379…..命令给各节点设置上密码。 注意:各个节点密码都必须一致,否则Redirected就会失败, 推荐这种方式,这种方式会把密码写入到redis.conf里面去,且不用重启。 用方式二修改密码,./redis-trib.rb check 172.19.0.2:6379执行时可能会报[ERR] Sorry, can't connect to node 172.19.0.2:6379,因为6379的redis.conf没找到密码配置。
class Client DEFAULTS = { :url => lambda { ENV["REDIS_URL"] }, :scheme => "redis", :host => "127.0.0.1", :port => 6379, :path => nil, :timeout => 5.0, :password => "idig8.com", :db => 0, :driver => nil, :id => nil, :tcp_keepalive => 0, :reconnect_attempts => 1, :inherit_socket => false } 注意:client.rb路径可以通过find命令查找:find / -name 'client.rb' 带密码访问集群 ./redis-cli -c -p 6379-a idig8.com PS:整个redis集群已经安装完毕,3个master3个salve,如果1个master挂了对应的slave自动升级为master,挂的原来的master如果重新启动就变成了slave。我尝试用官方的docker镜像redis来进行全流程的安装,在docker run命令中加入配置文件启动,这种方式是有问题的,到创建集群的时候还是会报错的,还是建议用我的镜像,这样稳定些。并且里面自带redis-trib.rb。 |