@Redis集群环境搭建
搭建含三个节点的集群,每个节点有一主一备。
mkdir /home/redis/redis-cluster
cp -r /home/redis/redis /home/redis/redis-cluster/7000
daemonize yes
#
bind 127.0.0.1 (注释掉,否则本地无法访问虚拟机redis端口)
protected-mode no
port 7000
requirepass zx123456
masterauth zx123456
cluster-enabled yes
cluster-config-file /home/redis/redis-cluster/nodes/nodes-7000.conf
cluster-node-timeout 5000
pidfile /home/redis/redis-cluster/pid/redis_7000.pid
logfile /home/redis/redis-cluster/logs/redis_7000.log
dir /home/redis/redis-cluster/dbfile
dbfilename dump7000.rdb
批量修改端口
perl -p -i -e
"s/6379/7000/g"
/home/redis/redis-cluster/7000/redis.conf
mkdir /home/redis/redis-cluster/logs
mkdir /home/redis/redis-cluster/nodes
mkdir /home/redis/redis-cluster/pid
mkdir /home/redis/redis-cluster/dbfile
mkdir /home/redis/redis-cluster/backup
mkdir /home/redis/redis-cluster/backup/nodes
mkdir /home/redis/redis-cluster/backup/pid
mkdir /home/redis/redis-cluster/backup/dbfile
cp -r /home/redis/redis-cluster/7000 /home/redis/redis-cluster/7001
cp -r /home/redis/redis-cluster/7000 /home/redis/redis-cluster/7002
cp -r /home/redis/redis-cluster/7000 /home/redis/redis-cluster/7003
cp -r /home/redis/redis-cluster/7000 /home/redis/redis-cluster/7004
cp -r /home/redis/redis-cluster/7000 /home/redis/redis-cluster/7005
cp -r /home/redis/redis-cluster/7000 /home/redis/redis-cluster/7006
cp -r /home/redis/redis-cluster/7000 /home/redis/redis-cluster/7007
perl -p -i -e
"s/7000/7001/g"
/home/redis/redis-cluster/7001/redis.conf
perl -p -i -e"s/7000/7002/g"
/home/redis/redis-cluster/7002/redis.conf
perl -p -i -e"s/7000/7003/g"
/home/redis/redis-cluster/7003/redis.conf
perl -p -i -e"s/7000/7004/g"
/home/redis/redis-cluster/7004/redis.conf
perl -p -i -e"s/7000/7005/g"
/home/redis/redis-cluster/7005/redis.conf
perl -p -i -e"s/7000/7006/g"
/home/redis/redis-cluster/7006/redis.conf
perl -p -i -e"s/7000/7007/g"
/home/redis/redis-cluster/7007/redis.conf
在 “/home/redis/redis-cluster/” 目录下创建批量启动所有节点脚本
cd /home/redis/redis-cluster/
vi start-all.sh
内容如下:
cd /home/redis/redis-cluster/7000/bin
./redis-server ../redis.conf
cd /home/redis/redis-cluster/7001/bin
./redis-server ../redis.conf
cd /home/redis/redis-cluster/7002/bin
./redis-server ../redis.conf
cd /home/redis/redis-cluster/7003/bin
./redis-server ../redis.conf
cd /home/redis/redis-cluster/7004/bin
./redis-server ../redis.conf
cd /home/redis/redis-cluster/7005/bin
./redis-server ../redis.conf
sh start-all.sh
ps -ef | grep redis-server
mv /home/redis/redis-cluster/dbfile/dump7000.rdb /home/redis/redis-cluster/backup/dbfile
mv /home/redis/redis-cluster/dbfile/dump7001.rdb /home/redis/redis-cluster/backup/dbfile
mv /home/redis/redis-cluster/dbfile/dump7002.rdb /home/redis/redis-cluster/backup/dbfile
mv /home/redis/redis-cluster/dbfile/dump7003.rdb /home/redis/redis-cluster/backup/dbfile
mv /home/redis/redis-cluster/dbfile/dump7004.rdb /home/redis/redis-cluster/backup/dbfile
mv /home/redis/redis-cluster/dbfile/dump7005.rdb /home/redis/redis-cluster/backup/dbfile
/home/redis/redis-cluster/7000/bin/redis-cli --cluster create 172.16.1.12:7000 172.16.1.12:7001 172.16.1.12:7002 172.16.1.12:7003 172.16.1.12:7004 172.16.1.12:7005 -a zx123456 --cluster-replicas 1
-a + 集群密码(masterauth )
redis-cli -h 127.0.0.1 -p 7000 -c
auth zx123456
cluster info
cluster nodes
关闭集群
redis-cli -p 7000 -c -a zx123456 shutdown
关闭节点
redis-cli -p 7000 -a zx123456 shutdown
redis-cli
--
cluster add-node:
<已存在节点 ip>
:<已存在节点端口>
-a zx123456
ps:也可以登陆集群客户端,执行命令:
cluster meet 172.16.1.12 7006
redis-cli
--
cluster reshard<任意一个节点 ip>
:<任意一个节点 port>
-a zx123456
需要移动多少哈希槽,输入
1000
指定移动哪几个点的哈希槽
1、all:所有的主节点中随机转移,凑够1000个哈希槽,然后输入 yes
2、ID + done:指定主节点移动
redis-cli -p
-a zx123456 cluster replicate
redis-cli
--
cluster reshard<任意一个节点 ip>
:<任意一个节点 port>
-a zx123456
需要移动多少哈希槽,输入
1000
移动到哪个节点,输入节点的ID
从哪个节点移出,输入节点的ID
ID
done
yes
redis-cli -a zx123456
--
cluster del-node<待删除节点 ip>
:<待删除节点 port>
<待删除节点 node-id>
redis-cli -a zx123456
--
cluster del-node<待删除节点 ip>
:<待删除节点 port>
<待删除节点 node-id>
https://www.ruby-lang.org/en/downloads/
redis用户新建文件夹
cd /home/redis
mkdir ruby
cd /home/redis/ruby
tar -zxvf ruby-2.5.3.tar.gz
cd ruby-2.5.3
./configure--
prefix=/home/redis/ruby
make && make install
--
prefix是将ruby安装到指定目录,也可以自定义
编译过程需要几分钟
使用root用户,执行命令:
ln -s /home/redis/ruby/bin/ruby /usr/bin/ruby
ruby -v
https://rubygems.org/pages/download
redis用户新建文件夹
cd /home/redis
mkdir rubygems
cd /home/redis/rubygems
tar -zxvf rubygems-2.7.8.tgz
cd rubygems-2.7.8
ruby setup.rb
使用root用户,执行命令:
ln -s /home/redis/rubygems/rubygems-2.7.8/bin/gem /usr/bin/gem
######⑤、验证
gem -v
redis 用户执行
cp /home/redis/redis-5.0.2/src/redis-trib.rb /home/redis/rubygems/rubygems-2.7.8/bin
root 用户执行
ln -s /home/redis/rubygems/rubygems-2.7.8/bin/redis-trib.rb /usr/bin/redis-trib
【原因】:以前redis集群旧数据和配置信息没有清理干净。
【方案】:
1、备份 .aof 、.rdb 、 nodes-xxx.cnf 文件然后删除
2、重启所有节点
3、重启集群