Created
December 28, 2012 03:54
-
-
Save matetsu/4394290 to your computer and use it in GitHub Desktop.
RedisのMasterホストを指定して、Slaveになるためのスクリプト。
要 redis-slaveof.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# redis-to-slave.sh | |
PROG_NAME=$0 | |
HOSTNAME=`hostname -s` | |
REDIS_PORT=6379 | |
logger -t ${PROG_NAME} "Start changing ${HOSTNAME} to redis slave..." | |
if [ "$#" != "1" ]; then | |
echo "FATAL: Invalid argument." | |
echo "Usage: ${0} redis_master_hostname" | |
exit 1 | |
fi | |
MASTER_HOST=$1 | |
logger -t ${PROG_NAME} "Change this host to slave." | |
# up to master | |
/usr/local/sbin/redis-slaveof.py ${MASTER_HOST} ${REDIS_PORT} | |
sed -i -e "s/^slaveof.*/slaveof ${MASTER_HOST} ${REDIS_PORT}/" /etc/redis/redis.conf | |
# setting for cluster | |
/sbin/service sentinel status > /dev/null 2>&1 | |
if [ "$?" = "0" ]; then | |
logger -t ${PROG_NAME} "sentinel service is running. so stop service." | |
/sbin/service sentinel stop | |
fi | |
logger -t ${PROG_NAME} "Changing sentinel.conf file." | |
sed -e "s/__MASTER_HOST__/${MASTER_HOST}/g" /etc/redis/sentinel.conf.template > /etc/redis/sentinel.conf | |
logger -t ${PROG_NAME} "Start sentinel service..." | |
/sbin/service sentinel start | |
/sbin/service sentinel status > /dev/null 2>&1 | |
if [ "$?" != "0" ]; then | |
logger -t ${PROG_NAME} "Failed to start sentinel service." | |
fi | |
/sbin/chkconfig sentinel on | |
logger -t ${PROG_NAME} "Finished to change ${HOSTNAME} to redis master." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment