systemctl stop firewalld
setenforce 0
yum install lrz* -y
yum install gcc gcc-c++ make -y
yum install zlib-devel -y
tar xf redis-5.0.0.tar.gz -C /opt/
cd /opt/redis-5.0.0
make install PREFIX=/usr/local/redis
make && make install
mkdir /usr/local/redis-cluster
cd /usr/local/redis-cluster/
mkdir -p 6379/data 6380/data 6381/data 6382/data 6383/data 6384/data
mkdir /usr/local/redis-cluster/bin
cd /opt/redis-5.0.0/src/
cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli redis-server redis-trib.rb /usr/local/redis-cluster/bin
cp /opt/redis-5.0.0/redis.conf 6379/
cd /usr/local/redis/bin/
vi 6379/redis.conf //修改各实例的配置文件
port 6379 //每个节点的端口号
daemonize yes
bind 192.168.86.102 //绑定当前机器 IP
dir /usr/local/redis-cluster/6379/data/ //数据文件存放位置
pidfile /var/run/redis_6379.pid //pid 6379和port要对应
cluster-enabled yes //启动集群模式
cluster-config-file nodes6379.conf //6379和port要对应
cluster-node-timeout 15000
appendonly yes
cp 6379/redis.conf 6380
cp 6379/redis.conf 6381
cp 6379/redis.conf 6382
cp 6379/redis.conf 6383
cp 6379/redis.conf 6384
vi 6380/redis.conf
:%s /6379/6380/g
注:剩余配置文件一样的操作
//开启所有节点服务(&是后台运行):
for i in 79 80 81 82 83 84; do /usr/local/bin/redis-server /usr/local/redis-cluster/63$i/redis.conf& done
//登录随便一个节点验证 确认节点服务可以正常登陆:
/usr/local/redis-cluster/bin/redis-cli -h 192.168.80.102 -p 6379
//查看进程,看有没有6个端口
ps -ef|grep redis|grep cluster
//配置Ruby环境-安装Ruby
yum install -y ruby ruby-devel rubygems rpm-build
gem install redis
报以下错误的话:
Fetching: redis-4.0.1.gem (100%)
ERROR: Error installing redis:
redis requires Ruby version >= 2.2.2.
注意:redis-trib.rb的运行需要的ruby包,Ruby版本至少需要2.2.2
安装rvm工具:
首先安装rvm安装会使用的包
yum install gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel sqlite-devel
安装rvm
curl -sSL https://rvm.io/pkuczynski.asc | gpg2 –import –
curl -L get.rvm.io | bash -s stable
配置rvm的运行环境
source /etc/profile.d/rvm.sh
rvm reload
检查安装情况
rvm requirements run
安装Ruby 2.4.1
rvm install 2.4.1
查看安装结果
rvm use 2.4.1
rvm remove 2.0.0
ruby –version
gem redis接口安装:
gem install redis
rubygems 安装:
yum install -y rubygems
cd /opt/redis-5.0.0/src/
cp redis-trib.rb /usr/local/bin
创建Redis集群:
redis-trib.rb create –replicas 1 192.168.80.102:6379 192.168.80.102:6380 192.168.80.102:6381 192.168.80.102:6382 192.168.80.102:6383 192.168.80.102:6384
redis-cli –cluster create 192.168.80.102:6379 192.168.80.102:6380 192.168.80.102:6381 192.168.80.102:6382 192.168.80.102:6383 192.168.80.102:6384 –cluster-replicas 1
创建Redis集群
redis-cli -h 192.168.80.102 -c -p 6379
192.168.86.100:6379> cluster info //查看状态
192.168.86.100:6379> cluster nodes //查看节点信息
注:-h+host –p+端口号 –c 连接集群,连接Redis集群必须要加该参数