redis安装包下载地址:
https://download.redis.io/releases/
tar xzvf redis-6.2.10.tar.gz -C /usr/local/
cd /usr/local/
mv redis-6.2.10/ redis
cd /usr/local/redis/
make #编译
mkdir /usr/local/redis/data #创建存放数据的目录
mkdir /usr/local/redis/data/{redis6380,redis6381}
#同级目录下有修改好的文件,直接上传即可(注意redis版本)
cp /usr/local/redis/redis.conf /usr/local/redis/data/redis6380
cd /usr/local/redis/data/redis6380
vim redis.conf(:/ 搜出来进行修改)
bind 192.168.116.172 ---->0.0.0.0
port 6379 ---->6380
daemonize no ---->yes
pidfile /var/run/redis_6379.pid ---->6380
logfile "" ---->logfile /var/log/redis_6380.log
dir /data/redis/data ---->/usr/local/redis/data
appendonly no ---->yes
cluster-enabled yes ---->解开注释,去掉空格
cluster-config-file nodes-6379.conf---->6380
cluster-node-timeout 5000 ---->解开注释,去掉前面空格
cluster-replica-validity-factor 10 ---->解开注释,去掉前面空格
cluster-migration-barrier 1 ---->解开注释,去掉前面空格
cluster-require-full-coverage yes ---->解开注释,去掉前面空格
cp redis.conf /usr/local/redis/data/redis6381
scp redis.conf 172.22.1.3:/usr/local/redis/data/redis6380/
scp redis.conf 172.22.1.3:/usr/local/redis/data/redis6381/
scp redis.conf 172.22.1.4:/usr/local/redis/data/redis6380/
scp redis.conf 172.22.1.4:/usr/local/redis/data/redis6381/
#每台机器修改配置文件
:%s/6380/6381/g #根据端口进行修改
systemctl stop firewalld
cd /usr/local/redis/src #三台机器上都需要操作
nohup ./redis-server ../data/redis6380/redis.conf & #根据端口进行修改
nohup ./redis-server ../data/redis6381/redis.conf & #根据端口进行修改
netstat -nltp |grep redis #查看redis的6380和6381端口
去任意一台redis上操作
cd /usr/local/redis/src
./redis-cli --cluster create --cluster-replicas 1 172.22.1.2:6380 172.22.1.2:6381 172.22.1.3:6380 172.22.1.3:6381 172.22.1.4:6380 172.22.1.4:6381
./redis-cli -h 172.22.1.2 -c -p 6380
6380> ping
PONG
6380> cluster info #查看集群信息
6380> cluster nodes #查看集群实例
这里masterauth和requirepass都需要设置,最好设置一样,否则会有验证失败等问题
每个redis实例上都操作
6380>config set masterauth oj+xjlARRfJqbC
6380>config set requirepass oj+xjlARRfJqbC
6380>auth oj+xjlARRfJqbC
6380>config rewrite
#每台机器上操作
ps -ef | grep redis
kill #杀死原有的redis进程
#重新启动redis
cd /usr/local/redis/src #三台机器上都需要操作
nohup ./redis-server ../data/redis6380/redis.conf & #根据端口进行修改
nohup ./redis-server ../data/redis6381/redis.conf & #根据端口进行修改
#再次连接redis
./redis-cli -h 172.22.1.2 -c -p 6380
6380> auth oj+xjlARRfJqbC
6380> cluster info