安裝配置
# 安裝yum install epel-release (centos 7可以直接安裝epel源)yum install redis# 配置vi /etc/redis.confvi /etc/redis-sentinel.conf# 啟動redis-server /etc/redis.confredis-sentinel /etc/redis-sentinel.conf
redis.conf常用設定
# bind 127.0.0.1protected-mode noport 6379daemonize yesmaxclients 10000requirepass <password>appendonly yes# slaveof及masterauth僅在從節點設定slaveof <masterip> <masterport>masterauth <master-password>
redis-sentinel.conf常用設定
protected-mode nodaemonize yesport 26397sentinel monitor <master-name> <ip> <redis-port> <quorum>sentinel auth-pass <master-name> <password>
開機自啟
# 編輯vi /etc/init.d/redisd# 賦權chmod 755 /etc/init.d/redisd# 嘗試/etc/init.d/redisd startservice redisd start/stop/restart# 自啟chkconfig redisd on
redisd樣本
#!/bin/sh# chkconfig: 2345 90 10 # description: Redis is a persistent key-value database# Simple Redis init.d script conceived to work on Linux systems# as it does use of the /proc filesystem.REDISPORT=6379REDISPWD='123456'EXEC=/usr/local/bin/redis-serverCLIEXEC=/usr/local/bin/redis-cliPIDFILE=/var/run/redis_${REDISPORT}.pidCONF="/etc/redis/${REDISPORT}.conf"case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." $EXEC $CONF fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $CLIEXEC -p $REDISPORT -a $REDISPWD shutdown while [ -x /proc/${PID} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; restart|force-reload) ${0} stop ${0} start ;; *) echo "Please use start|stop|restart|force-reload as first argument" ;;esac
redis-sentineld樣本
#!/bin/sh# chkconfig: 2345 90 10 # description: Redis SentinelREDISPORT=26379EXEC=/usr/bin/redis-sentinelCLIEXEC=/usr/bin/redis-cliCONF="/etc/redis-sentinel.conf"NAME="Redis Sentinel"PID=$(netstat -lnopt | grep :$REDISPORT | awk '/redis-sentine/{gsub(/\/redis-sentine/,"",$7);print $7;}' | head -1)case "$1" in start) if [ -z ${PID} ] then echo "Starting $NAME server..." $EXEC $CONFecho "start at port:$REDISPORT" elseecho "$NAME server already start,pid:$PID" fi ;; stop) if [ -z ${PID} ] thenecho "not find $NAME server on port:$REDISPORT" else echo "Stopping ..." $CLIEXEC -p $REDISPORT shutdown while [ -z ${PID} ] do echo "Waiting for $NAME server to shutdown ..." sleep 1 done echo "$NAME server stopped" fi ;; status) if [ -z ${PID} ] then echo "not find $NAME server on port:$REDISPORT" else echo "$NAME server is running,pid:$PID" fi ;; restart) ${0} stop ${0} start ;; *) echo "Please use start|stop|restart|status as first argument" ;;esac