1、主机
- 172.16.12.252
- 172.16.12.253
2、两台主机home 目录下创建文件夹
- /home/redis-cluster/7001/log
- /home/redis-cluster/7001/data
- /home/redis-cluster/7002/log
- /home/redis-cluster/7002/data
- /home/redis-cluster/7003/log
- /home/redis-cluster/7003/data
3、配置文件,将配置文件放入对应的端口
- 172.16.12.252 配置文件
redis-7001-master.conf
redis-7002-slave.conf
redis-7003-slave.conf - 172.16.12.253 配置文件
redis-7001-master.conf
redis-7002-master.conf
redis-7003-slave.conf - master节点需要改动的配置
bind 172.16.12.252
protected-mode yes
port 7001
pidfile /var/run/redis_7001.pid
logfile /home/redis-cluster/7001/log/7001.log
dir /home/redis-cluster/7001/data/
appendonly yes
cluster-enabled yes
cluster-config-file /home/redis-cluster/7001/nodes-7001.conf
requirepass 12678
- slave 节点需要改动的配置
bind 172.16.12.253
protected-mode yes
port 7003
pidfile /var/run/redis_7003.pid
logfile /home/redis-cluster/7003/log/7003.log
dir /home/redis-cluster/7003/data/
appendonly yes
cluster-enabled yes
cluster-config-file /home/redis-cluster/7003/nodes-7003.conf
requirepass 12678
4、下载redis 并安装
- 下载redis redis-4.0.11.tar.gz
- 将redis 解压在 /usr/local/redis 目录下面 tar -zxvf redis-4.0.11.tar.gz
- 安装redis 在redis-4.0.11 目录下执行 make
- 创建软连接,
- ln -s /usr/local/redis/redis-4.0.11/src/redis-server /usr/local/bin/redis-server
- ln -s /usr/local/redis/redis-4.0.11/src/redis-cli /usr/local/bin/redis-cli
5、创建redis集群
- 启动每个redis 节点
- redis-server /home/redis-cluster/7001/redis-7001.conf
- redis-server /home/redis-cluster/7002/redis-7002.conf
- redis-server /home/redis-cluster/7003/redis-7003.conf
- 通过ps 查看节点启动情况
创建集群
- 打开端口
1、查看防火墙策略
firewall-cmd —list-all
2、端口加入防火墙策略
sudo firewall-cmd —zone=public —add-port=17001/tcp —permanent
sudo firewall-cmd —zone=public —add-port=17002/tcp —permanent
sudo firewall-cmd —zone=public —add-port=17003/tcp —permanent
sudo firewall-cmd —zone=public —add-port=7001/tcp —permanent
sudo firewall-cmd —zone=public —add-port=7002/tcp —permanent
sudo firewall-cmd —zone=public —add-port=7003/tcp —permanent
3、重新加载防火墙
sudo firewall-cmd —reload 安装ruby gem redis
- 安装 yum install –y ruby
- 安装 yum install -y rubygems
- gem install redis
- 此处报错,说需要ruby 的版本大于2.3.0,但是centos 只支持到2.0.0 此处需要将ruby提升至2.3.0
- 执行以下命令即可升级
$ curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
$ curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
$ curl -L get.rvm.io | bash -s stable
$ find / -name rvm.sh
$ source /etc/profile.d/rvm.sh
$ rvm requirements
$ rvmsudo yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel
$ source /usr/local/rvm/scripts/rvm
$ rvm list known # 查看rvm库中已知的ruby版本
$ rvm install 2.3.3 # 安装一个ruby版本
$ rvm use 2.3.3 # 使用一个ruby版本
$ rvm remove 2.0.0 # 卸载已知版本
$ gem install redis # 安装reids
此处也可以手动安装gem redis,不用执行以上ruby命令
gem install —local redis-4.1.3.gem 下载连接redis-4.1.3.gem- 在 /usr/local/redis/redis-4.0.11/src 目录下执行
./redis-trib.rb create —replicas 1 172.16.12.253:7001 172.16.12.253:7002 172.16.12.253:7003 172.16.12.252:7001 172.16.12.252:7002 172.16.12.252:7003 - 重启/重建Redis集群时,必须删除去/etc/redis/nodes.conf文件。
- 打开端口
参考文档
https://blog.csdn.net/weixin_42255229/article/details/80425565