CentOS7单节点部署redis-cluster
准备一台机器,系统版本为CentOS7。(注意本文描述的是redis-cluster,不是主从复制)
1、下载软件包
# wget http://download.redis.io/releases/redis-3.2.8.tar.gz
2、解压
# tar xvf redis-3.2.8.tar.gz -C /usr/local/
# cd /usr/local/
# ln -sv redis-3.2.8/ redis
3、编译
# yum groupinstall -y "Development Tools"
# cd redis
# make
4、为多实例redis配置启动环境
# mkdir -pv /home/redis-cluster/{9000,9001,9002}
# cp src/{redis-server,redis-sentinel} /home/redis-cluster/9000/
# cp src/{redis-server,redis-sentinel} /home/redis-cluster/9001/
# cp src/{redis-server,redis-sentinel} /home/redis-cluster/9002/
# cp redis.conf sentinel.conf /home/redis-cluster/9000/
# cp redis.conf sentinel.conf /home/redis-cluster/9001/
# cp redis.conf sentinel.conf /home/redis-cluster/9002/
5、修改配置文件
# vim /home/redis-cluster/9000/redis.conf
bind 192.168.135.170
port 9000
daemonize yes
appendonly yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
# \cp /home/redis-cluster/9000/redis.conf /home/redis-cluster/9001/redis.conf
# \cp /home/redis-cluster/9000/redis.conf /home/redis-cluster/9002/redis.conf
# vim /home/redis-cluster/9001/redis.conf
port 9001
# vim /home/redis-cluster/9002/redis.conf
port 9002
6、启动三个redis实例
# cd /home/redis-cluster/9000/
# ./redis-server redis.conf
# cd ../9001/
# ./redis-server redis.conf
# cd ../9002/
# ./redis-server redis.conf
# ps -ef | grep redis
root 15583 1 0 00:32 ? 00:00:00 ./redis-server 192.168.135.170:9000 [cluster]
root 15592 1 0 00:33 ? 00:00:00 ./redis-server 192.168.135.170:9001 [cluster]
root 15597 1 0 00:33 ? 00:00:00 ./redis-server 192.168.135.170:9002 [cluster]
7、安装ruby环境
# yum install -y ruby
# gem install redis
8、启动redis集群
# cp /usr/local/redis/src/redis-trib.rb /bin/
# redis-trib.rb create 192.168.135.170:9000 192.168.135.170:9001 192.168.135.170:9002
9、查看集群状态
# /usr/local/redis/src/redis-cli -c -h 192.168.135.170 -p 9000
9000> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:3
cluster_size:3
cluster_current_epoch:3
cluster_my_epoch:1
cluster_stats_messages_sent:364
cluster_stats_messages_received:364