redis
安装步骤
创建redis用户
useradd redis
passwd redis
切换redis用户在该用户目录下建立redis_cluster
cd redis_cluster
wget http://download.redis.io/releases/redis-3.2.6.tar.gz
tar -zxf redis-3.2.6.tar.gz
cd redis-3.2.6
make
make的时候可能报错以下错误为未安装GCC环境
执行下yum install gcc -y
cd /home/redis/redis_cluster
分别在几台机器上 192.168.137.3 192.168.137.4 192.168.137.5 创建mkdir 7000 7001
在每个目录下创建redis.conf,并分别写入(注意port和cluster-config-file)
port 6179
bind 192.168.137.130 127.0.0.1
cluster-enabled yes
cluster-config-file /opt/app/redis_cluster/6179/nodes.conf
cluster-node-timeout 5000
appendonly yes
然后开始启动redis
cd /opt/redis_cluster
redis-3.2.6/src/redis-server 7000/redis.conf &
redis-3.2.6/src/redis-server 7001/redis.conf &
ps -ef | grep redis
cd /opt/redis_cluster/redis-3.2.6/src
./redis-trib.rb create --replicas 1 192.168.137.3:7000 192.168.137.3:7001 192.168.137.4:7000 192.168.137.4:7001 192.168.137.5:7000 192.168.137.5:7001
执行redis-trib.rb命令时,需要ruby环境,可能需要执行以下命令
yum install ruby
yum install rubygems
gem install redis --version 3.0.0
注意:gem install redis --version 3.0.0 失败的话,需要修改一下gem的源
gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/
然后在执行
./redis-trib.rb create --replicas 1 192.168.137.3:7000 192.168.137.3:7001 192.168.137.4:7000 192.168.137.4:7001 192.168.137.5:7000 192.168.137.5:7001
测试
测试集群可用状态,kill掉6179所在进程后,发现6279替代为主节点
重启6179后,6179只能做6279从节点
网友评论