记录一下:
1 运行了一个ubantu镜像
docker run -itd -p 10001:10001 -p 10002:10002 -p 10003:10003 -p 10004:10004 -p 10005:10005 -p 10006:10006 镜像名 /bin/bash
2 下载redis
wget http://download.redis.io/releases/redis-6.0.6.tar.gz
3 ubantu 镜像真干净 (没有make gcc)
yum install gcc gcc-c++ make automake autocon
4 解压
tar xzf redis-6.0.6.tar.gz cd redis-6.0.6 make make install
5 运行测试
redis-server redis-cli
6 开始搭建
mkdir -p /usr/local/redis-cluster/ cd /usr/local/redis-cluster/ mkdir 10001 10002 10003 10004 10005 10006 # cd 到 redis-6.0.6 cp redis.conf /usr/local/redis-cluster/10001 vim /usr/local/redis-cluster/10001/redis.conf
7 配置redis.conf (vim 中 /字符串) 查找
bind 172.17.0.2 # 自己的容器ip port 10001 # 端口尽量与文件夹一致 daemonize yes # 设置守护 dir /usr/local/redis-cluster/10001/ # 指定配置文件路径 appendonly yes # 开启日志 cluster-enabled yes # 开启集群 cluster-config-file nodes-10002.conf # 指定节点文件 cluster-node-timeout 5000
8 运行测试
redis-server /usr/local/redis-cluster/10001/redis.conf
9 配置多个节点( vim 命令 /%s/旧字符串/新字符串/g) 全局替换
cp /usr/local/redis-custer/10001/redis.conf /usr/local/redis-custer/10002/ vim /usr/local/redis-custer/10002/redis.conf /%s/10001/10002/g ..... .... ... .. .
10.运行测试
redis-server /usr/local/redis-cluster/10001/redis.conf redis-server /usr/local/redis-cluster/10002/redis.conf redis-server /usr/local/redis-cluster/10003/redis.conf redis-server /usr/local/redis-cluster/10004/redis.conf redis-server /usr/local/redis-cluster/10005/redis.conf redis-server /usr/local/redis-cluster/10006/redis.conf ps -ef |grep redis
11.创建集群 (redis5.0 之后 不在采用ruby 启动 而是c)
redis-cli --cluster create 172.17.0.2:10001 172.17.0.2:10002 172.17.0.2:10003 172.17.0.2:10004 172.17.0.2:10005 172.17.0.2:10006 --cluster-replicas 1 成功 ....
12 验证
redis-cli -c -p 172.17.0.2 -p 10001 cluster-info # 查看集群信息 cluster nodes # 查看节点详细信息
13 杀掉集群
# kill 掉 ps -ef | grep redis 进程 rm /usr/local/redis-custer/10001/redis-nodes-10002.conf appendonly.aof # 删除这两个文件 # 再重复 10, 11