系统部署之redis集群安装(sentinel)

系统部署之redis集群安装(sentinel)

安装文件

  • redis-3.2.9.tar.gz

编译安装

  1. yum install gcc
  2. make CFLAGS="-march=x86-64"
  3. make install PREFIX=/usr/local/redis
  4. mkdir /usr/local/redis/etc

创建用户

  1. groupadd redis
  2. useradd -g redis -d /var/lib/redis -s /sbin/nologin redis
  3. mkdir -p /var/lib/redis/{logs,data,sentinel_26379}
  4. chown -R redis:redis /var/lib/redis
  5. chown -R redis:redis /usr/local/redis/etc/

创建配置

master配置

/usr/local/redis/etc/redis.conf

daemonize yes
pidfile /var/lib/redis/logs/redis.pid
port 6379
timeout 0
loglevel notice
logfile /var/lib/redis/logs/redis.log
databases 16
save 60 100000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/log/redis/data
slave-serve-stale-data yes
slave-read-only yes
slave-priority 100
appendonly no
appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
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
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
min-slaves-to-write 1
min-slaves-max-lag 10
masterauth 123456
requirepass 123456
/usr/local/redis/etc/sentinel_26379.conf

port 26379
dir "/var/lib/redis/sentinel_26379"
logfile "/var/log/redis/logs/sentinel_26379.log"
daemonize yes
protected-mode no
sentinel monitor 51master 主IP 主端口 2
sentinel down-after-milliseconds 51master 5000
sentinel failover-timeout 51master 120000
sentinel auth-pass 51master 123456

slave配置

/usr/local/redis/etc/redis.conf

daemonize yes
pidfile /var/lib/redis/logs/redis.pid
port 6379
timeout 0
loglevel notice
logfile /var/lib/redis/logs/redis.log
databases 16
save 60 100000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis/data
slave-serve-stale-data yes
slave-read-only yes
slave-priority 100
appendonly no
appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
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
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
min-slaves-to-write 1
min-slaves-max-lag 10
masterauth 123456
requirepass 123456
slaveof 主IP 端口
/usr/local/redis/etc/sentinel_26379.conf

port 26379
dir "/var/lib/redis/sentinel_26379"
logfile "/var/log/redis/logs/sentinel_26379.log"
daemonize yes
protected-mode no
sentinel monitor 51master 主IP 主端口 2
sentinel down-after-milliseconds 51master 5000
sentinel failover-timeout 51master 120000
sentinel auth-pass 51master 123456

slave2配置

同slave1配置

系统服务(3台相同)

sentinel

/lib/systemd/system/redis_26379.service
 
[Unit]
Description=redis-sentinel
After=network.target,redis.target

[Service]
Type=forking
User=redis
ExecStart=/usr/local/redis/bin/redis-sentinel /usr/local/redis/etc/sentinel_26379.conf
Restart=on-failure

[Install]
WantedBy=multi-user.target

redis

/lib/systemd/system/redis.service

[Unit]
Description=redis
After=network.target

[Service]
Type=forking
User=redis
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
Restart=on-failure

[Install]
WantedBy=multi-user.target

标签: none

添加新评论