CentOS7 从零开始部署Redis 集群

序言

  1. 下载 reids 程序包: redis-3.2.3.tar.gz
  2. 下载 ruby 程序包 : ruby-2.3.1.tar.gz
  3. 准备三台CentOS机器:192.168.169.130, 192.168.169.139, 192.168.169.140
  4. 将代码包拷贝至 /usr/local 文件夹

安装部署

  1. 准备临时变量方便部署

    node1='192.168.169.130'
    node2='192.168.169.139'
    node3='192.168.169.140'
    currIp='192.168.169.130'
    redisDir='/home/redis/redis3.2'
  2. 添加用户和用户组

    groupadd redis
    useradd -d /home/redis -g redis redis
  3. 关闭防火墙

    systemctl stop firewalld.service
    systemctl disable firewalld.service
  4. 安装必要软件包

    yum -y install openssl* openssl-devel zlib-devel gcc gcc-c++ make autoconf readline-devel curl-devel expat-devel gettext-devel
    
  5. 安装编译 Redis

    cd /usr/local
    tar -zxvf redis-3.2.3.tar.gz 
    
    mv /usr/local/redis-3.2.3 $redisDir
    cd $redisDir
    make && make install
    chown -R redis:redis $redisDir 
  6. 配置Reids

    mkdir -P $redisDir/log
    cp $redisDir/redis.conf $redisDir/redis.conf.bak#备份文件
    
    echo  "cluster-enabled yes" >>  $redisDir/redis.conf
    echo  "cluster-node-timeout 5000" >>  $redisDir/redis.conf
    sed  -i "s/^appendonly no$/appendonly yes/"   $redisDir/redis.conf 
    sed  -i "s/^daemonize no$/daemonize yes/"   $redisDir/redis.conf 
    echo cluster-config-file node-6379.conf >> $redisDir/redis.conf 
    sed  -i 's/^logfile[^aa]*$/#logfile ""/' $redisDir/redis.conf
    echo "logfile $redisDir/log/redis.log"  >> $redisDir/redis.conf 
    sed -i "s/^bind 127.0.0.1$/bind $currIp/"  $redisDir/redis.conf 
    sed -i "s/^protected-mode yes$/protected-mode no/" $redisDir/redis.conf 
    
  7. 启动实例

    $redisDir/src/redis-server $redisDir/redis.conf  &

配置集群

  1. 编译 Ruby

    mkdir /usr/local/ssl
    cd /usr/local/ssl
    yum -y install wget
    wget --no-check-certificate https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/41808/raw/ext/openssl/ossl_pkey_ec.c
    wget --no-check-certificate https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/41808/raw/test/openssl/test_pkey_ec.rb
    
    tar -zxvf  ruby-2.3.1.tar.gz 
    cd /usr/local/ruby-2.3.1
    ./configure --enable-shared --enable-pthread --with-openssl-dir=/usr/local/ssl --prefix=/usr/local/ruby
    make && make install
    
  2. 配置 Ruby 环境

    echo 'export PATH=/usr/local/ruby/bin:$PATH' >> /etc/profile
    source /etc/profile
  3. 安装 Redis

    gem install redis
  4. 启动集群

    $redisDir/src/redis-trib.rb create  $node1:6379 $node2:6379 $node3:6379

    redis_cluster

  5. 测试

    $redisDir/src/redis-cli -c -h 192.168.169.130#注意 -c 开启集群模式

    testing


引用:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值