-
yum install gcc gcc-c++ automake autoconf libtool make -y
-
下载redis
wget https://download.redis.io/releases/redis-4.0.14.tar.gz
-
解压redis
tar -zxvg redis-4.0.14.tar.gz
-
进入redis目录编译并安装
cd /data/redis-4.0.14
make && make install -
修改redis配置文件
daemonize yes
#pidfile "/home/redis/redis/redisRun/redis_6379.pid"
port 6379
timeout 0
tcp-keepalive 0
loglevel notice
logfile "/var/log/redis/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"
#dir "/home/redis/redisdb"
#主节点密码
masterauth "Pw!123456"
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 102
requirepass "Pw!123456"
appendonly yes
# appendfsync always
appendfsync everysec
# 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
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
activerehashing yes -
配置redis自启服务文件
vi /etc/systemd/system/redis.service
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/data/redis-4.0.14/bin/redis-server /data/redis-4.0.14/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.targe -
设置redis开机自启
重载配置:systemctl daemon-reload
启动服务:systemctl start redis.service
添加开机自启:systemctl enable redis.service
查看服务状态1):systemctl status redis.service
查看服务状态2):ps -ef|grep redis -
开放端口限制
firewall-cmd --zone=public --add-port=6379/tcp --permanent
生效配置:firewall-cmd --reload -
其他2台从机器以上步骤一致
-
修改哨兵配置文件(sentinel.conf)
port 26379
bind 0.0.0.0
daemonize yes
sentinel myid 533c6dcc3deb4975df2813da6bb5e7e4c6dcb6d3
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster 192.168.0.103 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
logfile "/var/log/redis/sentinel.log"
# Generated by CONFIG REWRITE
dir "/data/redis-4.0.14"
sentinel auth-pass mymaster Pw!123456
sentinel config-epoch mymaster 4
sentinel leader-epoch mymaster 3
sentinel known-slave mymaster 192.168.0.104 6379
sentinel known-slave mymaster 192.168.0.102 6379
sentinel known-sentinel mymaster 192.168.0.104 26379 0339c0dc9ae30bb0fde907f67ce707d602fdc97f
sentinel known-sentinel mymaster 192.168.0.103 26379 ee5430bb33d99dc23598320a07e94e8658a8f6a4
sentinel current-epoch 4 -
开放哨兵端口限制
firewall-cmd --zone=public --add-port=26379/tcp --permanent
生效配置:firewall-cmd --reload -
配置哨兵自启
vi /etc/systemd/system/redis-sentinel.service
[Unit]
Description=redis-sentinel-server
After=redis-server
[Service]
Type=forking
ExecStart=/data/redis-4.0.14/bin/redis-server /data/redis-4.0.14/sentinel.conf --sentinel
PrivateTmp=true
[Install]
WantedBy=multi-user.target -
设置redis-sentinel开机自启
重载配置:systemctl daemon-reload
启动服务:systemctl start redis-sentinel.service
添加开机自启:systemctl enable redis-sentinel.service
查看服务状态1):systemctl status redis-sentinel.service
查看服务状态2):ps -ef|grep redis -
启动redis和哨兵
任意一台机器
redis-cli -p 6379
auth redis密码
info #查看信息 是否是主从模式
宕机master后是否重新选举master -