CentOS系統redis主從模式實現

來源:互聯網
上載者:User

安裝配置

# 安裝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


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.