CentOS6.5搭建redis集群

CentOS6.5非yum方式搭建redis集群步骤

一、ruby的安装

  1. 官网下载,这里选择的是ruby-2.2.10.tar.gz
    https://www.ruby-lang.org/en/downloads/
  2. 将tar 包上传至/usr/local/ruby目录
    这里通过xftp工具上传,上传时报错,文件夹权限问题,修改ruby文件夹权限
    chmod 777 ruby/
    tar包上传成功后恢复原权限
    chmod 755 ruby/
  3. 安装编译
    tar -zxvf ruby-2.2.10.tar.gz
    cd ruby-2.2.10
    ./configure
    make && make install

二、rubygems的安装

RubyGems简称gems,是一个用于对 Ruby组件进行打包的 Ruby 打包系统。

  1. 官网下载rubygems-3.0.3.tgz
    https://rubygems.org/pages/download
  2. 解压安装
    tar -zxvf rubygems-3.0.3.tgz
    cd rubygems-3.0.3
    ruby setup.rb

报错:
cannot load such file – zlib (LoadError)

表明缺少 zlib 包,需要下载并安装 zlib 包,建立目录,下载安装包:
wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
指定安装目录:
./configure --prefix=/usr/local/zlib/install/
编译安装:
make
make install

再到ruby目录下安装一下,不然同样报错
cd /usr/local/ruby/ruby-2.2.10/ext/zlib/
ruby extconf.rb --with-zlib-include=/usr/local/zlib/install/include/ --with-zlib-lib=/usr/local/zlib/install/lib/
make
make install

安装rubygems
cd /usr/local/rubygems/rubygems-3.0.3
ruby setup.rb

rubygems安装完成

三、redis集群的搭建

  1. 下载redis4.0.6的tar包
    命令: wget http://download.redis.io/releases/redis-4.0.6.tar.gz

  2. tar包解压缩
    命令: tar -zxvf redis-4.0.6.tar.gz

  3. 编译并安装
    cd redis-4.0.6
    make && make install

  4. 编写配置文件并启动各个节点
    cd redis-4.0.6
    mkdir redis-cluster
    cd redis-cluster
    mkdir 7001 7002 7003 7004 7005 7006
    mkdir data logs
    cd data
    mkdir 7001 7002 7003 7004 7005 7006
    cd …/7001
    vim redis_7001.conf
    加入以下内容:

    port 7001
    cluster-enabled yes
    cluster-config-file nodes_7001.conf
    cluster-node-timeout 15000
    daemonize yes
    pidfile /var/run/redis_7001.pid
    dir /usr/local/redis/redis-4.0.6/redis-cluster/data/7001
    logfile /usr/local/redis/redis-4.0.6/redis-cluster/logs/7001.log
    bind 192.168.154.128
    appendonly yes

    启动7001节点的redis服务:
    ./src/redis-server ./redis-cluster/7001/redis_7001.conf
    其他节点启动步骤类似,将配置文件复制一份然后修改即可

  5. 创建redis集群
    执行命令:
    ./src/redis-trib.rb create --replicas 1 192.168.154.128:7001 192.168.154.128:7002 192.168.154.128:7003 192.168.154.128:7004 192.168.154.128:7005 192.168.154.128:7006
    报错:

/usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require': cannot load such file -- redis (LoadError) from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire’
from ./src/redis-trib.rb:25:in

需要安装redis-gem,下载redis-4.0.3.gem:
https://rubygems.org/gems/redis/versions/4.0.3
安装redis-gem:
gem install redis-4.0.3.gem
报错:

ERROR: While executing gem … (Gem::Exception)
Unable to require openssl, install OpenSSL and rebuild Ruby (preferred) or use non-HTTPS sources

需要安装openssl:
wget https://www.openssl.org/source/openssl-1.0.2h.tar.gz
tar -zxvf openssl-1.0.2h.tar.gz
cd openssl-1.0.2h
./config -fPIC --prefix=/usr/local/openssl enable-shared
./config -t
make && make install

编译ruby中的openssl:
cd /usr/local/ruby/ruby-2.2.10/ext/openssl/
ruby extconf.rb --with-openssl-include=/usr/local/openssl/include/ --with-openssl-lib=/usr/local/openssl/lib/
make
报错:make: *** No rule to make target /include/ruby.h', needed byossl_rand.o’. Stop.
修改Makefile,增加变量 :
vim Makefile,加入下面一行
top_srcdir = …/…
保存后
make
make install
openssl 安装成功
重新安装redis-4.0.3.gem
gem install redis-4.0.3.gem
安装成功

重新创建集群
./src/redis-trib.rb create --replicas 1 192.168.154.128:7001 192.168.154.128:7002 192.168.154.128:7003 192.168.154.128:7004 192.168.154.128:7005 192.168.154.128:7006
创建成功后验证
./src/redis-cli -c -h 192.168.154.128 -p 7005
连接后
set name zhanga
get name
redis 集群搭建成功!!!

你可能感兴趣的:(redis搭建记录)