Last active
November 16, 2017 02:27
-
-
Save yangl/96aa60969634a40063c1e365d8bce0d9 to your computer and use it in GitHub Desktop.
Redis服务端配置、jedis连接池配置模板 rdb定时同步脚本----主要防止主从切换失败时手动启动Master或误重启导致数据丢失 详见:http://tech.lede.com/2017/11/14/rd/server/redistemplate/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> | |
<property name="maxIdle" value="30" /> //JedisPool最大空闲连接数 | |
<property name="minIdle" value="10" /> //JedisPool最小空闲连接数,也即初始化连接数 | |
<property name="testOnBorrow" value="false" /> //从JedisPool获取jedis实例时检查连接的有效性,默认是false | |
<property name="testWhileIdle" value="false" /> //表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,此object会被从pool中drop掉 | |
<property name="testOnReturn" value="true" /> //将jedis实例归还连接池时检查连接的有效性,默认是false ;test开启太多会影响性能,都不开启异常连接可能会被使用,建议至少开启一个 | |
<property name="maxTotal" value="300"/> //JedisPool最大连接数 | |
<property name="maxWaitMillis" value="4000"/> //从JedisPool获取连接等待毫秒数,超时则抛异常;若blockWhenExhausted为false,该配置项无效 | |
<property name="blockWhenExhausted" value="false"/> //blockWhenExhausted 表示连接耗尽时是否阻塞, false报异常,ture阻塞maxWaitMillis直到超时 ;不配默认是true;建议配置为false | |
</bean> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
project=$1 | |
backup_dir="/home/redisInstance/$project/data/rdb_bak/" | |
if [ ! -d "$backup_dir" ]; then | |
mkdir -p "$backup_dir" | |
fi | |
list=`ls /home/redisInstance/$project/data/rdb_bak/ | wc -l ` | |
echo "[$(date +%Y%m%d-%H:%M:%S)] the backup files number is $list" | |
result=$(find "$backup_dir" -amin +60 -name dump.rdb.* -print) | |
if [ $list -gt 13 ] | |
then | |
if [ x"$result" = x ] | |
then | |
echo "[$(date +%Y%m%d-%H:%M:%S)] no backup files found to delete!" | |
else | |
echo -e "[$(date +%Y%m%d-%H:%M:%S)] backup files found to delete : \"$result\" !" | |
fi | |
find "$backup_dir" -amin +60 -name "dump.rdb.*" -exec rm -rf {} \; | |
else | |
echo "[$(date +%Y%m%d-%H:%M:%S)] the backup files number is less than 13, no files allowed to delete" | |
fi | |
backuptime=$(date +%Y%m%d%H%M) | |
eval rsync -a /home/redisInstance/"$project"/data/dump.rdb "$backup_dir"dump.rdb."$backuptime" | |
cp "$backup_dir"dump.rdb."$backuptime" "$backup_dir"dump.rdb | |
if [ $? -eq 0 ] | |
then | |
echo "[$(date +%Y%m%d-%H:%M:%S)] the rdb file backup to local dir (rdb_bak) is OK" | |
else | |
echo "[$(date +%Y%m%d-%H:%M:%S)] the rdb file backup to local dir (rdb_bak) is error" | |
fi | |
rsynctime=$(date -d "-5 min" +%Y%m%d%H%M) | |
eval rsync -avzP /home/redisInstance/"$project"/data/rdb_bak/dump.rdb [email protected]::"$project" --password-file=/etc/rsyncd.secrets | |
if [ $? -eq 0 ] | |
then | |
echo "[$(date +%Y%m%d-%H:%M:%S)] the rdb file backup to remote host(10.120.117.165) dir (data) is OK" | |
else | |
echo "[$(date +%Y%m%d-%H:%M:%S)] the rdb file backup to remote host(10.120.117.165) dir (data) is error" | |
fi | |
rm -rf "$backup_dir"dump.rdb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
port {port} | |
daemonize yes | |
pidfile /{HOME}/log/redis.pid | |
logfile /{HOME}/log/redis.log | |
dir /{HOME}/data | |
dbfilename dump.rdb | |
requirepass {password} | |
masterauth {password} | |
timeout 0 | |
loglevel notice | |
databases 16 | |
rdbcompression yes | |
maxclients 10000 | |
maxmemory {maxmemory} | |
maxmemory-policy noeviction | |
save 900 1 | |
save 300 10 | |
save 60 300 | |
appendonly no | |
appendfsync everysec | |
no-appendfsync-on-rewrite yes | |
auto-aof-rewrite-percentage 100 | |
auto-aof-rewrite-min-size 64mb | |
slowlog-log-slower-than 50000 | |
slowlog-max-len 1024 | |
client-output-buffer-limit normal 10mb 5mb 10 | |
client-output-buffer-limit slave 1024mb 256mb 300 | |
client-output-buffer-limit pubsub 32mb 8mb 60 | |
lua-time-limit 1000 | |
#slave 打开 | |
#slaveof {ip address} {port} | |
rename-command FLUSHALL SUPER_FLUSHALL | |
rename-command FLUSHDB SUPER_FLUSHDB | |
rename-command SHUTDOWN SUPER_SHUTDOWN | |
rename-command KEYS SUPER_KEYS | |
rename-command MONITOR SUPER_MONITOR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
port {port} | |
daemonize yes | |
pidfile “/{HOME}/log/sentinel.pid” | |
logfile “/{HOME}/log/sentinel.log” | |
sentinel monitor master {ip address} {port} {quorum} /当哨兵数为3的时候,quorum需配置为2,哨兵数为5的时候,quorum需配置为3/ | |
sentinel down-after-milliseconds master 60000 /哨兵与master失连1分钟则主观下线/ | |
sentinel failover-timeout master 180000 | |
sentinel config-epoch master 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment