1:下载redis安装包并解压
2:在redis目录下运行
make
make的时候出现
报错了
下载pkg-config包进行安装,解压后进入目录运行
./configure --with-internal-glib
make
make install
安装完后重现进入redis目录执行make,就没有这个报错了
3:创建redis-cluster目录
4:cd redis-cluster
5:创建6个数据目录
mkdir data6379
mkdir data6380
mkdir data6381
mkdir data6382
mkdir data6383
mkdir data6384
6:将redis目录下的redis.conf文件拷贝6份
cp ../redis.conf redis6379.conf
cp ../redis.conf redis6380.conf
cp ../redis.conf redis6381.conf
cp ../redis.conf redis6382.conf
cp ../redis.conf redis6383.conf
cp ../redis.conf redis6384.conf
最终的目录结构是这样
7:修改daemonize为yes,让其作为守护进程运行,在后台运行
8:分别修改端口号port 为
port 6379
port 6380
port 6381
port 6382
port 6383
port 6384
例如:
8:修改指定文件位置
对应改为:
dir /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/data6379/
dir /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/data6380/
dir /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/data6381/
dir /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/data6382/
dir /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/data6383/
dir /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/data6384/
9:修改以集群模式启动
cluster-enabled yes
10:修改集群配置文件
分别为:
cluster-config-file nodes-6379.conf
cluster-config-file nodes-6380.conf
cluster-config-file nodes-6381.conf
cluster-config-file nodes-6382.conf
cluster-config-file nodes-6383.conf
cluster-config-file nodes-6384.conf
11:开启AOF持久化
appendonly yes
12:将六个节点分别运行起来
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-server /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/redis6379.conf
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-server /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/redis6380.conf
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-server /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/redis6381.conf
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-server /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/redis6382.conf
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-server /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/redis6383.conf
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-server /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/redis6384.conf
13:ps -ef|grep redis 查看到6个进程都已经启动
14: 将6个节点搭建为一个集群,3主3从
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-cli --cluster create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 --cluster-replicas 1
1代表主从比例为1
中途询问
Can I set the above configuration? (type 'yes' to accept):
输入yes后回车即可
15:连接其中一个节点进行测试
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-cli -c -h 127.0.0.1 -p 6379
连接成功后输入
cluster info
和
cluster nodes
测试
至此集群搭建成功。
16:停止集群节点需要一个个节点进行停止
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-cli -c -h 127.0.0.1 -p 6379 shutdown
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-cli -c -h 127.0.0.1 -p 6380 shutdown
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-cli -c -h 127.0.0.1 -p 6381 shutdown
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-cli -c -h 127.0.0.1 -p 6382 shutdown
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-cli -c -h 127.0.0.1 -p 6383 shutdown
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-cli -c -h 127.0.0.1 -p 6384 shutdown
17:一个个启动和停止太麻烦了,将启动命令全部放到一个shell脚本里面、将停止命令全部放到另一个脚本里面
在redis-cluster目录下创建bin
新建startup.sh文件,内容为
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-server /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/redis6379.conf
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-server /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/redis6380.conf
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-server /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/redis6381.conf
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-server /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/redis6382.conf
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-server /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/redis6383.conf
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-server /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/redis6384.conf
新建shutdown.sh文件,内容为
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-cli -c -h 127.0.0.1 -p 6379 shutdown
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-cli -c -h 127.0.0.1 -p 6380 shutdown
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-cli -c -h 127.0.0.1 -p 6381 shutdown
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-cli -c -h 127.0.0.1 -p 6382 shutdown
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-cli -c -h 127.0.0.1 -p 6383 shutdown
/Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/src/redis-cli -c -h 127.0.0.1 -p 6384 shutdown
下次启动则运行
sh /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/bin/startup.sh
停止集群则运行
sh /Users/guanhongchang/Documents/springcloud/redis/redis-6.2.1/redis-cluster/bin/shutdown.sh
谢谢!