一、Redis单节点安装
1.1 下载redis
wget http://download.redis.io/releases/redis-4.0.2.tar.gz
1.2 安装gcc
yum install gcc-c++
1.3 解压redis
tar -zxvf redis-4.0.2.tar.gz
1.4 编译
cd redis-4.0.2
make
make install PREFIX=/opt/apps/redis
1.5 修改配置文件
mkdir -p /opt/apps/redis/conf
cp /opt/software/redis-4.0.2/redis.conf /opt/apps/redis/conf
cd /opt/apps/redis/conf
vim /opt/apps/redis/bin/redis.conf
bind ===> 0.0.0.0
daemonize no ===> daemonize yes
1.6 启动单节点redis
/opt/apps/redis/bin/redis-server /opt/apps/redis/conf/redis.conf
二、Redis单节点转换为集群模式(kill 掉原始单机)
2.1 创建集群配置文件夹
rm -rf /opt/apps/redis/conf/redis.conf
mkdir -p /opt/apps/redis/conf/7000
mkdir -p /opt/apps/redis/conf/7001
mkdir -p /opt/apps/redis/conf/7002
mkdir -p /opt/apps/redis/conf/7003
mkdir -p /opt/apps/redis/conf/7004
mkdir -p /opt/apps/redis/conf/7005
2.2 修改配置文件
cat 7000/redis-7000.conf
port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
daemonize yes
bind 192.168.197.174
pidfile /opt/apps/redis/conf/7000/redis_7000.pid
dir /opt/apps/redis/conf/7000/
2.3 其他的配置文件依据上述进行修改
修改端口号,pid文件路径 dir路径
2.4 启动
/usr/local/redis/bin/redis-server /opt/apps/redis/conf/7000/redis-7000.conf
/usr/local/redis/bin/redis-server /opt/apps/redis/conf/7001/redis-7001.conf
/usr/local/redis/bin/redis-server /opt/apps/redis/conf/7002/redis-7002.conf
/usr/local/redis/bin/redis-server /opt/apps/redis/conf/7003/redis-7003.conf
/usr/local/redis/bin/redis-server /opt/apps/redis/conf/7004/redis-7004.conf
/usr/local/redis/bin/redis-server /opt/apps/redis/conf/7005/redis-7005.conf
2.5 安装ruby脚本
yum -y install ruby ruby-devel rubygems rpm-build
2.6 拷贝ruby-redis集群脚本
cp /opt/software/redis-4.0.2/src/redis-trib.rb /opt/apps/redis/bin/
2.7 安装redis集群管理工具
gem install redis
2.7.1 如果出现错误
1.安装curl
sudo yum install curl
2. 安装RVM
curl -L get.rvm.io | bash -s stable
--------如果报错就按照提示安装证书(gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB)--------
1.删除默认的的镜像源,添加国内最新的镜像源
gem sources --add https://gems.ruby-china.com/
2.重新安装rvm
curl -L get.rvm.io | bash -s stable
3.加载rvm
source /usr/local/rvm/scripts/rvm
4.查看库中已存在的ruby版本
rvm list known
5.列出可安装的 ruby 版本
rvm install 2.3.3
6.设置默认使用 2.3.3 版本
rvm use 2.3.3 --default
7.卸载2.0.0版本
rvm remove 2.0.0
8.再次执行这个安装成功
gem install redis
2.8 创建集群
/opt/apps/redis/bin/redis-trib.rb create --replicas 1 192.168.197.174:7000 192.168.197.174:7001 192.168.197.174:7002 192.168.197.174:7003 192.168.197.174:7004 192.168.197.174:7005
2.9 查看集群状态
/opt/apps/redis/bin/redis-cli -h 192.168.197.174 -p 7000 cluster nodes