CentOS 7.3 Sentinel实现Redis集群高可用部署

三台机器:
10.149.151.81    master/Sentinel
10.149.151.82    slave1/Sentinel
10.149.151.83    slave2/Sentinel
一、初始化系统环境(三台均需操作)
echo "vm.overcommit_memory = 1"  >> /etc/sysctl.conf
sysctl -p
echo 1024 > /proc/sys/net/core/somaxconn
mkdir /data/redis/logs/ -p
mkdir /data/redis/rdb/ -p

二、redis的安装和配置文件统一修改
1.安装:
cd /usr/src/
wget http://download.redis.io/releases/redis-3.2.6.tar.gz
tar zxf redis-3.2.6.tar.gz
cd redis-3.2.6
make
make PREFIX=/usr/local/redis install
cat < /etc/profile.d/redis.sh
export PATH=$PATH:/usr/local/redis/bin/
EOF
source /etc/profile.d/redis.sh
cp redis.conf /etc/
cp sentinel.conf /etc/
2.节点10.149.151.81
配置redis.conf
#bind 127.0.0.1
bind 127.0.0.1 10.149.151.81
protected-mode yes
port 6379
#tcp-backlog 511
tcp-backlog 1024
timeout 0
tcp-keepalive 300
#daemonize no
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "/data/redis/logs/redis.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
dbfilename redis_dump.rdb
masterauth "123456aa"
#dir ./
dir "/data/redis/rdb/"
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 "123456aa"
appendonly no
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-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
######################################
2.节点10.149.151.82
配置redis.conf
bind 127.0.0.1 10.149.151.82
protected-mode yes
port 6379
tcp-backlog 1024
timeout 0
tcp-keepalive 300
daemonize no
#daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "/data/redis/logs/redis.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
dbfilename redis_dump.rdb
masterauth "123456aa"
#dir ./
dir "/data/redis/rdb/"
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
requirepass "123456aa"
appendonly no
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-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
slaveof 10.149.151.81 6379
######################################
2.节点10.149.151.83
配置redis.conf
bind 127.0.0.1 10.149.151.83
protected-mode yes
port 6379
tcp-backlog 1024
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "/data/redis/logs/redis.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename redis_dump.rdb
masterauth "123456aa"
dir "/data/redis/rdb/"
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 95
requirepass "123456aa"
appendonly no
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-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
slaveof 10.149.151.81 6379
################################
3.三台机器配置sentinel.conf
port 26379
daemonize yes
protected-mode no
dir "/data/redis/logs"
logfile "sentinel.log"

sentinel monitor mymaster 10.149.151.81 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 15000
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster 123456aa
#####################################
4.启动redis,sentinel
master启动redis:
redis-server /etc/redis.conf &
三台均启动sentinel:
redis-sentinel /etc/sentinel.conf &
slave依次启动redis:
redis-server /etc/redis.conf &
5.验证:
连接:
redis-cli -h 10.149.151.81 -a 123456aa
查看信息:
info Replication
6.附命令:
停止redis:
redis-cli -h 10.149.151.81 -a 123456aa shutdown


你可能感兴趣的:(linux,shell,redis)