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

    CentOS7 从零开始部署Redis 集群_第1张图片

  5. 测试

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

    CentOS7 从零开始部署Redis 集群_第2张图片


引用:

你可能感兴趣的:(CentOS,Redis)