Redis|Redis 集群搭建
Redis 集群搭建 (伪集群)
软件环境
centos7.3 (虚拟机)
redis 5.0.5
搭建步骤
创建相关目录
- 创建主文件夹redis-cluster 在此文件夹下面创建六个子文件夹
mkdir /opt/redis-cluster
cd /opt/redis-cluster
mkdir 7000 7001 7002 7003 7004 7005
安装redis 5.0.5
- redis官网下载压缩包拷贝到/opt/redis-cluster中
- 编译安装
cd /opt/redis-cluster/redis5.0.5
make MALLOC=libc
cd src && make install
启动六个redis实例
- 移动redis.conf文件到每个实例中
cp /opt/redis-cluster/redis5.0.5/redis.conf /opt/redis-cluster/7000
- 修改配置
# bind 192.168.1.187//绑定服务器IP地址(注释掉开启远程连接)
port 7000//绑定端口号,必须修改,以此来区分Redis实例daemonize yes//后台运行pidfile /var/run/redis-7000.pid//修改pid进程文件名,以端口号命名logfile /root/application/program/redis-cluster/7000/redis.log//修改日志文件名称,以端口号为目录来区分dir /root/application/program/redis-cluster/7000///修改数据文件存放地址,以端口号为目录名来区分cluster-enabled yes//启用集群cluster-config-file nodes-7000.conf//配置每个节点的配置文件,同样以端口号为名称cluster-node-timeout 15000//配置集群节点的超时时间,可改可不改appendonly yes//启动AOF增量持久化策略appendfsync always//发生改变就记录日志protected-mode no
- 启动六个redis实例
cd /opt/redis-cluster/redis5.0.5/src
cp /redis-server ../
cp /redis-cli ../
cd ../
redis-server /opt/redis-cluster/7000/redis.conf
redis-server /opt/redis-cluster/7001/redis.conf
redis-server /opt/redis-cluster/7002/redis.conf
redis-server /opt/redis-cluster/7003/redis.conf
redis-server /opt/redis-cluster/7004/redis.conf
redis-server /opt/redis-cluster/7005/redis.conf
创建集群
- 执行创建集群命令
cd /opt/redis-cluster/redis5.0.5
redis-cli --cluster create 192.168.1.187:7000 192.168.1.187:7001 192.168.1.187:7002 192.168.1.187:7003 192.168.1.187:7004 192.168.1.187:7005 --cluster-replicas 1
全部重启
- 删除所有实例下面的 appendonly.aof 和 nodes-700*.conf
cd /opt/redis-cluster/
find . -name '*.aof' -type f -print -exec rm -rf {} \;
find . -name 'nodes-700*' -type f -print -exec rm -rf {} \;
- 杀掉所有redis实例进程
pkill -9 redis
- 重新启动所有redis实例
redis-server /opt/redis-cluster/7000/redis.conf
redis-server /opt/redis-cluster/7001/redis.conf
redis-server /opt/redis-cluster/7002/redis.conf
redis-server /opt/redis-cluster/7003/redis.conf
redis-server /opt/redis-cluster/7004/redis.conf
redis-server /opt/redis-cluster/7005/redis.conf
- 创建集群
redis-cli --cluster create 192.168.1.187:7000 192.168.1.187:7001 192.168.1.187:7002 192.168.1.187:7003 192.168.1.187:7004 192.168.1.187:7005 --cluster-replicas 1
【Redis|Redis 集群搭建】==注意:== 这种重启会丢失数据
推荐阅读
- 六步搭建ES6语法环境
- federation--kubernetes集群联邦的实现
- springboot使用redis缓存
- (1)redis集群原理及搭建与使用(1)
- 桁架搭建有什么价值()
- VM|VM ware 的 harbor 私有仓库搭建 (Ubuntu16.04)
- PHP开发-Mac搭建ThinkPHP5.0
- springboot结合redis实现搜索栏热搜功能及文字过滤
- Python|Win10下 Python开发环境搭建(PyCharm + Anaconda) && 环境变量配置 && 常用工具安装配置
- Redis——发布订阅/消息队列