注意:文中10.211.55.26 这个ip地址需要改为自己服务器ip地址,这个也是redis客户端连接redis服务端时候使用的ip地址。
master:负责读写
slave:master正常运行则不能读取到数据,master挂了之后,角色更改为master
直接开始搭建
mkdir -p /usr/local/src/redis
cd /usr/local/src/redis
wget http://download.redis.io/releases/redis-stable.tar.gz #下载redis
tar xvzf redis-stable.tar.gz
cd redis-stable
make
make install
mkdir -p /etc/redis/7001
mkdir -p /etc/redis/7002
mkdir -p /etc/redis/7003
mkdir -p /etc/redis/7004
mkdir -p /etc/redis/7005
mkdir -p /etc/redis/7006
mkdir -p /var/redis/7001
mkdir -p /var/redis/7002
mkdir -p /var/redis/7003
mkdir -p /var/redis/7004
mkdir -p /var/redis/7005
mkdir -p /var/redis/7006
vim /etc/redis/7001/7001.conf
port 7001
bind 10.211.55.26
dir /var/redis/7001
cluster-enabled yes
cluster-config-file nodes-7001.conf
cluster-node-timeout 5000
appendonly yes
daemonize yes
protected-mode no
pidfile /var/run/redis_7001.pid
vim /etc/redis/7002/7002.conf
port 7002
bind 10.211.55.26
dir /var/redis/7002
cluster-enabled yes
cluster-config-file nodes-7002.conf
cluster-node-timeout 5000
appendonly yes
daemonize yes
protected-mode no
pidfile /var/run/redis_7002.pid
vim /etc/redis/7003/7003.conf
port 7003
bind 10.211.55.26
dir /var/redis/7003
cluster-enabled yes
cluster-config-file nodes-7003.conf
cluster-node-timeout 5000
appendonly yes
daemonize yes
protected-mode no
pidfile /var/run/redis_7003.pid
vim /etc/redis/7004/7004.conf
port 7004
bind 10.211.55.26
dir /var/redis/7004
cluster-enabled yes
cluster-config-file nodes-7004.conf
cluster-node-timeout 5000
appendonly yes
daemonize yes
protected-mode no
pidfile /var/run/redis_7004.pid
vim /etc/redis/7005/7005.conf
port 7005
bind 10.211.55.26
dir /var/redis/7005
cluster-enabled yes
cluster-config-file nodes-7005.conf
cluster-node-timeout 5000
appendonly yes
daemonize yes
protected-mode no
pidfile /var/run/redis_7005.pid
vim /etc/redis/7006/7006.conf
port 7006
bind 10.211.55.26
dir /var/redis/7006
cluster-enabled yes
cluster-config-file nodes-7006.conf
cluster-node-timeout 5000
appendonly yes
daemonize yes
protected-mode no
pidfile /var/run/redis_7006.pid
/usr/local/bin/redis-server /etc/redis/7001/7001.conf
/usr/local/bin/redis-server /etc/redis/7002/7002.conf
/usr/local/bin/redis-server /etc/redis/7003/7003.conf
/usr/local/bin/redis-server /etc/redis/7004/7004.conf
/usr/local/bin/redis-server /etc/redis/7005/7005.conf
/usr/local/bin/redis-server /etc/redis/7006/7006.conf
检测进程
ps -ef|grep redis
/sbin/iptables -I INPUT -p tcp --dport 7001 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 7002 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 7003 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 7004 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 7005 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 7006 -j ACCEPT
/usr/local/bin/redis-cli --cluster create 10.211.55.26:7001 10.211.55.26:7002 10.211.55.26:7003 10.211.55.26:7004 10.211.55.26:7005 10.211.55.26:7006 --cluster-replicas 1
vim /usr/local/src/redis/redis-stable/utils/create-cluster/create-cluster
ports=7000
nodes=6
cp /usr/local/src/redis/redis-stable/utils/create-cluster/create-cluster /usr/local/bin/utils/
vim /usr/local/bin/utils/create-cluster
更改
ports=7000
nodes=6
stop命令中加入 -h 10.211.55.26
/usr/local/bin/utils/create-cluster stop
/usr/local/bin/utils/create-cluster start