Redis-Server 监控机安装
一、安装redis
此过程请参考 这里
复制可执行文件
12sudo cp /usr/local/redis/src/redis-server /usr/local/binsudo cp /usr/local/redis/src/redis-cli /usr/local/bin创建
redis-monitor
的软链12cd /usr/local/binsudo ln -s /usr/local/bin/redis-server redis-monitor
二、配置监控
创建
redis
目录12sudo mkdir /etc/redissudo mkdir /etc/log/redis赋予
redis
目录权限12sudo chown -R admin:admin /etc/redissudo chown -R admin:admin /etc/log/redis创建监控配置文件
sentinel.conf
1touch /etc/redis/sentinel.conf修改
sentinel.conf
增加portal-session
、portal-site
配置段1234567891011121314151617181920212223# 监控端口port 26379# 集群master端口及地址,名称支持 A-z 0-9 特殊字符可包含 ".-_"sentinel monitor portal-site 172.17.121.33 1221 1sentinel monitor portal-session 172.17.121.33 6379 1# Master宕机后 N 秒内由slave接替其工作,单位:毫秒sentinel down-after-milliseconds portal-site 30000sentinel down-after-milliseconds portal-session 30000# 设置是否可以由监控发起自动切换sentinel can-failover portal-site yessentinel can-failover portal-session yes# 设置当master宕机后由 N 个slave同步提供服务# 如果仅使用redis供查询使用,请尽量设置一个较低的值以避免同步锁问题sentinel parallel-syncs portal-site 1sentinel parallel-syncs portal-session 1# Default is 15 minutes.sentinel failover-timeout portal-site 900000sentinel failover-timeout portal-session 900000创建服务启动脚本
1sudo touch /etc/init.d/redis-monitor修改
redis-monitor
脚本内容123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596#!/bin/sh## 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: /etc/redis/sentinel.conf# pidfile: /var/run/sentinel.pid# lockfile: /var/lcok/sentinel# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ "$NETWORKING" = "no" ] && exit 0# define the exec progromREDIS_EXEC="/usr/local/bin/redis-monitor"REDIS_CONF_FILE="/etc/redis/sentinel.conf"PROG=$(basename $REDIS_EXEC)# if /etc/sysconfig/redis exists,use this config env[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redisLOCKFILE=/var/lock/redis/sentinelstart() {[ -x $REDIS_EXEC ] || exit 5[ -f $REDIS_CONF_FILE ] || exit 6echo -n $"Starting $PROG: "nohup $REDIS_EXEC /etc/redis/sentinel.conf --sentinel > /var/log/redis/monitor.log 2>&1 &echo [ OK ] && touch $LOCKFILEreturn}stop() {pid=`ps -ef|grep $REDIS_EXEC|grep -v grep|awk '{print $2}'`if [ ! $pid ]; thenecho $"$PROG is stoped"elseecho -n $"Stopping $PROG: "kill -9 $pidecho [ OK ] && rm -f $LOCKFILEfireturn}rh_status() {status $PROG}rh_status_q() {rh_status >/dev/null 2>&1}restart() {stopstart}exit_a(){echo $"$PROG is running"exit 0}exit_b(){echo $"$PROG is stopped"exit 0}case "$1" instart)rh_status_q && exit_a$1;;stop)rh_status_q || exit_b$1;;restart|configtest)$1;;status)rh_status;;*)echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"exit 2esac赋予此脚本可执行权限
1sudo chmod u+x redis-monitor添加系统启动服务
12sudo chkconfig --add redis-monitorsudo chkconfig --level 345 redis-monitor on启动服务
1sudo service redis-monitor start验证服务正确启动