redis集群部署


redis集群部署(单机)

 1.下载redis源码包

wget http://download.redis.io/releases/redis-4.0.11.tar.gz

2.安装部署

tar -xvf redis-4.0.11.tar.gz -C /usr/local
cd /usr/local/redis-4.0.11
make && make install

3.创建集群目录

mkdir /usr/local/redis-cluster
cd  /usr/local/redis-cluster
mkdir  data  log  conf
mkdir -p data/redis600{1..6}

4.下载ruby

wget https://repo.huaweicloud.com/ruby/ruby/ruby-2.3.8.tar.gz
tar -xvf ruby-2.3.8.tar.gz -C /usr/local/
cd  /usr/local/ruby-2.3.8/
./configure prefix=/usr/local/ruby
make && make install
ruby -v
ln -s /usr/local/ruby/bin/ruby /usr/bin/ruby
ln -s /usr/local/ruby/bin/gem /usr/bin/gem

5.下载rubygem redis依赖

wget http://rubygems.org/downloads/redis-3.3.0.gem
gem install -l redis-3.3.0.gem

# 一般会报错以下信息
ERROR:  Loading command: install (LoadError)
    cannot load such file -- zlib
ERROR:  While executing gem ... (NoMethodError)
    undefined method `invoke_with_build_args' for nil:NilClass

# 我们做下下面步骤
yum -y install zlib-devel
cd ruby-2.3.8/ext/zlib/
ruby ./extconf.rb
make && make install
gem install -l redis-3.3.0.gem
# Successfully installed redis-3.3.0
# 显示这条信息代表安装成功

 6.配置redis集群中各节点配置文件

cp /usr/local/redis/src/redis-trib.rb /usr/local/redis-cluster/
cd /usr/local/redis-cluster/data
mkdir -p redis-600{1..6} cd /usr/local/redis-cluster/conf touch redis-600{1..6}.conf

 redis-6001.conf

vim redis-6001.conf     

daemonize yes
bind 127.0.0.1
dir /usr/local/redis-cluster/data/redis-6001
pidfile /var/run/redis-cluster/redis-6001.pid
logfile /usr/local/redis-cluster/log/redis-6001.log
port 6001
masterauth "123456" 
requirepass "123456"
cluster-enabled yes
cluster-config-file /usr/local/redis-cluster/conf/node-6001.conf
cluster-node-timeout 10000
appendonly yes

redis-6002.conf

vim redis-6002.conf

daemonize yes
bind 127.0.0.1
dir /usr/local/redis-cluster/data/redis-6002
pidfile /var/run/redis-cluster/redis-6002.pid
logfile /usr/local/redis-cluster/log/redis-6002.log
port 6002
masterauth "123456" 
requirepass "123456"
cluster-enabled yes
cluster-config-file /usr/local/redis-cluster/conf/node-6002.conf
cluster-node-timeout 10000
appendonly yes

redis-6003.conf

vim redis-6003.conf

daemonize yes
bind 127.0.0.1
dir /usr/local/redis-cluster/data/redis-6003
pidfile /var/run/redis-cluster/redis-6003.pid
logfile /usr/local/redis-cluster/log/redis-6003.log
port 6003
masterauth "123456" 
requirepass "123456"
cluster-enabled yes
cluster-config-file /usr/local/redis-cluster/conf/node-6003.conf
cluster-node-timeout 10000
appendonly yes

redis-6004.conf

vim redis-6004.conf

daemonize yes
bind 127.0.0.1
dir /usr/local/redis-cluster/data/redis-6004
pidfile /var/run/redis-cluster/redis-6004.pid
logfile /usr/local/redis-cluster/log/redis-6004.log
port 6004
masterauth "123456" 
requirepass "123456"
cluster-enabled yes
cluster-config-file /usr/local/redis-cluster/conf/node-6004.conf
cluster-node-timeout 10000
appendonly yes

redis-6005.conf

vim redis-6005.conf

daemonize yes
bind 127.0.0.1
dir /usr/local/redis-cluster/data/redis-6005
pidfile /var/run/redis-cluster/redis-6005.pid
logfile /usr/local/redis-cluster/log/redis-6005.log
port 6005
masterauth "123456" 
requirepass "123456"
cluster-enabled yes
cluster-config-file /usr/local/redis-cluster/conf/node-6005.conf
cluster-node-timeout 10000
appendonly yes

redis-6006.conf

vim redis-6006.conf

daemonize yes
bind 127.0.0.1
dir /usr/local/redis-cluster/data/redis-6006
pidfile /var/run/redis-cluster/redis-6006.pid
logfile /usr/local/redis-cluster/log/redis-6006.log
port 6006
masterauth "123456" 
requirepass "123456"
cluster-enabled yes
cluster-config-file /usr/local/redis-cluster/conf/node-6006.conf
cluster-node-timeout 10000
appendonly yes

启动redis节点

redis-server /usr/local/redis-cluster/conf/redis-6001.conf 
redis-server /usr/local/redis-cluster/conf/redis-6002.conf 
redis-server /usr/local/redis-cluster/conf/redis-6003.conf 
redis-server /usr/local/redis-cluster/conf/redis-6004.conf 
redis-server /usr/local/redis-cluster/conf/redis-6005.conf 
redis-server /usr/local/redis-cluster/conf/redis-6006.conf 
ps -ef | grep redis-server
netstat -tnlp |grep redis-server

创建redis集群

./redis-trib.rb create --replicas 1 127.0.0.1:6001 127.0.0.1:6002 127.0.0.1:6003 127.0.0.1:6004 127.0.0.1:6005 127.0.0.1:6006
redis-trib.rb check 127.0.0.1:6003    (检查节点)
redis-trib.rb check 127.0.0.1:6001
ps -ef |grep redis-server

 

 

posted @ 2021-06-01 15:26  Noleaf  阅读(60)  评论(0编辑  收藏  举报