三台服务器:先设置hosts
10.0.0.231  node1
10.0.0.232  node2
10.0.0.233  node3
端口分配:
node1:7000 
node1:7001  
node2:7002  
node2:7003  
node3:7004  
node3:7005

1:下载redis-4.0.1并解压

解压目录:/usr/local/redis-4.0.1
建立软连接:ln -s redis-4.0.1 redis

2:编译安装

指定安装目录到:/usr/local/redis

make && make install PREFIX=/usr/local/redis

3:创建配制节点

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

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

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

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

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

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

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日志开启  有需要就开启,它会每次写操作都记录一条日志

5:复制src目录中的redis-trib.rb 到/usr/local/redis/bin目录

cp  /usr/local/redis/redis-trib.rb /usr/local/redis/bin

6:安装ruby环境

yum install -y ruby
yum install -y rubygems

7:安装ruby的包

gem install redis-4.0.0.rc1.gem

如果不成功需要去下载后安装
下载地址
https://rubygems.org/gems/redis/versions/4.0.0.rc1
https://rubygems.org/downloads/redis-4.0.0.rc1.gem

安装命令:gem install -l ./redis-4.0.0.rc1.gem

8:启动各个节点

node1服务器:
/usr/local/redis/bin/redis-server /usr/loca/redis/redis_cluster/7000/redis.conf
/usr/local/redis/bin/redis-server /usr/loca/redis/redis_cluster/7001/redis.conf

node2服务器:
/usr/local/redis/bin/redis-server /usr/loca/redis/redis_cluster/7002/redis.conf
/usr/local/redis/bin/redis-server /usr/loca/redis/redis_cluster/7003/redis.conf

node3服务器:
/usr/local/redis/bin/redis-server /usr/loca/redis/redis_cluster/7004/redis.conf
/usr/local/redis/bin/redis-server /usr/loca/redis/redis_cluster/7005/redis.conf

9:检查各节点是否启动

查看进程
ps -ef | grep redis

查看端口
netstat -tnlp | grep redis

 10:创建集群

进入node1的bin目录下,执行以下脚本
./redis-trib.rb  create  --replicas  1  node1:7000 node1:7001  node2:7002  node2:7003  node3:7004  node3:7005

11:验证集群

进入每台服务器的redis/src目录,记住参数  -c不可以少

redis-cli -h node1 -p 7000 -c

redis-cli -h node2 -p 7002 -c

redis-cli -h node3 -p 7004 -c

 

posted on 2017-07-28 10:47  网络终结者  阅读(6490)  评论(0编辑  收藏  举报