使用redis-cli搭建redis5.x集群

注意:文中10.211.55.26 这个ip地址需要改为自己服务器ip地址,这个也是redis客户端连接redis服务端时候使用的ip地址。
master:负责读写
slave:master正常运行则不能读取到数据,master挂了之后,角色更改为master
直接开始搭建

1,创建下载目录,下载安装
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
2,创建配置文件目录
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
3,创建数据保存目录
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
4,编写配置文件
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

7,启动redis
/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
8,防火墙端口打开
/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
9,创建集群
/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
10,使用脚本管理集群
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

你可能感兴趣的:(服务器)