redis-4.0.8在centos的集群安装



一、集群机器
三台服务器:先设置hosts
192.168.2.11  node1
192.168.2.12  node2
192.168.2.13 node3
端口分配:
node1:7000
node1:7001 
node2:7002 
node2:7003 
node3:7004 
node3:7005

1.下载redis-4.0.8
wget http://download.redis.io/releases/redis-4.0.8.tar.gz
make test
yum install tcl
make && make install PREFIX=/usr/local/redis   (确定安装目录)

mkdir -p /usr/local/redis/redis_cluster/ 7000
mkdir -p /usr/local/redis/redis_cluster/ 7001


node1服务器:
mkdir -p /usr/local/redis/redis_cluster/7000
mkdir -p /usr/local/redis/redis_cluster/7001

cp redis.conf /usr/local/redis/redis_cluster/7000
cp  redis.conf /usr/local/redis/redis_cluster/7001

node2服务器:
mkdir -p /usr/local/redis/redis_cluster/7002
mkdir -p /usr/local/redis/redis_cluster/7003

cp redis.conf /usr/local/redis/redis_cluster/7002
cp redis.conf /usr/local/redis/redis_cluster/7003

node3服务器:
mkdir -p /usr/local/redis/redis_cluster/7004
mkdir -p /usr/local/redis/redis_cluster/7005

cp redis.conf /usr/local/redis/redis_cluster/7004
cp redis.conf /usr/local/redis/redis_cluster/7005


192.168.2.11 node1
192.168.2.12 node2
192.168.2.13 node3


4:修改redis.conf
port  7000                                //端口根据对应的文件夹去配制端口 7000,7001,7002,7003,7004,7005     
bind 本机ip                               //根据本机所在的IP或hostname去配制 node1 node2 node3
daemonize    yes                          //redis后台运行
pidfile  /var/run/redis_7000.pid          //pidfile文件对应7000,7001,7002,7003,7004,7005
cluster-enabled  yes                      //开启集群  把注释#去掉
cluster-config-file  nodes_7000.conf      //集群的配置  配置文件首次启动自动生成 7000,7001,7002,7003,7004,7005
cluster-node-timeout  15000               //请求超时  默认15秒,可自行设置
appendonly  yes                           //aof日志开启  有需要就开启,它会每次写操作都记录一条日志

scp   /usr/local/redis/redis_cluster/7000/redis.conf  node2:/usr/local/redis/redis_cluster/7002
scp   /usr/local/redis/redis_cluster/7000/redis.conf  node2:/usr/local/redis/redis_cluster/7003

scp   /usr/local/redis/redis_cluster/7000/redis.conf  node3:/usr/local/redis/redis_cluster/7004
scp   /usr/local/redis/redis_cluster/7000/redis.conf  node3:/usr/local/redis/redis_cluster/7005

5.启动

/usr/local/redis/redis-cluster/7000/data/
/usr/local/redis/redis_cluster/7000/data

logfile /usr/local/redis/redis_cluster/7000/log



cd /usr/local/redis/redis_cluster/7000
/usr/local/redis/bin/redis-server /usr/local/redis/redis_cluster/7000/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis/redis_cluster/7001/redis.conf

/usr/local/redis/bin/redis-server /usr/local/redis/redis_cluster/7002/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis/redis_cluster/7003/redis.conf


/usr/local/redis/bin/redis-server /usr/local/redis/redis_cluster/7004/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis/redis_cluster/7005/redis.conf

6.启动集群

root@node1 soft]# gem install redis-4.0.0.gem
ERROR:  Loading command: install (LoadError)
cannot load such file -- zlib
ERROR:  While executing gem ... (NoMethodError)
    undefined method `invoke_with_build_args' for nil:NilClass

解决办法是:
  1. 进入ruby源码文件夹
  1. 安装ruby自身提供的zlib包
#cd ext/zlib
#ruby ./extconf.rb
#make
#make install

问题一:
问题:
/soft/redis-4.0.8/src/redis-trib.rb create --replicas 1 node1:7000 node1:7001 node2:7002  node2:7003  node3:7004 node3:7005
/usr/local/ruby/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- redis (LoadError)
from /usr/local/ruby/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /soft/redis-4.0.8/src/redis-trib.rb:25:in `

解决办法:
Ruby的redis接口没有安装,需要安装Redis接口,输入命令 " gem install redis " 进行安装,如下图:
http://blog.csdn.net/hello_world_qwp/article/details/78261618




今天yum install的时候出问题了,找了半天才找到一个可行的解决办法
fastestmirror 是yum的一个加速插件,这里是插件提示信息是插件不能用了。
不能用就先别用呗,禁用掉,先yum了再说。
1.修改插件的配置文件
# vi  /etc/yum/pluginconf.d/fastestmirror.conf  
enabled = 1//由1改为0,禁用该插件
...............................
2.修改yum的配置文件
# vi /etc/yum.conf
.........................
plugins=1//改为0,不使用插件
........................
清理 删除yum
yum clean
yum update


第一步:安装gcc 、zlib-devel 库
注:由于安装系统的时候没有装c编译器 导致很多源码安装的程序无法编译 所以需要在Linux上装c编译器,必须按顺序安装否则安装不会成功 。
yum -y install gcc gcc-c++ autoconf automake make
yum install zlib,zlib-devel
第二步、 离线安装perl5.
看看perl的版本: perl -v
首先下载最新的perl源码包:
wget http://www.cpan.org/src/5.0/perl-5.16.1.tar.gz
解压源码包
tar -xvf  perl-5.16.1.tar.gz
编译并安装,目录可以自定义
cd perl-5.16.1
 ./Configure -des -Dprefix=/usr/local/perl
make
make test
make install

第三步、我们又得安装OpenSSL才行,
官网地址: https://www.openssl.org/source/  上次压缩包到服务器,解压,
1 $ tar -xzvf openssl- 1.0 .2l.tar.gz
2 $ cd openssl- 1.0 .2l
3 $ ./config -fPIC --prefix=/usr/local/openssl enable- shared
4 $ ./config - t
5 $ make && make install
openssl version - a
打印版本信息表示成功,


出现问题,安装有问题,参考
https://www.cnblogs.com/xuliangxing/p/7146868.html
https://www.cnblogs.com/xuliangxing/p/7146868.html
https://www.cnblogs.com/hellxz/p/redis.html


第四步 离线安装高版本的ruby2.5
https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.0.tar.gz
wget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.0.tar.gz
tar -xvf ruby-2.5.0.tar.gz
$ ./configure --prefix=/usr/local/ruby -prefix是将ruby安装到指定目录,也可以自定义
2 $ make && make install
ln -s /usr/local/ruby/bin/ruby /usr/bin/ruby



cd /soft/ruby-2.5.0/ext/openssl       备注:/soft/ruby-2.5.0这个目录是ruby安装包后解压的目录,就是前面提到的ruby离线安装
$ruby extconf.rb  --with-openssl-include=/usr/local/openssl/include/ --with-openssl-lib=/usr/local/openssl/lib //会生成一个Makefile文件
问题:extconf.rb:94:in `
': OpenSSL library could not be found. You might want to use --with-openssl-dir= option to specify the prefix where OpenSSL is installed. (RuntimeError)
解决办法:修改Make文件的变量  top_srcdir=../.. ,openssl没安装成功的原因,
备注:开始下载的是openssl-fips-2.0.16.tar.gz,后面改成1.1.0g.tar.gz 。
在当前目录下要执行此命令
$ make && make install
注意:make: *** No rule to make target `/usr/include/ruby/backward.h', needed by `ossl_pkey_ec.o'.  Stop.(搞的很纠结,重新安装ruby)

$ gem install redis
Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
Unable to require openssl, install OpenSSL and rebuild Ruby (preferred) or use non-HTTPS sources
说明Ruby对应的openssl没安装成功
https://gems.ruby-china.org/




启动有错误:
ERR Invalid node address specified: node1:7000 (Redis::CommandError)
openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
这是由于openssl库的位置不正确造成的。
解决方法:
在root用户下执行:
ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1

先安装openssl ,然后在安装ruby, 在ruby的ext目录下进行再安装。

遇到问题了,处理方式参考,
https://blog.csdn.net/yelllowcong/article/details/78362370


/soft/redis-4.0.8/src/redis-trib.rb create --replicas 1 192.168.2.11:7000 192.168.2.11:7001 192.168.2.12:7002  192.168.2.12:7003  192.168.2.13:7004 192.168.2.13:7005


cat /etc/sysctl.conf
vi /etc/sysctl.conf
增加下面的内容
vm.overcommit_memory = 1
net.core.somaxconn = 2048

sysctl -p

vi /etc/rc.local
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
chmod +x /etc/rc.d/rc.local

redis.conf
port  7000                               
bind 192.168.2.11                            
daemonize    yes                         
pidfile  /var/run/redis_7000.pid       
cluster-enabled  yes                    
cluster-config-file  /usr/local/redis/redis_cluster/nodes_7000.conf     
cluster-node-timeout  15000              
dir /usr/local/redis/redis_cluster/7000/data
logfile /usr/local/redis/redis_cluster/7000/redis.log  
appendonly  yes

你可能感兴趣的:(redis-4.0.8集群,redis-4.0.8)