CentOS system Redis Master-Slave mode implementation

Source: Internet
Author: User
Tags sleep install redis redis server

Installation configuration

# install
yum install Epel-release (CentOS 7 can directly install Epel source)
Yum install Redis

# configuration
vi/etc/redis.conf
VI/ etc/redis-sentinel.conf

# start
redis-server/etc/redis.conf
redis-sentinel/etc/redis-sentinel.conf

redis.conf Common Settings

# bind 127.0.0.1
protected-mode no
port 6379
daemonize Yes
maxclients 10000 Requirepass
< password>
appendonly Yes
# slaveof and Masterauth only set
slaveof <masterip> <masterport> from node
Masterauth <master-password>

redis-sentinel.conf Common Settings

Protected-mode no
daemonize Yes
port 26397
Sentinel Monitor <master-name> <ip> < redis-port> <quorum>
Sentinel Auth-pass <master-name> <password>

Power-on Self-starter

# edit
VI/ETC/INIT.D/REDISD
# empower
chmod 755/ETC/INIT.D/REDISD
# try
/ETC/INIT.D/REDISD start
Service REDISD Start/stop/restart
# self-starter
chkconfig REDISD on

REDISD sample

#!/bin/sh # chkconfig:2345 Description:redis is a persistent key-value database # simple Redis INIT.D Script Co

Nceived to work on Linux systems # as it does the use of The/proc filesystem. redisport=6379 redispwd= ' 123456 ' exec=/usr/local/bin/redis-server cliexec=/usr/local/bin/redis-cli PIDFILE=/var/
        Run/redis_${redisport}.pid conf= "/etc/redis/${redisport}.conf" case "' in Start ' if [-f $PIDFILE] Then echo "$PIDFILE exists, process is already running or crashed" else echo "Sta
    Rting Redis server ... "$EXEC $CONF fi;;
        STOP) if [! f $PIDFILE] then echo "$PIDFILE does not exist, process isn't running" Else pid=$ (cat $PIDFILE) echo "Stopping ..." $CLIEXEC-P $REDISPORT- A $REDISPWD shutdown while [-x/proc/${pid}] doing echo waiting for Re DiS 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 a argument";; Esac


Redis-sentineld sample

#!/bin/sh # chkconfig:2345 Description:redis Sentinel redisport=26379 exec=/usr/bin/redis-sentinel CLIEXEC=/us R/BIN/REDIS-CLI conf= "/etc/redis-sentinel.conf" name= "Redis Sentinel" pid=$ (netstat-lnopt | grep: $REDISPORT | awk '/re Dis-sentine/{gsub (/\/redis-sentine/, "", $);p rint $;} ' |
                HEAD-1) Case "in Start" if [-Z ${pid}] then echo "Starting $NAME server ..."
        $EXEC $CONF echo "start at Port: $REDISPORT" Else echo "$NAME server already start,pid: $PID"
    fi;;
                Stop) if [-Z ${pid}] then echo "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 a argument";; Esac


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.