链接: https://pan.baidu.com/s/1IczvAUFhNz23xvCjlTiI_A?pwd=ruge
- Redis入门篇
https://blog.csdn.net/tongxin_tongmeng/article/details/126620333 - 集群配置文件(3主3从)
1.复制/home/redis/redis-7.0.4/redis.conf到/home/redis/workspace/cluster_many cp /home/redis/redis-7.0.4/redis.conf /home/redis/workspace/cluster_many/redis_7001.conf cp /home/redis/redis-7.0.4/redis.conf /home/redis/workspace/cluster_many/redis_7002.conf cp /home/redis/redis-7.0.4/redis.conf /home/redis/workspace/cluster_many/redis_7003.conf 2.编辑/home/redis/workspace/cluster_many/redis_7001.conf 设置服务端口:port 7001 解除本机绑定:# bind 127.0.0.1 -::1 守护方式启动:daemonize yes 设置pid路径:pidfile /home/redis/workspace/cluster_many/redis_7001.pid 设置存储路径:dir /home/redis/workspace/cluster_many 设置连接密码:requirepass 123456 AOF方式持久化:appendonly yes AOF存储文件名:appendfilename "appendonly_7001.aof" AOF持久化策略:appendfsync always 开启集群:cluster-enabled yes 集群Node名称:luster-config-file nodes_7001.conf 集群超时时间:cluster-node-timeout 5000 3.编辑/home/redis/workspace/cluster_many/redis_7002.conf 设置服务端口:port 7002 解除本机绑定:# bind 127.0.0.1 -::1 守护方式启动:daemonize yes 设置pid路径:pidfile /home/redis/workspace/cluster_many/redis_7002.pid 设置存储路径:dir /home/redis/workspace/cluster_many 设置连接密码:requirepass 123456 AOF方式持久化:appendonly yes AOF存储文件名:appendfilename "appendonly_7002.aof" AOF持久化策略:appendfsync always 开启集群:cluster-enabled yes 集群Node名称:luster-config-file nodes_7002.conf 集群超时时间:cluster-node-timeout 5000 4.编辑/home/redis/workspace/cluster_many/redis_7003.conf 设置服务端口:port 7003 解除本机绑定:# bind 127.0.0.1 -::1 守护方式启动:daemonize yes 设置pid路径:pidfile /home/redis/workspace/cluster_many/redis_7003.pid 设置存储路径:dir /home/redis/workspace/cluster_many 设置连接密码:requirepass 123456 AOF方式持久化:appendonly yes AOF存储文件名:appendfilename "appendonly_7003.aof" AOF持久化策略:appendfsync always 开启集群:cluster-enabled yes 集群Node名称:luster-config-file nodes_7003.conf 集群超时时间:cluster-node-timeout 5000
-
克隆redis-1-->redis-2
redis-1:192.168.1.4 redis-2:192.168.1.244
-
创建集群
注意:端口7001、7002、7003为本机客户端登录端口,17001、17002、17003为redis集群默认的集群总线端口,集群内部不同机器之间通过集群总线端口互相进行客户端登录,如果防火墙不打开集群总线端口则集群无法正常创建,持续阻塞"Waiting for the cluster to join" 1.打开redis-1防火墙端口权限 firewall-cmd --zone=public --add-port=17001/tcp --permanent firewall-cmd --zone=public --add-port=17002/tcp --permanent firewall-cmd --zone=public --add-port=17003/tcp --permanent firewall-cmd --reload 2.启动redis-1的redis服务 redis-server /home/redis/workspace/cluster_many/redis_7001.conf redis-server /home/redis/workspace/cluster_many/redis_7002.conf redis-server /home/redis/workspace/cluster_many/redis_7003.conf 3.打开redis-2防火墙端口权限 firewall-cmd --zone=public --add-port=17001/tcp --permanent firewall-cmd --zone=public --add-port=17002/tcp --permanent firewall-cmd --zone=public --add-port=17003/tcp --permanent firewall-cmd --reload 4.启动redis-2的redis服务 redis-server /home/redis/workspace/cluster_many/redis_7001.conf redis-server /home/redis/workspace/cluster_many/redis_7002.conf redis-server /home/redis/workspace/cluster_many/redis_7003.conf 5.创建集群(redis-1或redis-2执行) redis-cli -a 123456 --cluster create --cluster-replicas 1 192.168.1.4:7001 192.168.1.4:7002 192.168.1.4:7003 192.168.1.244:7001 192.168.1.244:7002 192.168.1.244:7003 注意:前3个为主节点,后3个为从节点,创建命令只执行一次,重启集群只需要重启redis服务
-
启动集群
1.启动redis-1的redis服务 redis-server /home/redis/workspace/cluster_many/redis_7001.conf redis-server /home/redis/workspace/cluster_many/redis_7002.conf redis-server /home/redis/workspace/cluster_many/redis_7003.conf 2.启动redis-2的redis服务 redis-server /home/redis/workspace/cluster_many/redis_7001.conf redis-server /home/redis/workspace/cluster_many/redis_7002.conf redis-server /home/redis/workspace/cluster_many/redis_7003.conf
-
关闭集群
1.方式一:redis-cli命令关闭集群(推荐) redis-cli -a 123456 -c -h 192.168.1.4 -p 7001 shutdown redis-cli -a 123456 -c -h 192.168.1.4 -p 7002 shutdown redis-cli -a 123456 -c -h 192.168.1.4 -p 7003 shutdown redis-cli -a 123456 -c -h 192.168.1.244 -p 7001 shutdown redis-cli -a 123456 -c -h 192.168.1.244 -p 7002 shutdown redis-cli -a 123456 -c -h 192.168.1.244 -p 7003 shutdown 注意:redis-1或者redis-2可以相互关闭对方的redis服务 2.方式二:根据进程号关闭集群(方便) ps -ef | grep -i redis kill -9 24611 24617 24643
-
登录集群
1.登录redis-1的客户端 redis-cli -a 123456 -c -h 192.168.1.4 -p 7001 redis-cli -a 123456 -c -h 192.168.1.4 -p 7002 redis-cli -a 123456 -c -h 192.168.1.4 -p 7003 2.登录redis-2的客户端 redis-cli -a 123456 -c -h 192.168.1.244 -p 7001 redis-cli -a 123456 -c -h 192.168.1.244 -p 7002 redis-cli -a 123456 -c -h 192.168.1.244 -p 7003 2.客户端切换时需要先退出:quit
-
集群信息
-
数据备份、恢复