数据库
首页 > 数据库> > redis-cluster 集群编译按装到指定目

redis-cluster 集群编译按装到指定目

作者:互联网

 

 

1,下载源码 可以到http://download.redis.io/releases/ 查找指定版本
wget http://download.redis.io/releases/redis-5.0.0.tar.gz
tar xf redis-5.0.0.tar.gz
2,开始编译
cd redis-5.0.0
make

#make MALLOC=libc
3,确定需要安装得目录使用PREFIX参数,一定要大写
mkdir ~/redis ~/redis/conf -p
make PREFIX=~/redis install
cp redis.conf ~/redis/conf/

#yum -y install ruby
#yum -y install rubygems
#reids5版本以上版本不需要,redis-trib.rb create改为 redis-cli --cluster create
cp src/redis-trib.rb ~/redis/bin


4,创建群集目录
cd ~/redis/conf/
mkdir 7001 7002 7003 7004 7005 7006
5,修改配置文件
vim redis.conf

建议:
port 端口区别其它实例:分布式部署可以不区分
bind 192.168.xxx.xxx
cluster-enabled yes 打开注释
daemonized yes 修改为yes 启动直接放入后台
logfile XXX/redis/conf/7001/redis.log #日志路径
dir ./改为 dir XXX/redis/conf/7001/

#高版本有masteraut redis 主的密码,在建立集群添加密码后需要添加.

cp redis.conf ./7001/redis_7001.conf
cp redis.conf ./7002/redis_7002.conf
cp redis.conf ./7003/redis_7003.conf
cp redis.conf ./7004/redis_7004.conf
cp redis.conf ./7005/redis_7005.conf
cp redis.conf ./7006/redis_7006.conf

sed -i "s#7001#7002#g" ./7002/redis_7002.conf
sed -i "s#7001#7003#g" ./7003/redis_7003.conf
sed -i "s#7001#7004#g" ./7004/redis_7004.conf
sed -i "s#7001#7005#g" ./7005/redis_7005.conf
sed -i "s#7001#7006#g" ./7006/redis_7006.conf

 


6,启动实例
/home/redis/bin/redis-server /home/redis/7001/redis_7001.conf
/home/redis/bin/redis-server /home/redis/7002/redis_7002.conf
/home/redis/bin/redis-server /home/redis/7003/redis_7003.conf
/home/redis/bin/redis-server /home/redis/7004/redis_7004.conf
/home/redis/bin/redis-server /home/redis/7005/redis_7005.conf
/home/redis/bin/redis-server /home/redis/7006/redis_7006.conf


7,配置集群


#低版本 ./redis-trib.rb create --replicas 1 192.168.1.30:7001 192.168.1.30:7002 192.168.1.30:7003 192.168.1.30:7004 192.168.1.30:7005 192.168.1.30:7006
# ./redis-cli --cluster help #最好手动敲 ./redis-cli --cluster create 系统提示有时是中文符号
[cloudapp@localhost redis/bin]$ ./redis-cli --cluster create 192.168.1.30:7001 192.168.1.30:7002 192.168.1.30:7003 192.168.1.30:7004 192.168.1.30:7005 192.168.1.30:7006 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.1.30:7004 to 192.168.1.30:7001
Adding replica 192.168.1.30:7005 to 192.168.1.30:7002
Adding replica 192.168.1.30:7006 to 192.168.1.30:7003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 905f20d61ba2d426bdf3648150721413ce19ff08 192.168.1.30:7001
slots:[0-5460] (5461 slots) master
M: 310a3b6ae356783094ac285337821de89565614e 192.168.1.30:7002
slots:[5461-10922] (5462 slots) master
M: 99edcf48d3de3783cae5b6d8287ba9613bf0e7f2 192.168.1.30:7003
slots:[10923-16383] (5461 slots) master
S: c2afa6d27ed6fd773da08f2a5c4dea07152545ee 192.168.1.30:7004
replicates 310a3b6ae356783094ac285337821de89565614e
S: 990a5b50bb44fe07c100b37af73c0087c66756c6 192.168.1.30:7005
replicates 99edcf48d3de3783cae5b6d8287ba9613bf0e7f2
S: 1d7b4c5748c51b277aa2252fe2e904cbe7c2d980 192.168.1.30:7006
replicates 905f20d61ba2d426bdf3648150721413ce19ff08
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
....
>>> Performing Cluster Check (using node 192.168.1.30:7001)
M: 905f20d61ba2d426bdf3648150721413ce19ff08 192.168.1.30:7001
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: c2afa6d27ed6fd773da08f2a5c4dea07152545ee 192.168.1.30:7004
slots: (0 slots) slave
replicates 310a3b6ae356783094ac285337821de89565614e
S: 1d7b4c5748c51b277aa2252fe2e904cbe7c2d980 192.168.1.30:7006
slots: (0 slots) slave
replicates 905f20d61ba2d426bdf3648150721413ce19ff08
S: 990a5b50bb44fe07c100b37af73c0087c66756c6 192.168.1.30:7005
slots: (0 slots) slave
replicates 99edcf48d3de3783cae5b6d8287ba9613bf0e7f2
M: 99edcf48d3de3783cae5b6d8287ba9613bf0e7f2 192.168.1.30:7003
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
M: 310a3b6ae356783094ac285337821de89565614e 192.168.1.30:7002
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[cloudapp@localhost redis/bin]$

8,连接redis
-h 指定ip
-p 指定端口
-c 表示以集群方式连接redis
./redis-cli -h 192.168.1.30 -p 7001 -c

8,检查集群
查询集群结点信息;
cluster nodes

查询集群状态信:
cluster info

标签:7001,redis,192.168,cluster,conf,1.30,slots,按装
来源: https://www.cnblogs.com/ershinian/p/16493292.html