这两天工作有空闲,所以看了一下redis文档,决定按照文档搭建一套测试环境,做一下集群的测试。在开始配置集群时,官方推荐采用6个节点,但是测试样例中需要手动创建每个节点的目录和配置文件。正好最近想学习一下脚本,所以写了一个脚本进行自动创建节点,用来学习shell脚本编写。本文只是学习记录,如有打扰请见谅。
redis的文档地址:http://redisdoc.com/topic/cluster-tutorial.html
脚本代码如下
#!/bin/bash
if [ $# -ne 3 ]
then
echo "scan param count is : $#"
echo "scan param is : $*"
exit 1
fi
REDIS_BASE_PATH=$1
REDIS_START_PORT=$2
REDIS_INSTENCE_NUM=$3
echo "redis base path is ${REDIS_BASE_PATH}"
echo "redis start port is ${REDIS_START_PORT}"
echo "redis instence num is ${REDIS_INSTENCE_NUM}"
if [ $REDIS_INSTENCE_NUM -gt 0 ]
then
echo "redis instence is $REDIS_INSTENCE_NUM"
int=1
while (($int<=${REDIS_INSTENCE_NUM}));
do
redis_config_path=$REDIS_BASE_PATH/$REDIS_START_PORT
redis_config_file=$redis_config_path/redis.conf
mkdir -p $redis_config_path
echo "mkdir path is $redis_config_path"
touch $redis_config_file
echo "touch file is $redis_config_file"
chmod 777 $redis_config_file
echo "port $REDIS_START_PORT" > $redis_config_file
echo "cluster-enabled yes" >> $redis_config_file
echo "cluster-config-file nodes.conf" >> $redis_config_file
echo "cluster-node-timeout 5000" >> $redis_config_file
echo "appendonly yes" >> $redis_config_file
let "int++"
let "REDIS_START_PORT++"
done
else
echo "redis instence is 0"
exit 1
fi
exit 0