安装:Linux系统安装Redis(2020最新最详细) - 净重21克 - 博客园 (cnblogs.com)
通过以上方法一般能够安装成功。
搭建集群:
(1)进入bin下修改redis.conf文件的port及其他配置。如下
port 7001
daemonize yes
cluster-enabled yes
cluster-config-file condes.conf
cluster-node-timeout 15000
appendonly yes
pidfile /var/run/redis_7001.pid
(2)修改完成之后,回到bin所在的目录下,修改bin的名称为redis01
可以使用命令
mv bin /usr/local/redis-6.x/redis01
(3) 复制5份该目录
cp -r redis01 /usr/local/redis-6.x/redis02
cp -r redis01 /usr/local/redis-6.x/redis03
cp -r redis01 /usr/local/redis-6.x/redis04
cp -r redis01 /usr/local/redis-6.x/redis05
cp -r redis01 /usr/local/redis-6.x/redis06
并且修改相应的redis.conf文件的端口和pidfile
例如:
port 7002
pidfile /var/run/redis_7002.pid
自行进行修改
(4)开启一下服务看是否能正常运行
可以写一个start-all.sh脚本一键开启,还有一个shutdown-all.sh脚本一键关闭
# start-all.sh
cd redis01
./redis-server conf/redis.conf
cd ..
cd redis02
./redis-server conf/redis.conf
cd ..
cd redis03
./redis-server conf/redis.conf
cd ..
cd redis04
./redis-server conf/redis.conf
cd ..
cd redis05
./redis-server conf/redis.conf
cd ..
cd redis06
./redis-server conf/redis.conf
cd ..
# ./start-all.sh 一键开启服务
#shutdown-all.sh
cd redis01
redis-cli -p 7001 shutdown
cd ..
cd redis02
redis-cli -p 7002 shutdown
cd ..
cd redis03
redis-cli -p 7003 shutdown
cd ..
cd redis04
redis-cli -p 7004 shutdown
cd ..
cd redis05
redis-cli -p 7005 shutdown
cd ..
cd redis06
redis-cli -p 7006 shutdown
cd ..
如果启动正常,可以通过ps -ef | grep redis 来查看服务的开启情况,如果开启成功,结果类似这样:
(5)搭建集群
先开启服务,然后搭建集群
./start-all.sh
redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluster-replicas 1
得到结果
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 127.0.0.1:7005 to 127.0.0.1:7001
Adding replica 127.0.0.1:7006 to 127.0.0.1:7002
Adding replica 127.0.0.1:7004 to 127.0.0.1:7003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: c06eb49b431d16767ef03bb4125de8c2f49b0818 127.0.0.1:7001
slots:[0-5460] (5461 slots) master
M: e3f44dd3dda6b7e454e37bd408ee4ebdd21dc310 127.0.0.1:7002
slots:[5461-10922] (5462 slots) master
M: 408bedc56b7c20553210f949221b68c4802f2d6c 127.0.0.1:7003
slots:[10923-16383] (5461 slots) master
S: e7c38d782029d3c0877581fa082e5f1fb935d549 127.0.0.1:7004
replicates e3f44dd3dda6b7e454e37bd408ee4ebdd21dc310
S: b0f804cd3db36ea93ca884aabf4c35260467a891 127.0.0.1:7005
replicates 408bedc56b7c20553210f949221b68c4802f2d6c
S: 354fd5ba6bfe3b9781a0c867e5f29a3fb87a6028 127.0.0.1:7006
replicates c06eb49b431d16767ef03bb4125de8c2f49b0818
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 127.0.0.1:7001)
M: c06eb49b431d16767ef03bb4125de8c2f49b0818 127.0.0.1:7001
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 354fd5ba6bfe3b9781a0c867e5f29a3fb87a6028 127.0.0.1:7006
slots: (0 slots) slave
replicates c06eb49b431d16767ef03bb4125de8c2f49b0818
S: e7c38d782029d3c0877581fa082e5f1fb935d549 127.0.0.1:7004
slots: (0 slots) slave
replicates e3f44dd3dda6b7e454e37bd408ee4ebdd21dc310
M: e3f44dd3dda6b7e454e37bd408ee4ebdd21dc310 127.0.0.1:7002
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
M: 408bedc56b7c20553210f949221b68c4802f2d6c 127.0.0.1:7003
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: b0f804cd3db36ea93ca884aabf4c35260467a891 127.0.0.1:7005
slots: (0 slots) slave
replicates 408bedc56b7c20553210f949221b68c4802f2d6c
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
其中redis 集群新增节点 可以参考这篇文章
redis集群搭建以及redis集群中添加新结点,重新分配哈希槽