内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

3臺(tái)服務(wù)器Redis高可用哨兵模式

建站服務(wù)器 3臺(tái)服務(wù)器Redis高可用哨兵模式

學(xué)習(xí)redis高可用

創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的浦江網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

3臺(tái)服務(wù)器Redis高可用哨兵模式

3.1 主redis配置

3.2 從redis配置

1. 介紹

2. redis程序安裝

3. 哨兵模式配置

3.3 啟動(dòng)redis和哨兵

4. 總結(jié)

1. 介紹

Redis Sentinel 是一個(gè)分布式系統(tǒng), 你可以在一個(gè)架構(gòu)中運(yùn)行多個(gè) Sentinel 進(jìn)程(progress), 這些進(jìn)程使用流言協(xié)議(gossip protocols)來接收關(guān)于主服務(wù)器是否下線的信息, 并使用投票協(xié)議(agreement protocols)來決定是否執(zhí)行自動(dòng)故障遷移, 以及選擇哪個(gè)從服務(wù)器作為新的主服務(wù)器。
雖然 Redis Sentinel 釋出為一個(gè)單獨(dú)的可執(zhí)行文件 redis-sentinel , 但實(shí)際上它只是一個(gè)運(yùn)行在特殊模式下的 Redis 服務(wù)器, 你可以在啟動(dòng)一個(gè)普通 Redis 服務(wù)器時(shí)通過給定 –sentinel 選項(xiàng)來啟動(dòng) Redis Sentinel 。

CentOS7.2
redis3.2.8

服務(wù)器IPredis端口哨兵端口服務(wù)器角色10.1.0.160637926379主10.1.0.161637926379從110.1.0.71637926379從22. redis程序安裝

cat install_redis.sh

#!/usr/bin/env bash
# It\'s Used to be install redis.
# Created on 2016/10/19 11:18.
# @author: Chinge_Yang.
# Version: 1.0

function install_redis () {
#################################################################################################
sourcepackage_dir=/tmp
redis_install_dir=/usr/local/redis
cd ${sourcepackage_dir}
if [ ! -f redis-stable.tar.gz ]; then
wget http://download.redis.io/releases/redis-stable.tar.gz
fi
cd ${makework_dir}
tar -zxvf ${sourcepackage_dir}/redis-stable.tar.gz
cd redis-stable
make PREFIX=/usr/local/redis install
return_echo make
mkdir -p /usr/local/redis/{etc,var}
rsync -avz redis.conf /usr/local/redis/etc/
sed -i \'s@pidfile.*@pidfile /var/run/redis-server.pid@\' $redis_install_dir/etc/redis.conf
sed -i s@logfile.*@logfile $redis_install_dir/var/redis.log@ $redis_install_dir/etc/redis.conf
sed -i s@^dir.*@dir $redis_install_dir/var@ $redis_install_dir/etc/redis.conf
sed -i \'s/daemonize no/daemonize yes/g\' /usr/local/redis/etc/redis.conf
sed -i \'s/^# bind 127.0.0.1/bind 127.0.0.1/g\' /usr/local/redis/etc/redis.conf
rsync -avz ${sourcepackage_dir}/init.d/redis-server /etc/init.d/
/etc/init.d/redis-server start
chkconfig --add redis-server
chkconfig redis-server on
#################################################################################################
}

install_redis

cat redis-server

#!/bin/bash 
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /usr/local/redis/etc/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /usr/local/redis/var/redis-server.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ $NETWORKING = no ] && exit 0

redis=/usr/local/redis/bin/redis-server
prog=$(basename $redis)

REDIS_CONF_FILE=/usr/local/redis/etc/redis.conf

[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis

lockfile=/var/lock/subsys/redis-server

start() {
[ -x $redis ] || exit 5
[ -f $REDIS_CONF_FILE ] || exit 6
echo -n $Starting $prog:
daemon $redis $REDIS_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}

stop() {
echo -n $Stopping $prog:
killproc $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}

restart() {
stop
start
}

reload() {
echo -n $Reloading $prog:
killproc $redis -HUP
RETVAL=$?
echo
}

force_reload() {
restart
}

rh_status() {
status $prog
}

rh_status_q() {
rh_status >/dev/null 2>&1
}

case $1 in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}
exit 2
esac

#!/bin/bash 
#
# redis-sentinel - this script starts and stops the redis-server sentinel daemon
#
# chkconfig: - 85 15
# description: Redis sentinel
# processname: redis-server
# config: /usr/local/redis/etc/sentinel.conf
# config: /etc/sysconfig/redis
# pidfile: /usr/local/redis/var/redis-sentinel.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ $NETWORKING = no ] && exit 0

redis=/usr/local/redis/bin/redis-sentinel
prog=$(basename $redis)

REDIS_CONF_FILE=/usr/local/redis/etc/sentinel.conf

[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis

lockfile=/var/lock/subsys/redis-sentinel

start() {
[ -x $redis ] || exit 5
[ -f $REDIS_CONF_FILE ] || exit 6
echo -n $Starting $prog:
daemon $redis $REDIS_CONF_FILE --sentinel
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}

stop() {
echo -n $Stopping $prog:
killproc $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}

restart() {
stop
start
}

reload() {
echo -n $Reloading $prog:
killproc $redis -HUP
RETVAL=$?
echo
}

force_reload() {
restart
}

rh_status() {
status $prog
}

rh_status_q() {
rh_status >/dev/null 2>&1
}

case $1 in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}
exit 2
esac
3. 哨兵模式配置

按照前面單redis安裝方法安裝程序;

創(chuàng)建相應(yīng)數(shù)據(jù)目錄;

mkdir -p /usr/local/redis/data/redis
mkdir -p /usr/local/redis/data/sentinel
mkdir -p /usr/local/redis/sbin
vim /usr/local/redis/sbin/redis-server # 使用上文中的示例腳本
vim /usr/local/redis/sbin/redis-sentinel # 使用上文中的示例腳本
3.1 主redis配置

vim redis.conf

daemonize yes
pidfile /usr/local/redis/var/redis-server.pid
port 6379
tcp-backlog 128
timeout 0
tcp-keepalive 0
loglevel notice
logfile /usr/local/redis/var/redis-server.log
databases 16
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/data/redis
masterauth 20170310
requirepass 20170310
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
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
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-entries 512
list-max-ziplist-value 64
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

群集文件配置
vim sentinel.conf

port 26379
pidfile /usr/local/redis/var/redis-sentinel.pid
dir /usr/local/redis/data/sentinel
daemonize yes
logfile /usr/local/redis/var/redis-sentinel.log
sentinel monitor mymaster 10.1.0.160 6379 2
sentinel parallel-syncs mymaster 2
sentinel auth-pass mymaster 20170310
3.2 從redis配置

slaveof 10.1.0.160 6379

vim redis.conf

daemonize yes
pidfile /usr/local/redis/var/redis-server.pid
port 6379
tcp-backlog 128
timeout 0
tcp-keepalive 0
loglevel notice
logfile /usr/local/redis/var/redis-server.log
databases 16
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/data/redis
masterauth 20170310
requirepass 20170310
slaveof 10.1.0.160 6379
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 90
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
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-entries 512
list-max-ziplist-value 64
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

port 26379
pidfile /usr/local/redis/var/redis-sentinel.pid
dir /usr/local/redis/data/sentinel
daemonize yes
logfile /usr/local/redis/var/redis-sentinel.log
sentinel monitor mymaster 10.1.0.160 6379 2
sentinel config-epoch mymaster 0
3.3 啟動(dòng)redis和哨兵

/usr/local/redis/sbin/redis-server start
啟動(dòng)群集監(jiān)控,主從都要啟動(dòng)
/usr/local/redis/sbin/redis-sentinel start

錯(cuò)誤1:
WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add \'vm.overcommit_memory = 1\' to /etc/sysctl.conf and then reboot or run the command \'sysctl vm.overcommit_memory=1\' for this to take effect.

解決方法(overcommit_memory)
1. `vim /etc/sysctl.conf`添加如下設(shè)置 , 然后`sysctl -p`
vm.overcommit_memory = 1
可選值:0、1、2。

0, 表示內(nèi)核將檢查是否有足夠的可用內(nèi)存供應(yīng)用進(jìn)程使用;如果有足夠的可用內(nèi)存,內(nèi)存申請(qǐng)?jiān)试S;否則,內(nèi)存申請(qǐng)失敗,并把錯(cuò)誤返回給應(yīng)用進(jìn)程。
1, 表示內(nèi)核允許分配所有的物理內(nèi)存,而不管當(dāng)前的內(nèi)存狀態(tài)如何。
2, 表示內(nèi)核允許分配超過所有物理內(nèi)存和交換空間總和的內(nèi)存

注意:redis在dump數(shù)據(jù)的時(shí)候,會(huì)fork出一個(gè)子進(jìn)程,理論上child進(jìn)程所占用的內(nèi)存和parent是一樣的,比如parent占用 的內(nèi)存為8G,這個(gè)時(shí)候也要同樣分配8G的內(nèi)存給child,如果內(nèi)存無法負(fù)擔(dān),往往會(huì)造成redis服務(wù)器的down機(jī)或者IO負(fù)載過高,效率下降。所 以這里比較優(yōu)化的內(nèi)存分配策略應(yīng)該設(shè)置為 1(表示內(nèi)核允許分配所有的物理內(nèi)存,而不管當(dāng)前的內(nèi)存狀態(tài)如何)。
這里又涉及到Overcommit和OOM。

什么是Overcommit和OOM?
在Unix中,當(dāng)一個(gè)用戶進(jìn)程使用malloc()函數(shù)申請(qǐng)內(nèi)存時(shí),假如返回值是NULL,則這個(gè)進(jìn)程知道當(dāng)前沒有可用內(nèi)存空間,就會(huì)做相應(yīng)的處理工作。許多進(jìn)程會(huì)打印錯(cuò)誤信息并退出。
Linux使用另外一種處理方式,它對(duì)大部分申請(qǐng)內(nèi)存的請(qǐng)求都回復(fù)yes,以便能跑更多更大的程序。因?yàn)樯暾?qǐng)內(nèi)存后,并不會(huì)馬上使用內(nèi)存。這種技術(shù)叫做Overcommit。
當(dāng)內(nèi)存不足時(shí),會(huì)發(fā)生OOM killer(OOM=out-of-memory)。它會(huì)選擇殺死一些進(jìn)程(用戶態(tài)進(jìn)程,不是內(nèi)核線程),以便釋放內(nèi)存。

Overcommit的策略
Linux下overcommit有三種策略(Documentation/vm/overcommit-accounting):
0. 啟發(fā)式策略。合理的overcommit會(huì)被接受,不合理的overcommit會(huì)被拒絕。
1. 任何overcommit都會(huì)被接受。
2. 當(dāng)系統(tǒng)分配的內(nèi)存超過swap+N%*物理RAM(N%由vm.overcommit_ratio決定)時(shí),會(huì)拒絕commit。
overcommit的策略通過vm.overcommit_memory設(shè)置。
overcommit的百分比由vm.overcommit_ratio設(shè)置。

# echo 2 > /proc/sys/vm/overcommit_memory
# echo 80 > /proc/sys/vm/overcommit_ratio

當(dāng)oom-killer發(fā)生時(shí),linux會(huì)選擇殺死哪些進(jìn)程
選擇進(jìn)程的函數(shù)是oom_badness函數(shù)(在mm/oom_kill.c中),該函數(shù)會(huì)計(jì)算每個(gè)進(jìn)程的點(diǎn)數(shù)(0~1000)。
點(diǎn)數(shù)越高,這個(gè)進(jìn)程越有可能被殺死。
每個(gè)進(jìn)程的點(diǎn)數(shù)跟oom_score_adj有關(guān),而且oom_score_adj可以被設(shè)置(-1000低,1000高)。

錯(cuò)誤2:
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

echo 511 > /proc/sys/net/core/somaxconn

錯(cuò)誤3:
16433:X 12 Jun 14:52:37.734 * Increased maximum number of open files to 10032 (it was originally set to 1024).

新裝的linux默認(rèn)只有1024,當(dāng)負(fù)載較大時(shí),會(huì)經(jīng)常出現(xiàn)error: too many open files

ulimit -a:使用可以查看當(dāng)前系統(tǒng)的所有限制值

vim /etc/security/limits.conf
在文件的末尾加上

* soft nofile 65535
* hard nofile 65535

執(zhí)行su或者重新關(guān)閉連接用戶再執(zhí)行ulimit -a就可以查看修改后的結(jié)果。

啟動(dòng)群集之后,群集程序默認(rèn)會(huì)在主從的sentinel.conf文件中加入群集信息

port 26379
pidfile /usr/local/redis/var/redis-sentinel.pid
dir /usr/local/redis/data/sentinel
daemonize yes
logfile /usr/local/redis/var/redis-sentinel.log
sentinel myid aeff525d03a2234ef834808f7991761db03a1973
sentinel monitor mymaster 10.1.0.160 6379 2
sentinel parallel-syncs mymaster 2
sentinel auth-pass mymaster 20170310
# Generated by CONFIG REWRITE
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 10.1.0.71 6379
sentinel known-slave mymaster 10.1.0.161 6379
sentinel current-epoch 0

port 26379
pidfile /usr/local/redis/var/redis-sentinel.pid
dir /usr/local/redis/data/sentinel
daemonize yes
logfile /usr/local/redis/var/redis-sentinel.log
sentinel myid 01b1b7674abe648f6a2344fc5610e73b7e87cb8a
sentinel monitor mymaster 10.1.0.160 6379 2
sentinel config-epoch mymaster 0
# Generated by CONFIG REWRITE
sentinel leader-epoch mymaster 0
sentinel current-epoch 0

port 26379
pidfile /usr/local/redis/var/redis-sentinel.pid
dir /usr/local/redis/data/sentinel
daemonize yes
logfile /usr/local/redis/var/redis-sentinel.log
sentinel myid f1589f48079b3b3b536add4e2e01a36304aeba8c
sentinel monitor mymaster 10.1.0.160 6379 2
sentinel config-epoch mymaster 0
# Generated by CONFIG REWRITE
sentinel leader-epoch mymaster 0
sentinel current-epoch 0

[root@show160 redis]# /usr/local/redis/bin/redis-cli -p 6379
127.0.0.1:6379> AUTH 20170310
OK
127.0.0.1:6379> DEBUG SEGFAULT
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> quit

4. 總結(jié)

https://redis.io/topics/sentinel
http://www.redis.cn/topics/sentinel.html
http://www.majunwei.com/view/201610302123020678.html

名稱欄目:3臺(tái)服務(wù)器Redis高可用哨兵模式
瀏覽路徑:http://www.rwnh.cn/article40/cggpho.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、自適應(yīng)網(wǎng)站、用戶體驗(yàn)微信公眾號(hào)、品牌網(wǎng)站制作、靜態(tài)網(wǎng)站

廣告

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

措美县| 延安市| 栾川县| 武夷山市| 建湖县| 建湖县| 双流县| 无棣县| 德庆县| 凤山县| 得荣县| 晴隆县| 塘沽区| 右玉县| 宜宾市| 南江县| 土默特右旗| 公主岭市| 西昌市| 张家口市| 鄯善县| 合山市| 盈江县| 广丰县| 益阳市| 财经| 托克托县| 柳江县| 凤山县| 抚顺县| 大埔县| 九龙县| 敦化市| 舟山市| 乌苏市| 肃北| 永吉县| 建平县| 高安市| 青浦区| 阿克陶县|