【Linux(CentOS7)下應用的安裝部署】:八、搭建Redis+sentinel高可用服務

Step 1:Redis的下載安裝

官網下載redis 解壓並安裝:

[root@mycomputer ~]# cd /home/

[root@mycomputer home]# wget http://download.redis.io/releases/redis-4.0.11.tar.gz

[root@mycomputer home]# tar -zxvf -C redis-4.0.11.tar.gz

[root@mycomputer home]# cd redis-4.0.11/src

[root@mycomputer src]# make

編譯中.... ....

CC setproctitle.oCC hyperloglog.oCC latency.oCC sparkline.oLINK redis-serverINSTALL redis-sentinelCC redis-cli.oLINK redis-cliCC redis-benchmark.oLINK redis-benchmarkCC redis-check-dump.oLINK redis-check-dumpCC redis-check-aof.oLINK

redis-check-aof Hint: It’s a good idea to run ‘make test’ ;)  

[root@mycomputer src]# make install

安裝中...... 完成

安裝完成,可以看到此時,src文件夾下出現了一些綠色的文件,這些文件就是我們以後需要用到的命令文件


 


Step 2:Redis 主從複製的配置

1.在 redis 目錄下創建 config 和 data 文件夾:config 用來存放 redis.conf/sentinel.conf 配置文件, data 用來存放 .log 文件和 .rdb 文件

[root@mycomputer redis-4.0.11]# mkdir config

[root@mycomputer redis-4.0.11]# mkdir data

[root@mycomputer redis-4.0.11]# cd config/

2.配置 redis master  端口 7000 : 創建 redis_7000.conf


# Redis configuration file master.

#bind 127.0.0.1

####################   端口    #############################

port 7000

####################  是否以守護進程啓動    #################

daemonize yes

####################  進程id文件   ##############

pidfile /var/run/redis_7000.pid

#######################     系統日誌   ###############

logfile "redis_7000.log"

######################   rdb數據文件    #############

dbfilename dump_7000.rdb

######################    工作目錄    ###############

dir "/home/redis-4.0.11/data"

########################  密碼 #####################

requirepass 123456

 

######################    主要是以上的配置   #################

protected-mode no

tcp-backlog 511

timeout 0

tcp-keepalive 300

supervised no

loglevel notice

databases 16

always-show-logo yes

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

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

lazyfree-lazy-eviction no

lazyfree-lazy-expire no

lazyfree-lazy-server-del no

slave-lazy-flush no

appendonly no

appendfilename "appendonly.aof"

appendfsync everysec

# appendfsync no

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

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
 

3.配置 redis slave  端口 7001/7002/7003 ...... : 創建 redis_7001.conf/redis_7002.conf/redis_7003.conf  .......


# Redis configuration file slave NO.1.

#bind 127.0.0.1

#######################  主從複製:複製127.0.0.1 的數據   端口7000

slaveof 123.45.57.14 7000

####################   端口    #############################

port 7001

####################  是否以守護進程啓動    #################

daemonize yes

####################  進程id文件   ##############

pidfile "/var/run/redis_7001.pid"

#######################     系統日誌   ###############

logfile "redis_7001.log"

######################   rdb數據文件    #############

dbfilename "dump_7001.rdb"

######################    工作目錄    ###############

dir "/home/redis-4.0.11/data"

########################  密碼 #####################

requirepass "123456"

# master 節點的密碼

masterauth "123456"

 

######################     主要是以上的  #################

protected-mode no

tcp-backlog 511

timeout 0

tcp-keepalive 300

supervised no

loglevel notice

databases 16

always-show-logo yes

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

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

lazyfree-lazy-eviction no

lazyfree-lazy-expire no

lazyfree-lazy-server-del no

slave-lazy-flush no

appendonly no

appendfilename "appendonly.aof"

appendfsync everysec

# appendfsync no

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

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
 

3.分別啓動  master/slave 的 redis 服務:

[root@mycomputer redis-4.0.11]# cd src

[root@mycomputer src]# ./redis-server /home/redis-4.0.11/config/redis_7000.conf

[root@mycomputer src]# ./redis-server /home/redis-4.0.11/config/redis_7001.conf

[root@mycomputer src]# ./redis-server /home/redis-4.0.11/config/redis_7002.conf 
 

這樣就啓動好了 redis 主從服務


 


Step 3:Sentinel 高可用配置

在 config 目錄下創建多個 sentinel.conf 文件 :sentinel_26379.conf/sentinel_26380.conf/sentinel_26381.conf ....(端口號不同就行)

port 26379

daemonize yes

dir "/home/redis-4.0.11/data"

logfile "sentinel_26379.log"

sentinel myid ac633fe2e30979a6e63e5bc26199ab2ace08f242

sentinel monitor mymaster redis服務ip 7000 2

sentinel auth-pass mymaster 123456

sentinel config-epoch mymaster 1

protected-mode no

[root@mycomputer redis-4.0.11]# cd src

[root@mycomputer src]# ./redis-sentinel /home/redis-4.0.11/config/sentinel_26379.conf

[root@mycomputer src]# ./redis-sentinel /home/redis-4.0.11/config/sentinel_26380.conf

[root@mycomputer src]# ./redis-sentinel /home/redis-4.0.11/config/sentinel_26381.conf

完成此操作即實現了 Redis sentinel 高可用

 

ps:

1. master /slave 的 redis.conf 最好配置密碼(一定要配置密碼:否則 JedisSentinelPool 報錯) 

2. master /slave 的 redis.conf 最好配置的密碼相同

3. master /slave 的 redis.conf 配置 protected-mode no(sentinel.conf 裏面同樣需要配置)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章