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
相关推荐
m0_734949795 小时前
MySQL如何配置定时清理过期备份文件_find命令与保留周期策略
jvm·数据库·python
t***5445 小时前
Clang 编译器在 Orwell Dev-C++ 中的局限性
开发语言·c++
m0_514520575 小时前
MySQL索引优化后性能没提升_通过EXPLAIN查看索引命中率
jvm·数据库·python
NaMM CHIN5 小时前
sql实战解析-sum()over(partition by xx order by xx)
数据库·sql
不瘦80斤不改名5 小时前
深入浅出 MySQL(一):一文理清 SQL 核心规范与五大分类
数据库·sql·mysql
oy_mail5 小时前
QoS质量配置
开发语言·智能路由器·php
oyzz1206 小时前
PHP操作redis
开发语言·redis·php
woniu_buhui_fei6 小时前
MySQL知识整理二
数据库·mysql
nashane6 小时前
HarmonyOS 6学习:网络能力变化监听与智能提示——告别流量偷跑,打造贴心网络感知应用
开发语言·php·harmony app
yolo_guo6 小时前
redis++使用: hmset 与 hmget
c++·redis