/**
*
* centos7和redis-3.2.9
*
*/
##################redis集群搭建###################
#依赖环境
yum -y install ruby
yum -y install rubygems
gem install redis #安装ruby和redis的接口程序
#压缩
tar -zxvf redis-3.2.9.tar.gz
cd /opt/redis-3.2.9
#编译
make
make install
#新建目标
mkdir cluster
cd /opt/redis-3.2.9/cluster
mkdir -p 7000 7001 7002
#/opt/redis-3.2.9拷贝redis.conf放在7000/7001/7002目录下
#修改如下配置项
port 7000
daemonize yes #后台运行,守护进程
cluster-enabled yes #开启集群模式
cluster-config-file nodes-7000.conf #集群配置文件(不要一致)
cluster-node-timeout 5000 #作为集群fail的依据,5秒没有回应
appendonly yes #每一次写操作请求都追加到appendonly.aof 文件中,防止数据大量丢失
bind 192.168.61.136 #本机IP
#启动redis
cd /opt/redis-3.2.9/src
./redis-server ./../cluster/7000/redis.conf
./redis-server ./../cluster/7001/redis.conf
./redis-server ./../cluster/7002/redis.conf
ps -ef|grep redis #查看redis的启动情况
#############以上多台机器执行###########
#集群(执行一次)
./redis-trib.rb create --replicas 1 192.168.61.142:7000 192.168.61.142:7001 192.168.61.142:7002 192.168.61.136:7000 192.168.61.136:7001 192.168.61.136:7002
cd /opt/redis-3.2.9/src
./redis-cli -c -h 192.168.61.142 -p 7000
>cluster info #查看集群状态信息
cd /opt/redis-3.2.9/src
#使用redis-cli客户端验证
> set hello 'hello'
> get hello
cd /opt/redis-3.2.9/src
--help
./redis-cli -c -p 7000 #客户端验证