redis集群Cluster模式如何部署

這篇文章將為大家詳細講解有關(guān)redis集群Cluster模式如何部署,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站設(shè)計、成都網(wǎng)站制作、南康網(wǎng)絡(luò)推廣、小程序開發(fā)、南康網(wǎng)絡(luò)營銷、南康企業(yè)策劃、南康品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供南康建站搭建服務(wù),24小時服務(wù)熱線:18980820575,官方網(wǎng)址:bm7419.com

一、Redis 集群模式搭建

redis集群部署分為三種:主從、哨兵(Sentinel)、集群(Cluster)。

前幾天由于新應(yīng)用上線,需要部署一套redis集群,現(xiàn)形成文檔,將部署過程進行記錄。

環(huán)境介紹

ip
軟件包
系統(tǒng)版本
10.1.112.248redis-4.0.11.tar.gzCentOS Linux release 7.6.1810 (Core)
10.1.112.249redis-4.0.11.tar.gzCentOS Linux release 7.6.1810 (Core)

1、目錄結(jié)構(gòu)

[root@localhost local]# pwd
/usr/local
[root@localhost local]# tree redis-cluster/
redis-cluster/
├── redis-4.0.11-node1
│   ├── data
│   └── logs
├── redis-4.0.11-node2
│   ├── data
│   └── logs
└── redis-4.0.11-node3
    ├── data
    └── logs

9 directories, 0 files

2、下載解壓redis-4.0.11

mkdir /usr/local/software
cd /usr/local/software && wget http://download.redis.io/releases/redis-4.0.11.tar.gz
tar xf redis-4.0.11.tar.gz

3、安裝(兩臺服務(wù)器均安裝)

[root@localhost software]# pwd
/usr/local/software
[root@localhost software]# tar xf redis-4.0.11.tar.gz
[root@localhost software]# cd redis-4.0.1
[root@localhost redis-4.0.11]# make install
出現(xiàn)如下截圖即可

redis集群Cluster模式如何部署

4、準(zhǔn)備配置文件

[root@localhost redis-4.0.11]# cp src/redis-trib.rb /usr/local/bin/
[root@localhost redis-4.0.11]# cp redis.conf /usr/local/redis-cluster/redis-4.0.11-node1/
[root@localhost redis-4.0.11]# cp redis.conf /usr/local/redis-cluster/redis-4.0.11-node2/
[root@localhost redis-4.0.11]# cp redis.conf /usr/local/redis-cluster/redis-4.0.11-node3/
[root@localhost redis-4.0.11]# cp src/{redis-cli,redis-server} /usr/local/redis-cluster/redis-4.0.11-node1/
[root@localhost redis-4.0.11]# cp src/{redis-cli,redis-server} /usr/local/redis-cluster/redis-4.0.11-node2/
[root@localhost redis-4.0.11]# cp src/{redis-cli,redis-server} /usr/local/redis-cluster/redis-4.0.11-node3/
[root@localhost redis-4.0.11-node1]# grep -Ev "^#|^$" redis.conf 
bind 10.1.112.248            #領(lǐng)一臺服務(wù)器配置為10.1.112.249
protected-mode yes
port 7000                    #其他節(jié)點分別配置為7001/7002
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /usr/local/redis-cluster/redis-4.0.11-node1/redis_7000.pid          #其他節(jié)點配置為redis-4.0.11-node2/redis_7001.pid、redis-4.0.11-node3/redis_7002.pid
loglevel notice
logfile "/usr/local/redis-cluster/redis-4.0.11-node1/logs/redis_7000.log"   #同上
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /usr/local/redis-cluster/redis-4.0.11-node1/data    #redis-4.0.11-node3/data、redis-4.0.11-node3/data
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
requirepass xxx
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-node-timeout 15000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

5、分別啟動3個節(jié)點(另一臺服務(wù)器同樣啟動)

cd /usr/local/redis-cluster/redis-4.0.11-node1
./redis.server redis.conf
cd /usr/local/redis-cluster/redis-4.0.11-node2
./redis.server redis.conf
cd /usr/local/redis-cluster/redis-4.0.11-node3
./redis.server redis.conf

查看進程
[root@localhost redis-4.0.11-node1]# ps -ef |grep redis
root      6015  5673  0 17:52 pts/1    00:00:00 grep --color=auto redis
weblogic 28246     1  0 Oct21 ?        00:01:14 ./redis-server 10.1.112.248:7000 [cluster]
weblogic 28284     1  0 Oct21 ?        00:01:14 ./redis-server 10.1.112.248:7001 [cluster]
weblogic 28301     1  0 Oct21 ?        00:02:25 ./redis-server 10.1.112.248:7002 [cluster]
[root@localhost redis-4.0.11-node1]# ps -ef |grep redis
root      6015  5673  0 17:52 pts/1    00:00:00 grep --color=auto redis
weblogic 28246     1  0 Oct21 ?        00:01:14 ./redis-server 10.1.112.249:7000 [cluster]
weblogic 28284     1  0 Oct21 ?        00:01:14 ./redis-server 10.1.112.249:7001 [cluster]
weblogic 28301     1  0 Oct21 ?        00:02:25 ./redis-server 10.1.112.249:7002 [cluster]

6、使用 redis-trib.rb創(chuàng)建集群

[root@localhost redis-4.0.11-node1]# yum -y install ruby ruby-devel rubygems rpm-build
[root@localhost redis-4.0.11-node1]# gem install redis
Fetching: redis-4.1.3.gem (100%)
ERROR:  Error installing redis:
        redis requires Ruby version >= 2.3.0.
提示ruby版本過低。
升級ruby版本
[root@localhost redis-4.0.11-node1]# curl -L get.rvm.io | bash -s stable
按提示導(dǎo)入秘鑰,再次執(zhí)行"curl -L get.rvm.io | bash -s stable"

[root@localhost redis-4.0.11-node1]# source /usr/local/rvm/scripts/rvm

查看可用的ruby版本并安裝
[root@localhost redis-4.0.11-node1]# rvm list known
[root@localhost redis-4.0.11-node1]# rvm install 2.3.0   #這一步用時較長,耐心等待安裝完成。

7、安裝gem redis接口

rvm use 2.3.0
ruby --version
gem install redis

8、安裝rubygems

yum install -y rubygems

至此,Ruby和運行redis-trib.rb需要的環(huán)境安裝完成了,接下來使用redis-trib.rb創(chuàng)建集群

9、創(chuàng)建集群

redis-trib.rb create --replicas 1 10.1.112.248:7000 10.1.112.248:7001 10.1.112.248:7002 10.1.112.249:7000 10.1.112.249:7001 10.1.112.249:7002

10、查看集群狀態(tài)

[weblogic@geb-redis1 ~]$ redis-trib.rb check 10.1.112.248:7000
>>> Performing Cluster Check (using node 10.1.112.248:7000)
M: 61d94b047e12679886991c7c6d225b471374a018 10.1.112.248:7000
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: a582b9d7784d2f1b2e6a20d5352a19062dc29d4a 10.1.112.248:7002
   slots: (0 slots) slave
   replicates 0addc56bce940a659aa2ac4aa6d51677c1f2c523
M: 0addc56bce940a659aa2ac4aa6d51677c1f2c523 10.1.112.249:7000
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 087de17dafa03c361d87f7a4c4a5b2d7ce0555fc 10.1.112.249:7001
   slots: (0 slots) slave
   replicates fd9f572038a7504e088dde150b89beb2bac39e3c
M: fd9f572038a7504e088dde150b89beb2bac39e3c 10.1.112.248:7001
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 407d6ea2eb3725e142d2e5ae4e1eef4eee1a48ca 10.1.112.249:7002
   slots: (0 slots) slave
   replicates 61d94b047e12679886991c7c6d225b471374a018
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

redis集群Cluster模式如何部署

11、整體目錄結(jié)構(gòu)

[root@geb-redis1 redis-cluster]# tree
.
├── redis-4.0.11-node1
│   ├── data
│   │   ├── appendonly.aof
│   │   └── nodes-7000.conf
│   ├── logs
│   │   └── redis_7000.log
│   ├── redis_7000.pid
│   ├── redis-cli
│   ├── redis.conf
│   └── redis-server
├── redis-4.0.11-node2
│   ├── data
│   │   ├── appendonly.aof
│   │   └── nodes-7001.conf
│   ├── logs
│   │   └── redis_7001.log
│   ├── redis_7001.pid
│   ├── redis-cli
│   ├── redis.conf
│   └── redis-server
└── redis-4.0.11-node3
    ├── data
    │   ├── appendonly.aof
    │   └── nodes-7002.conf
    ├── logs
    │   └── redis_7002.log
    ├── redis_7002.pid
    ├── redis-cli
    ├── redis.conf
    └── redis-server

9 directories, 21 files

[root@geb-redis2 redis-cluster]# tree
.
├── redis-4.0.11-node1
│   ├── data
│   │   ├── appendonly.aof
│   │   └── nodes-7000.conf
│   ├── logs
│   │   └── redis_7000.log
│   ├── redis_7000.pid
│   ├── redis-cli
│   ├── redis.conf
│   └── redis-server
├── redis-4.0.11-node2
│   ├── data
│   │   ├── appendonly.aof
│   │   └── nodes-7001.conf
│   ├── logs
│   │   └── redis_7001.log
│   ├── redis_7001.pid
│   ├── redis-cli
│   ├── redis.conf
│   └── redis-server
└── redis-4.0.11-node3
    ├── data
    │   ├── appendonly.aof
    │   └── nodes-7002.conf
    ├── logs
    │   └── redis_7002.log
    ├── redis_7002.pid
    ├── redis-cli
    ├── redis.conf
    └── redis-server

9 directories, 21 files

12、部署過程中需要調(diào)整的系統(tǒng)參數(shù)

# echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
# echo "net.core.somaxconn = 2048" >> /etc/sysctl.conf
# cat /etc/rc.local
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
   echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi

關(guān)于“redis集群Cluster模式如何部署”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

本文標(biāo)題:redis集群Cluster模式如何部署
網(wǎng)頁路徑:http://bm7419.com/article38/jddgsp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計公司、靜態(tài)網(wǎng)站網(wǎng)站內(nèi)鏈、建站公司微信公眾號、小程序開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司