linux-tutorial/codes/linux/soft/config/redis/cluster/redis-cluster.sh

102 lines
2.2 KiB
Bash
Raw Normal View History

2020-07-16 11:21:46 +08:00
#!/usr/bin/env bash
# Settings
2020-07-16 11:21:46 +08:00
HOST="172.22.6.3"
PORT=7000
TIMEOUT=2000
NODES=6
REPLICAS=1
2020-07-16 11:21:46 +08:00
ENDPORT=$((PORT+NODES))
# You may want to put the above config parameters into config.sh in order to
# override the defaults without modifying this script.
2020-07-16 11:21:46 +08:00
if [[ -a config.sh ]]
then
source "config.sh"
fi
2020-07-16 11:21:46 +08:00
if [[ "$1" == "create" ]]
then
2020-07-16 11:21:46 +08:00
HOSTLIST=""
while [[ $((PORT < ENDPORT)) != "0" ]]; do
PORT=$((PORT+1))
2020-07-16 11:21:46 +08:00
HOSTLIST="$HOSTLIST $HOST:$PORT"
done
2020-07-16 11:21:46 +08:00
/opt/redis/src/redis-cli --cluster create ${HOSTLIST} --cluster-replicas ${REPLICAS}
exit 0
fi
2020-07-16 11:21:46 +08:00
if [[ "$1" == "start" ]]
then
2020-07-16 11:21:46 +08:00
while [[ $((PORT < ENDPORT)) != "0" ]]; do
PORT=$((PORT+1))
2020-07-16 11:21:46 +08:00
echo "Starting $PORT"
/opt/redis/src/redis-server /usr/local/redis/conf/${PORT}/redis.conf
done
exit 0
fi
2020-07-16 11:21:46 +08:00
if [[ "$1" == "stop" ]]
then
2020-07-16 11:21:46 +08:00
while [[ $((PORT < ENDPORT)) != "0" ]]; do
PORT=$((PORT+1))
echo "Stopping $PORT"
2020-07-16 11:21:46 +08:00
/opt/redis/src/redis-cli -p ${PORT} shutdown nosave
done
exit 0
fi
2020-07-16 11:21:46 +08:00
if [[ "$1" == "watch" ]]
then
PORT=$((PORT+1))
while [ 1 ]; do
clear
date
2020-07-16 11:21:46 +08:00
/opt/redis/src/redis-cli -p ${PORT} cluster nodes | head -30
sleep 1
done
exit 0
fi
2020-07-16 11:21:46 +08:00
if [[ "$1" == "tail" ]]
then
INSTANCE=$2
PORT=$((PORT+INSTANCE))
tail -f ${PORT}.log
exit 0
fi
2020-07-16 11:21:46 +08:00
if [[ "$1" == "call" ]]
then
2020-07-16 11:21:46 +08:00
while [[ $((PORT < ENDPORT)) != "0" ]]; do
PORT=$((PORT+1))
2020-07-16 11:21:46 +08:00
/opt/redis/src/redis-cli -p ${PORT} $2 $3 $4 $5 $6 $7 $8 $9
done
exit 0
fi
2020-07-16 11:21:46 +08:00
if [[ "$1" == "clean" ]]
then
rm -rf *.log
rm -rf appendonly*.aof
rm -rf dump*.rdb
rm -rf nodes*.conf
exit 0
fi
2020-07-16 11:21:46 +08:00
if [[ "$1" == "clean-logs" ]]
then
rm -rf *.log
exit 0
fi
echo "Usage: $0 [start|create|stop|watch|tail|clean]"
echo "start -- Launch Redis Cluster instances."
echo "create -- Create a cluster using redis-cli --cluster create."
echo "stop -- Stop Redis Cluster instances."
echo "watch -- Show CLUSTER NODES output (first 30 lines) of first node."
echo "tail <id> -- Run tail -f of instance at base port + ID."
echo "clean -- Remove all instances data, logs, configs."
echo "clean-logs -- Remove just instances logs."