一.规划篇
1.机器规划
Matser Slave
192.168.1.31:7000 192.168.1.31:7001
192.168.1.32:7000 192.168.1.32:7001
192.168.1.33:7000 192.168.1.33:7001
192.168.1.34:7000 192.168.1.34:7001
2.程序规划
配置文件:
Matser: /usr/local/etc/redis-cluster/redis-7000
Slave: /usr/local/etc/redis-cluster/redis-7001
执行程序:
/usr/local/bin
源码路径:
/opt/redis-3.0.7
二.安装篇
1.编译redis
#将redis解压到/opt下tar zxvf redis-3.0.7.tar.gz -C /opt#进入redis目录,并编译cd /opt/redis-3.0.7 && make MALLOC=libc#安装redismake install
2.创建master & slave配置文件
#创建目录mkdir /usr/local/etc/redis-cluster/redis-7000 /usr/local/etc/redis-cluster/redis-7001#创建配置文件cp /opt/redis-3.0.7/redis.conf mkdir /usr/local/etc/redis-cluster/redis-7000/#修改配置文件vim /opt/redis-3.0.7/redis.conf mkdir /usr/local/etc/redis-cluster/redis-7000/redis.conf修改如下配置:port 7000daemonize yescluster-enabled yescluster-config-file nodes.confcluster-node-timeout 5000appendonly yes从节点和其他机器依次修改,只是端口号需要根据实际更改;
3.启动redis
#每个节点都需要启动/usr/local/bin/redis-server /opt/redis/cluster/redis-7000.conf #检查redis状态ps -aux|grep redis
4.配置gem环境
#安装gem需要1.8.7版本以上,如果不是需要升级,这里不演示升级;yum install ruby ruby-devel rubygems rpm-build#安装redis ruby接口gem install redis#构建集群配置redis-trib.rb create --replicas 1 192.168.1.31:7000 192.168.1.32:7001 192.168.1.32:7000 192.168.1.33:7001 192.168.1.33:7000 192.168.1.34:7001 192.168.1.34:7000 192.168.1.31:7001#redis-trib.rb create 创建集群# 1 一个master节点对应的slave节点数量
5.登入redis集群某节点
redis-cli -c -p 7000
6.检查集群
redis-trib.rb check 192.168.1.31:7000#如果没有任何警告或错误,表示集群启动成功并注意OK状态
时间: 2024-10-14 06:39:50