redis學習之shell自動建立節點配置檔案
阿新 • • 發佈:2019-02-16
這兩天工作有空閒,所以看了一下redis文件,決定按照文件搭建一套測試環境,做一下叢集的測試。在開始配置叢集時,官方推薦採用6個節點,但是測試樣例中需要手動建立每個節點的目錄和配置檔案。正好最近想學習一下指令碼,所以寫了一個指令碼進行自動建立節點,用來學習shell指令碼編寫。本文只是學習記錄,如有打擾請見諒。
指令碼程式碼如下
#!/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