linux redis5.0 集群搭建

一、下载

  wget http://download.redis.io/releases/redis-5.0.0.tar.gz

二、解压、编译

  #解押到 /usr/local/ 文件夹

  tar -zxvf redis-5.0.0.tar.gz -C /usr/local/

  # 编译,并安装熬 /usr/local/redis 文件夹

  make & make install PREFIX=/usr/local/redis

  #复制 redis.conf 到安装目录

    cp -r  /usr/local/redis-5.0.0/redis.conf  /usr/local/redis

三、搭建集群

  #创建集群目录

  mkdir  /usr/local/redis-cluster

  # 复制redis原版到第一个集群节点文件夹

  cp -r /usr/local/redis/bin /usr/local/redis-cluster/7001

  # 打开 redis.conf 集群配置文件

  vim /usr/local/redis-cluster/7001/redis.conf

  # 配置下面内容

  daemonize yes

  bind 0.0.0.0

  protected-mode no
  port 7001
  requirepass "yingfeng365"
  masterauth "yingfeng365"

  cluster-enabled yes
  cluster-config-file /usr/local/redis-cluster/nodes_7001.conf
  cluster-node-timeout 5000
  pidfile /usr/local/redis-cluster/redis_7001.pid
  logfile "/usr/local/redis-cluster/redis_7001.log"
  dir /usr/local/redis-cluster/7001

  # 以第一个节点为原版,再复制五个节点,并修改 redis.conf 为对应端口

  cp -r /usr/local/redis-cluster/7001 /usr/local/redis-cluster/7002

四、启动节点

  /usr/local/redis-cluster/7001/redis-server /usr/local/redis-cluster/7001/redis.conf

  /usr/local/redis-cluster/7002/redis-server /usr/local/redis-cluster/7002/redis.conf
  /usr/local/redis-cluster/7003/redis-server /usr/local/redis-cluster/7003/redis.conf
  /usr/local/redis-cluster/7004/redis-server /usr/local/redis-cluster/7004/redis.conf
  /usr/local/redis-cluster/7005/redis-server /usr/local/redis-cluster/7005/redis.conf  
  /usr/local/redis-cluster/7006/redis-server /usr/local/redis-cluster/7006/redis.conf

  # 查看是否启动成功

  ps -ef | grep redis

  

五、创建集群

  /usr/local/redis-5.0.0/src/redis-cli --cluster create 123.56.223.168:7001 123.56.223.168:7002 123.56.223.168:7003 123.56.223.168:7004 123.56.223.168:7005 123.56.223.168:7006 -a mima

 

注意事项:外网访问需要更换 cluster-config-file 对应文件的ip地址为外网;

     查看进程 ps -ef | grep redis

     关闭进程 kill -9 2034

     重复执行上面第四部,这样就可以外网访问

     JedisCluster 实例化后变成内网

 

posted @ 2018-11-24 15:42  骑车走西藏  阅读(2067)  评论(0编辑  收藏  举报