参考文档
https://www.cnblogs.com/hmwh/p/10289138.html
https://www.cnblogs.com/zgqbky/p/11792141.html
以下操作均需在每台服务器上执行
- 安装依赖关系
yum install make zlib openssl* ImageMagick-devel gcc* rubygems -y
2、创建节点目录
mkdir -p /opt/app/redis-cluster/redis7376
mkdir -p /opt/app/redis-cluster/redis8376
mkdir -p /opt/app/redis-cluster/redis9376
3、下载redis5.0.10版本并解压
cd /opt/app/redis-cluster
wget http://download.redis.io/releases/redis-5.0.10.tar.gz
tar -zxvf redis-5.0.10.tar.gz
4、安装redis
cd redis-5.0.10
make #编译
make install PREFIX=/opt/app/redis #编译安装并将redis放在/opt/app/redis下,这样就可以直接使用redis
5、配置集群文件
将配置文件复制到安装目录
cp redis.conf /opt/app/redis-cluster/redis7376/redis-7376.conf
cp redis.conf /opt/app/redis-cluster/redis8376/redis-8376.conf
cp redis.conf /opt/app/redis-cluster/redis9376/redis-9376.conf
将配置安装文件复制到集群节点
cp /opt/app/redis/bin/* /opt/app/redis-cluster/redis7376/
cp /opt/app/redis/bin/* /opt/app/redis-cluster/redis8376/
cp /opt/app/redis/bin/* /opt/app/redis-cluster/redis9376/
内核调优
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo "vm.overcommit_memory = 1" >> /opt/app/sysctl.conf
6、编辑配置文件
vim /opt/app/redis-cluster/redis7376/redis-7376.conf
port 7376 #端口
cluster-enabled yes #启用集群模式
cluster-node-timeout 5000 #超时时间
protected-mode no #关闭网络安全模式
appendonly yes #开启持久化模式
daemonize yes #后台运行
bind 10.10.133.47 #127.0.0.0配置为本机IP
cluster-config-file nodes-7376.conf #nodes配置为节点名称
pidfile /var/run/redis_7376.pid #防止启动多个进程副本,只启动7376
更改完成后复制redis-7376.conf至redis-8376和redis-9376目录,并修改端口、pid和nodes文件名称
cp /opt/app/redis-cluster/redis7376/redis-7376.conf /opt/app/redis-cluster/redis8376/redis-8376.conf
cp /opt/app/redis-cluster/redis7376/redis-7376.conf /opt/app/redis-cluster/redis7376/redis-9376.conf
vim /opt/app/redis-cluster/redis8376/redis-8376.conf
vim /opt/app/redis-cluster/redis8376/redis-9376.conf
7、启动redis
cd /opt/app/redis-cluster/redis7376/
./redis-server redis-7376.conf
cd /opt/app/redis-cluster/redis8376/
./redis-server redis-8376.conf
cd /opt/app/redis-cluster/redis9376/
./redis-server redis-9376.conf
7、启动集群(在master上)
因为我们使用的5.0.0以上的版本的Redis搭建的集群只需要把编译后的redis目录中的这个redis-cli文件拷贝到redis-cluster目录过来就可以了
至于redis-cli在/opt/app/redis-cluster/redis-5.0.10/src下就可以找到,然后复制到/opt/app/redis-cluster下就可以了
cp -r /opt/app/redis-cluster/redis-5.0.10/src/redis-cli /opt/app/redis-cluster
集群启动命令
/opt/app/redis-cluster/redis-cli --cluster create 10.10.133.47:7376 10.10.133.47:8376 10.10.133.47:9376 10.10.133.48:7376 10.10.133.48:8376 10.10.133.48:9376 --cluster-replicas 1
提示如下则成功:
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
设置密码(在主备每个节点执行):
config set masterauth umpay2010
config set requirepass umpay2010
AUTH umpay2010
config rewrite
8、如果出现集群一直join状态或第二次启动集群时报错,在每个节点执行以下命令然后再重试
cd /opt/app/redis-cluster/redis7376/
删除启动文件
rm -rf rm -rf appendonly.aof nodes-6379.conf
初始化redis(注意IP和端口)
./redis-cli -h 10.10.133.48 -p 7376
10.10.133.48:7376> flushall
OK
10.10.133.48:7376> cluster reset
OK
10.10.133.48:7376> exit
停止redis
ps -ef |grep redis
kill -9 pid
启动redis
./redis-server redis-7376.conf
start.sh单节点脚本
DIR=/opt/app/redis-cluster
cd $DIR/redis7376
./redis-server redis-7376.conf
cd $DIR/redis8376
./redis-server redis-8376.conf
cd $DIR/redis9376
./redis-server redis-9376.conf
ps -ef |grep redis|grep -v grep
shoutdown.sh 停止集群脚本
/opt/app/redis-cluster/redis-cli -c -h
10.10.133.47 -p 7376 shutdown
/opt/app/redis-cluster/redis-cli -c -h 10.10.133.47 -p 7376 shutdown
/opt/app/redis-cluster/redis-cli -c -h 10.10.133.47 -p 8376 shutdown
/opt/app/redis-cluster/redis-cli -c -h 10.10.133.47 -p 9376 shutdown
/opt/app/redis-cluster/redis-cli -c -h 10.10.133.48 -p 7376 shutdown
/opt/app/redis-cluster/redis-cli -c -h 10.10.133.48 -p 8376 shutdown
/opt/app/redis-cluster/redis-cli -c -h 10.10.133.48 -p 9376 shutdown
./redis
标签:opt,10,app,redis,7376,cluster,Redis5.0,conf,集群 From: https://www.cnblogs.com/xiaobaijin/p/18503805