Linux下redis的完整安装过程 https://mp.csdn.net/console/editor/html/106296400
Linux下安装phpredis完整步骤 https://mp.csdn.net/console/editor/html/106298390
搭建集群
mkdir -p /redis-cluster/800{1..6}
cp /etc/redis.conf /tmp/
vim /tmp/redis.conf
sed -i 's#daemonize no#daemonize yes#g' /tmp/redis.conf
sed -i 's#6379#8001#g' /tmp/redis.conf
sed -i '192c dir /redis-cluster/8001' /tmp/redis.conf
sed -i '637c cluster-enabled yes' /tmp/redis.conf
sed -i '645c cluster-config-file nodes-8001.conf' /tmp/redis.conf
sed -i '651c cluster-node-timeout 5000' /tmp/redis.conf
sed -i '69a bind 172.16.1.3' /tmp/redis.conf
sed -i 's#appendonly no#appendonly yes#g' /tmp/redis.conf
\cp /tmp/redis.conf /redis-cluster/8001/
\cp /tmp/redis.conf /redis-cluster/8002/
\cp /tmp/redis.conf /redis-cluster/8003/
\cp /tmp/redis.conf /redis-cluster/8004/
\cp /tmp/redis.conf /redis-cluster/8005/
\cp /tmp/redis.conf /redis-cluster/8006/
sed -i 's#8001#8002#g' /redis-cluster/8002/redis.conf
sed -i 's#8001#8003#g' /redis-cluster/8003/redis.conf
sed -i 's#8001#8004#g' /redis-cluster/8004/redis.conf
sed -i 's#8001#8005#g' /redis-cluster/8005/redis.conf
sed -i 's#8001#8006#g' /redis-cluster/8006/redis.conf
yum install ruby
yum install rubygems
gem install redis --version=3.0.7
redis-server /redis-cluster/8001/redis.conf
redis-server /redis-cluster/8002/redis.conf
redis-server /redis-cluster/8003/redis.conf
redis-server /redis-cluster/8004/redis.conf
redis-server /redis-cluster/8005/redis.conf
redis-server /redis-cluster/8006/redis.conf
#这里换成自己的redis-trib.rb路径
/home/oldboy/tools/redis-3.0.7/src/redis-trib.rb create --replicas 1 172.16.1.3:8001 172.16.1.3:8002 172.16.1.3:8003 172.16.1.3:8004 172.16.1.3:8005 172.16.1.3:8006
验证:
[root@redis3 ~]# redis-cli -c -h 172.16.1.3 -p 8001
172.16.1.3:8001> cluster info
172.16.1.3:8001> cluster nodes
172.16.1.3:8001> set name huang
172.16.1.3:8002> get name