虽然这里用的是4.0.8的包,但是你可以下个5以上的包,因为redis5以前的版本集群是依靠ruby脚本redis-trib.rb实现,需要安装ruby环境,而redis5以上可以使用redis-cli创建整个redis集群
[root@node1 ~]# tar xf redis-4.0.8.tar.gz
[root@node1 ~]# yum -y install gcc make
[root@node1 ~]# cd redis-4.0.8/
[root@node1 redis-4.0.8]# make
#官方默认redis放在前台,占用终端。这里修改配置,放在后台
[root@node1 redis-4.0.8]# vim +136 redis.conf
daemonize yes
[root@node1 redis-4.0.8]# src/redis-server redis.conf
[root@node1 redis-4.0.8]# ss -antup | grep redis
[root@node1 redis-4.0.8]# src/redis-cli
127.0.0.1:6379> set hello world
OK
127.0.0.1:6379> get hello
"world"
127.0.0.1:6379>exit
[root@node1 redis-4.0.8]# src/redis-cli shutdown
[root@node1 redis-4.0.8]# ss -antup | grep redis
[root@node1 ~]# mv redis-4.0.8 /opt/
[root@node1 ~]# cd /opt/
查看6381-6386端口,确保端口未被使用
[root@node1 redis-4.0.8]# ss -antup | grep 8381
[root@node1 opt]# mkdir -p cluster/{6381,6382,6383,6384,6385,6386}
[root@node1 opt]# cp redis-4.0.8/redis.conf cluster/6381
[root@node1 opt]# vim cluster/6381/redis.conf
69 bind 127.0.0.1 #单机搭建不修改,两台或以上时修改成主机IP
92 port 6381
136 daemonize yes
159 pidfile /opt/cluster/6381/redis_6381.pid
172 logfile "/opt/cluster/6381/redis6381.log"
264 dir /opt/cluster/6381 # 设置redis数据写入目录
#501 # requirepass 12345 #如果需要密码,可以打开
673 appendonly yes # aof日志开启 有需要就开启
677 appendfilename "appendonly.aof" # aof日志文件名
815 cluster-enabled yes
[root@node1 opt]# for i in {6382..6386}; do cp cluster/6381/redis.conf cluster/$i/; done
[root@node1 opt]# for i in {6382..6386}; do sed -i "s/6381/$i/g" cluster/$i/redis.conf
[root@node1 opt]# for i in {6381..6386}; do /opt/redis-4.0.8/src/redis-server /opt/cluster/$i/redis.conf ; done
[root@node1 opt]# ss -antup | grep redis
[root@node1 ~]# yum -y install rubygems ruby
[root@node1 ~]# gem install redis-3.2.1.gem #包需要再下载
[root@node1 opt]# redis-4.0.8/src/redis-trib.rb create --replicas 1 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385 127.0.0.1:6386
Can I set the above configuration? (type 'yes' to accept): yes
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
redis5以上可以使用redis-cli创建整个redis集群(),这里有密码 -a 123456
[root@node1 opt]# redis-4.0.8/src/redis-cli -a 123456 --cluster create --cluster-replicas 1 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385 127.0.0.1:6386
[root@node1 opt]# redis-4.0.8/redis-cli -h 127.0.0.1 -p 6381
[root@node1 ~]# ps -aux | grep redis