ubuntu之redis集群配置

redis3版本以上支持集群

需要ruby的支持

root@iZ2zejfbthvbzs5lxf37vjZ:/usr/local/src/redis-3.2.9/src# apt-get install ruby

root@iZ2zejfbthvbzs5lxf37vjZ:/usr/local/src/redis-3.2.9/src# apt-get install rubygems

root@iZ2zejfbthvbzs5lxf37vjZ:/usr/local/src# gem install redis

在redis安装目录下创建redis-cluster文件夹(mkdir redis-cluster)

在redis-cluster下创建6个文件7000,7001,7002,7003,7004,7005

将你的redis.conf配置文件分别复制到这6个文件夹中,更改如下,跟文件名名字一样

port  7000                                        //端口7000,7001,7002,7003,7004,7005        
bind 本机ip                                       //默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访问对应的端口,无法创建集群
daemonize    yes                               //redis后台运行
pidfile  /var/run/redis_7000.pid          //pidfile文件对应7000,7001,7002,7003,7004,7005
cluster-enabled  yes                           //开启集群  把注释#去掉
cluster-config-file  nodes_7000.conf   //集群的配置  配置文件首次启动自动生成 7000,7001,7002,7003,7004,7005
cluster-node-timeout  15000                //请求超时  默认15秒,可自行设置
appendonly  yes                           //aof日志开启  有需要就开启,它会每次写操作都记录一条日志 

开启这6个redis服务

root@iZ2zejfbthvbzs5lxf37vjZ:/usr/local/src/redis-3.2.9/redis_cluster# redis-server /usr/local/src/redis-3.2.9/redis_cluster/7000/redis.conf
root@iZ2zejfbthvbzs5lxf37vjZ:/usr/local/src/redis-3.2.9/redis_cluster# redis-server /usr/local/src/redis-3.2.9/redis_cluster/7001/redis.conf
root@iZ2zejfbthvbzs5lxf37vjZ:/usr/local/src/redis-3.2.9/redis_cluster# redis-server /usr/local/src/redis-3.2.9/redis_cluster/7002/redis.conf
root@iZ2zejfbthvbzs5lxf37vjZ:/usr/local/src/redis-3.2.9/redis_cluster# redis-server /usr/local/src/redis-3.2.9/redis_cluster/7003/redis.conf
root@iZ2zejfbthvbzs5lxf37vjZ:/usr/local/src/redis-3.2.9/redis_cluster# redis-server /usr/local/src/redis-3.2.9/redis_cluster/7004/redis.conf
root@iZ2zejfbthvbzs5lxf37vjZ:/usr/local/src/redis-3.2.9/redis_cluster# redis-server /usr/local/src/redis-3.2.9/redis_cluster/7005/redis.conf

创建集群(其中redis-trib.rb在你的redis安装目录/src下)

root@iZ2zejfbthvbzs5lxf37vjZ:/usr/local/src# /usr/local/src/redis-3.2.9/src/redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

可以看到创建集群成功了:

 设置redis集群密码

如下图,逐一设置redis密码:

 

posted @ 2017-06-15 14:18  岁月静好13543  阅读(1769)  评论(0编辑  收藏  举报
AmazingCounters.com