新建redis集群

redis版本

5.0.5

主备规划

三主三从

安装路径

/opt/redis-5.0.5

操作步骤

  1. 安装依赖

    # 需要外网
    yum  install -y gcc
    
  2. 复制安装包到 /opt/data_collection

    # 使用rz命令将安装包上传
    rz
    
  3. 解压安装包到/opt目录

    tar -zxvf redis-5.0.5.tar.gz -C /opt
    
  4. 编译

    cd /opt/redis-5.0.5
    make PREFIX=/opt/redis-5.0.5 install
    
  5. 复制配置文件到 /opt/redis-5.0.5

    cp redis.conf redis-6379.conf
    
  6. 修改生成配置文件

    vi redis-6379.conf
    # 文件内容如下
        #bind 127.0.0.1
        port 6379
        dir /data01/redis/6379
        pidfile /var/run/redis_6379.pid
        daemonize yes
        cluster-enabled yes
        cluster-config-file nodes-6379.conf
        cluster-node-timeout 15000
        appendonly yes
        appendfilename "appendonly.aof"
        protected-mode no
        maxclients 100000
        timeout 3600
    
    # 复制生成 6380配置文件
    
    cp redis-6379.conf redis-6380.conf
    
    # 把上述6379改成6380
    %s/6379/6380/g
    
  7. 复制到其他集群机器

    scp redis-6379.conf redis-6380.conf root@datanode01:/opt/redis-5.0.5
    scp redis-6379.conf redis-6380.conf root@datanode02:/opt/redis-5.0.5
    
    # 每台机器都执行
    mkdir -p /data01/redis/6379
    mkdir -p /data01/redis/6380
    
  8. 启动redis

    cd /opt/redis-5.0.5
    ./bin/redis-server redis-6379.conf 
    ./bin/redis-server redis-6380.conf 
    
  9. 设置集群模式

    ./bin/redis-cli --cluster create 172.168.63.1:6379 172.168.63.1:6380 172.168.63.2:6379 172.168.63.2:6380 172.168.63.3:6379 172.168.63.3:6380 --cluster-replicas 1
    
  10. 连接检查

    ./bin/redis-cli -c -h 172.168.63.1  -p 6379 cluster info
    
  11. 关闭redis

    ./bin/redis-cli -h localhost -p 6379 shutdown
    ./bin/redis-cli -h localhost -p 6380 shutdown
    

posted on 2022-11-29 18:40  枫夜求索阁  阅读(11)  评论(0)    收藏  举报

导航