1、部署单机redis
(1)下载redis安装包
wget http://download.redis.io/releases/redis-4.0.10.tar.gz
复制代码
(2)解压到指定文件夹
tar zxvf redis-4.0.10.tar.gz
mv redis-4.0.10 /usr/local/redis/
复制代码
(3)编译安装
cd /usr/local/redis
make
make install
复制代码
(4)修改redis的配置文件
vim /usr/local/redis/redis.conf
复制代码
port 6379
daemonize yes
bind 0.0.0.0
pidfile /var/run/redis_6379.pid
cluster-enabled no
appendonly yes
复制代码
(5)启动redis
redis-server /usr/local/redis/redis.conf
复制代码
2、部署redis集群
(1)创建文件夹
mkdir -p /usr/local/redis-cluster/{9001,9002,9003,9004,9005,9006}/data
复制代码
(2)修改/usr/local/redis/redis.conf的配置文件为集群模式,如下:
port 9001
daemonize yes
bind 0.0.0.0
dir /usr/local/redis-cluster/9001/data/
pidfile /var/run/redis_9001.pid
cluster-enabled yes
cluster-config-file nodes9001.conf
cluster-node-timeout 15000
appendonly yes
复制代码
(3)拷贝配置文件到创建的6个端口的文件夹,并修改配置文件中的端口
cd /usr/local/redis-cluster
echo 9001/ 9002/ 9003/ 9004/ 9005/ 9006/ | xargs -n 1 cp -v /usr/local/redis/redis.conf
复制代码
(4)启动6个redis服务
redis-server /usr/local/redis-cluster/9001/redis.conf
redis-server /usr/local/redis-cluster/9002/redis.conf
redis-server /usr/local/redis-cluster/9003/redis.conf
redis-server /usr/local/redis-cluster/9004/redis.conf
redis-server /usr/local/redis-cluster/9005/redis.conf
redis-server /usr/local/redis-cluster/9006/redis.conf
复制代码
(5)安装ruby,如果提示版本需要大于2.2.2,需要使用rvm安装ruby
yum install ruby
yum install rubygems
gem install redis
复制代码
(6)启动集群
/usr/local/redis/src/redis-trib.rb create --replicas 1 服务器ip:9001 服务器ip.42:9002 服务器ip:9003 服务器ip:9004 服务器ip:9005 服务器ip:9006
复制代码