目标:使用3台服务器A、B、C,每台服务器部署一套主从(1主1从),三个主服务来平分redis槽
- 10.108.1.88(6379、6380)
- 10.108.1.89(6379、6380)
- 10.108.1.90(6379、6380)
安装Redis
建议下到
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
tar -zxvf redis-5.0.5.tar.gz
cp -r redis-5.0.5 /usr/local/redis
cd /usr/local/redis/redis-5.0.5/
编译并安装
sudo make
sudo make install
集群配置
- 使用utils路径下的 install_server.sh安装3个端口配置文件,下面以6379为例
[root@node01 utils]# pwd
/usr/local/redis/redis-5.0.5/utils
[root@node01 utils]# sudo sh install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/opt/redis/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /opt/redis/bin/redis-server
Cli Executable : /opt/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
- 自行安装2个端口(6379、6380)以后分别修改配置文件
#打开集群模式
cluster-enabled yes
#集群配置文件
cluster-config-file nodes_6379.conf
#集群节点超时时间
cluster-node-timeout 5000
#允许其他服务器连接
protected-mode no
#本机IP地址
bind 10.108.1.88
#打开aof持久化模式
appendonly yes
- 主从(6379、6380)配置都修改完以后,以同样的方式再添加10.108.1.89,10.108.1.90两台配置作为集群备用
开始部署集群
- 分别在10.108.1.88、10.108.1.89、10.108.1.90 上执行启动redis的命令
sudo redis-server /etc/redis/6379.con
sudo redis-server /etc/redis/6380.con
-
使用redic-cli部署集群
redis-cli --cluster create 10.108.1.88:6379 10.108.1.88:6380 10.108.1.89:6379 10.108.1.89:6380 10.108.1.90:6379 10.108.1.90:6380 --cluster-replicas 1