Redis快速上手篇七(集群-一台虚拟机六个节点)

​​​​​​http://t.csdnimg.cn/S0NpK与上篇六个虚拟机配置基本一样有不懂可以看上篇配置实例

集群搭建

根据上篇文章,本篇只着重于小方面的配置差别

配置集群一般不要设置密码

1.搭建一台虚拟机后再安装目录下新建文件夹 redis_cluster

2.在文件夹内创建六个文件夹,分别为7001 7002 7003 7004 7005 7006

3.将 redis.conf 拷贝到这六个目录中

echo ./7002 ./7003 ./7004 ./7005 ./7006 | xargs -n 1 cp -v /usr/local/bin/redis_cluster/7001/redis.conf

4.配置 redis7001.conf

vim redis7001.conf

这里我们并没有新建 redis7001.conf 文件vim编辑不存在的文件会自动创建

引入的配置文件为安装目录下的 redis.conf 文件复制过来

cp usr/local/bin/redis.conf /usr/local/bin/redis_cluster

复制代码
include /usr/local/bin/redis_cluster/redis.conf #引入配置文件
port 7001 #端口设置
pidfile "/var/run/redis_7001.pid" #存放进程ID防止启动多个进程副本
dbfilename "dump_7001.rdb" #持久化文件名称
dir "/usr/local/bin/redis_cluster" #持久化保存位置
logfile "/usr/local/bin/redis_cluster/redis_err_7001.log"
cluster-enabled yes    #开启集群
cluster-config-file nodes-7001.conf #节点名称
cluster-node-timeout 15000 #节点过期时间

5.分别对每个文件夹下的每个 .conf文件进行以上配置

注意端口号

后续步骤与 ​​​​​​ http://t.csdnimg.cn/enij1文章中完全一致

需要注意运行时文件夹路径

一键启动与关闭脚本

bash 复制代码
#! /bin/bash
l=`ps -ef|grep -w redis|grep -v grep|wc -l`
if [ $l == 0 ]
then
   echo "redis还没有启动,开始启动。。。。"
   /usr/local/bin/redis-server /usr/local/bin/redis_cluster/7001/redis.conf
   /usr/local/bin/redis-server /usr/local/bin/redis_cluster/7002/redis.conf
   /usr/local/bin/redis-server /usr/local/bin/redis_cluster/7003/redis.conf
   /usr/local/bin/redis-server /usr/local/bin/redis_cluster/7004/redis.conf
   /usr/local/bin/redis-server /usr/local/bin/redis_cluster/7005/redis.conf
   /usr/local/bin/redis-server /usr/local/bin/redis_cluster/7006/redis.conf
  echo "启动成功。。。。。。。。。"
else
  echo "redis已经启动,开始关闭******************************"
  /usr/local/bin/redis-cli -h 127.0.0.1 -p 7001 shutdown
  /usr/local/bin/redis-cli -h 127.0.0.1 -p 7002 shutdown
  /usr/local/bin/redis-cli -h 127.0.0.1 -p 7003 shutdown
  /usr/local/bin/redis-cli -h 127.0.0.1 -p 7004 shutdown
  /usr/local/bin/redis-cli -h 127.0.0.1 -p 7005 shutdown
  /usr/local/bin/redis-cli -h 127.0.0.1 -p 7006 shutdown
  echo "关闭成功****************************************"
fi
相关推荐
weixin_459753942 小时前
golang如何实现Trace上下文传播_golang Trace上下文传播实现思路
jvm·数据库·python
zhangfeng11332 小时前
openclaw skills 小龙虾技能 通讯仿真 matlab skill Simulink Agentic Toolkit,通过kimi找到,mcp通讯
开发语言·matlab·openclaw·通讯仿真
weixin_444012932 小时前
PHP 中逻辑或(--)运算符的正确使用与条件逻辑重构指南
jvm·数据库·python
iAm_Ike8 小时前
Go 中自定义类型与基础类型间的显式类型转换详解
jvm·数据库·python
iuvtsrt8 小时前
Golang怎么实现方法集与接口的匹配_Golang如何理解值类型和指针类型实现接口的区别【详解】
jvm·数据库·python
chao1898448 小时前
基于 SPEA2 的多目标优化算法 MATLAB 实现
开发语言·算法·matlab
難釋懷8 小时前
Redis数据结构-Set结构
数据结构·redis·bootstrap
赏金术士9 小时前
Kotlin 习题集 · 高级篇
android·开发语言·kotlin
tongluowan0079 小时前
MySQL中列数量及长度
数据库·mysql
-liming-9 小时前
单片机设计_串口调试工具
数据库·单片机·mongodb