centos7 redis安装/集群部署/slots迁移


一.安装依赖

1.ruby

安装 yum install ruby

安装后查看版本 ruby -v (redis依赖版本为2.0以上)

若不满足则卸载 yum remove ruby ruby-devel

重新安装

方法一:换yum源安装

yum install centos-release-scl-rh  //会在/etc/yum.repos.d/目录下多出一个CentOS-SCLo-scl-rh.repo源

yum install rh-ruby25  -y    //直接yum安装即可

scl  enable  rh-ruby25 bash    //必要一步

ruby -v    //查看安装版本

方法二:下载tar压缩包安装

wget http://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.5.tar.gz

tar zxvf  ruby-2.3.5.tar.gz

cd ruby-2.3.5

./configure  --prefix=/opt/ruby

make && make install

ln -s /opt/ruby/bin/ruby /usr/bin/ruby

ln -s /opt/ruby/bin/gem /usr/bin/gem

ruby -v    //查看一下

方法三:RVM 安装

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E37D2BAF1CF37B13E2069D6956105BD0E739499BDB

可能会等待一段时间,然后执行下面命令:

curl -sSL https://get.rvm.io | bash -s stable

source  /etc/profile.d/rvm.sh    //按照提示,执行该命令

rvm list known    // list一下可以安装的版本

rvm install 2.4.1     // 直接跟版本号即可

ruby -v     //查看验证下已经安装的版本

gem -v

2.gem

yum install rubygems

3.redis接口

下载https://rubygems.org/gems/redis/versions/3.3.5

gem install -l redis-3.3.5.gem

gem list|grep redis //查看安装版本

二.redis

1.安装

下载源码http://download.redis.io/releases/redis-4.0.1.tar.gz 

安装redis需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:yum install gcc-c++

解压命令: 

tar -zxvf redis-4.0.1.tar.gz 

//进入解压后的目录进行编译 

cd /usr/local/redis-4.0.1 

make 

//安装到指定目录,如 /usr/local/redis 

cd /usr/local/redis-4.0.1 

make PREFIX=/usr/local/redis install 

2.配置文件

bind 192.168.182.128

protected-mode no

port 7001

daemonize yes

supervised no

pidfile /var/run/redis_7001.pid

loglevel notice

logfile "/home/test/redis/7001/log"

databases 16

always-show-logo yes

save 900 1

save 300 10

save 60 10000

rdbcompression yes

dbfilename dump.rdb

dir /home/test/redis/7001/data/

appendonly no

appendfilename "appendonly.aof"

# appendfsync always

appendfsync everysec

# appendfsync no

cluster-enabled yes

cluster-config-file nodes-7001.conf

cluster-node-timeout 15000

masterauth "****"

requirepass "****"

3.启动

/home/test/redis/bin/redis-server /home/test/redis/7001/redis11.conf

/home/test/redis/bin/redis-server /home/test/redis/7002/redis12.conf

/home/test/redis/bin/redis-server /home/test/redis/7003/redis13.conf

4.检测

ps -el | grep redis

5.创建集群

/home/test/redis/bin/redis-trib.rb create --replicas 1 192.168.182.128:7001 192.168.182.128:7002 192.168.182.128:7003 192.168.182.129:7001 192.168.182.129:7002 192.168.182.129:7003

6.连接

/home/test/redis/bin/redis-cli -c -h 192.168.182.128 -p $1 -a ****

三.sentinel

1.配置

bind 192.168.182.128

port 27001

daemonize yes

dir /tmp

sentinel monitor mymaster1 192.168.182.128 7001 2

sentinel monitor mymaster2 192.168.182.128 7002 2

sentinel monitor mymaster3 192.168.182.129 7001 2

sentinel down-after-milliseconds mymaster1 30000

sentinel down-after-milliseconds mymaster2 30000

sentinel down-after-milliseconds mymaster3 30000

sentinel parallel-syncs mymaster1 1

sentinel parallel-syncs mymaster2 1

sentinel parallel-syncs mymaster3 1

sentinel failover-timeout mymaster1 180000

sentinel failover-timeout mymaster2 180000

sentinel failover-timeout mymaster3 180000

2.启动

/home/test/redis/bin/redis-sentinel /home/test/redis/sentinel/sentinel.conf

3.检查

ps -el | grep sentinel

四.redis集群增减节点/迁移slots

1.新增主节点

redis-trib.rb add-node  192.168.182.130:7001 192.168.182.128:7001

2.新增从节点

redis-trib.rb add-node –-slave 192.168.182.130:7003 192.168.182.128:7001

redis-trib.rb add-node –-slave 192.168.182.130:7002 192.168.182.128:7001

3.密码

//使密码失效

CONFIG SET masterauth ""

CONFIG SET requirepass ""

config rewrite

//添加密码

CONFIG SET masterauth ****

CONFIG SET requirepass ****

config rewrite

4.迁移solt

./redis-trib.rb reshard 192.168.182.128:7001

填入迁移solt个数

填入接收节点

填入源节点

done

5.将主节点变更为从节点

CLUSTER REPLICATE 35eeecb262bd3c6a5537d46c337df12022bb55c9  //将当前节点变更为node_id指定节点的从节点

6.检查集群

./redis-trib.rb check 192.168.182.128:7001

你可能感兴趣的:(centos7 redis安装/集群部署/slots迁移)