[Shell Script in CentOS] Redis 다운로드 및 재배포 패키징하기 :: 2014/07/08 15:43

#!/bin/sh

CURRENT_DIR=$(pwd)

make_default_config() {
  echo "daemonize no" >> $REDIS_DIR/redis.conf
  echo "pidfile /var/run/redis.pid" >> $REDIS_DIR/redis.conf
  echo "tcp-backlog 511" >> $REDIS_DIR/redis.conf
  echo "port 6379" >> $REDIS_DIR/redis.conf
  echo "timeout 0" >> $REDIS_DIR/redis.conf
  echo "tcp-keepalive 0" >> $REDIS_DIR/redis.conf
  echo "loglevel notice" >> $REDIS_DIR/redis.conf
  if [[ -z "$AG_HOME" ]]; then
    echo "logfile \"$HOME/ag/logs/redis.log\"" >> $REDIS_DIR/redis.conf
  else
    echo "logfile \"$AG_HOME/logs/redis.log\"" >> $REDIS_DIR/redis.conf
  fi
  echo "databases 16" >> $REDIS_DIR/redis.conf
  echo "save 900 1" >> $REDIS_DIR/redis.conf
  echo "save 300 10" >> $REDIS_DIR/redis.conf
  echo "save 60 10000" >> $REDIS_DIR/redis.conf
  echo "stop-writes-on-bgsave-error yes" >> $REDIS_DIR/redis.conf
  echo "rdbcompression yes" >> $REDIS_DIR/redis.conf
  echo "rdbchecksum yes" >> $REDIS_DIR/redis.conf
  echo "dbfilename \"dump.rdb\"" >> $REDIS_DIR/redis.conf
  if [[ -z "$REDIS_HOME" ]]; then
    echo "dir \"$HOME/ag/redis\"" >> $REDIS_DIR/redis.conf
  else
    echo "dir \"$REDIS_HOME\"" >> $REDIS_DIR/redis.conf
  fi
  echo "slave-serve-stale-data yes" >> $REDIS_DIR/redis.conf
  echo "slave-read-only yes" >> $REDIS_DIR/redis.conf
  echo "repl-disable-tcp-nodelay no" >> $REDIS_DIR/redis.conf
  echo "slave-priority 100" >> $REDIS_DIR/redis.conf
  echo "appendonly yes" >> $REDIS_DIR/redis.conf
  echo "appendfilename \"appendonly.aof\"" >> $REDIS_DIR/redis.conf
  echo "appendfsync everysec" >> $REDIS_DIR/redis.conf
  echo "no-appendfsync-on-rewrite no" >> $REDIS_DIR/redis.conf
  echo "auto-aof-rewrite-percentage 100" >> $REDIS_DIR/redis.conf
  echo "auto-aof-rewrite-min-size 64mb" >> $REDIS_DIR/redis.conf
  echo "lua-time-limit 5000" >> $REDIS_DIR/redis.conf
  echo "slowlog-max-len 128" >> $REDIS_DIR/redis.conf
  echo "notify-keyspace-events \"\"" >> $REDIS_DIR/redis.conf
  echo "hash-max-ziplist-entries 512" >> $REDIS_DIR/redis.conf
  echo "hash-max-ziplist-value 64" >> $REDIS_DIR/redis.conf
  echo "list-max-ziplist-entries 512" >> $REDIS_DIR/redis.conf
  echo "list-max-ziplist-value 64" >> $REDIS_DIR/redis.conf
  echo "set-max-intset-entries 512" >> $REDIS_DIR/redis.conf
  echo "zset-max-ziplist-entries 128" >> $REDIS_DIR/redis.conf
  echo "zset-max-ziplist-value 64" >> $REDIS_DIR/redis.conf
  echo "hll-sparse-max-bytes 3000" >> $REDIS_DIR/redis.conf
  echo "activerehashing yes" >> $REDIS_DIR/redis.conf
  echo "client-output-buffer-limit normal 0 0 0" >> $REDIS_DIR/redis.conf
  echo "client-output-buffer-limit slave 256mb 64mb 60" >> $REDIS_DIR/redis.conf
  echo "client-output-buffer-limit pubsub 32mb 8mb 60" >> $REDIS_DIR/redis.conf
  echo "hz 10" >> $REDIS_DIR/redis.conf
  echo "aof-rewrite-incremental-fsync yes" >> $REDIS_DIR/redis.conf
  echo "maxclients 8160" >> $REDIS_DIR/redis.conf
}

DOWN_BASE_URL="http://download.redis.io/releases/"
BASE_PREFIX="redis-"
BASE_SUFFIX=".tar.gz"

# Check Input Parameters
while getopts "l:v:" o;
do
  case "${o}" in
  l)
    LOCATE=${OPTARG}
    ;;
  v)
    VERSION=${OPTARG}
    ;;
  *)
    echo "Invalid Parameter."
    exit 1
    ;;
  \?)
    echo "Invalid Parameter."
    exit 1
    ;;
  esac
done

echo "Step 1 : Check redis server source package....."
  sleep 1
 
  if [[ -z "$LOCATE" ]]; then
    LOCATE="local"
  fi
 
  if [[ -z "$VERSION" ]]; then
    VERSION="2.8.12"
  fi
 
  if [[ "$LOCATE" == "remote" ]]; then
    wget $DOWN_BASE_URL$BASE_PREFIX$VERSION$BASE_SUFFIX
  else
    cd $CURRENT_DIR
    if [ -f "$BASE_PREFIX$VERSION$BASE_SUFFIX" ]; then
      echo "  $BASE_PREFIX$VERSION$BASE_SUFFIX exists in current directory."
    else
      echo "  $BASE_PREFIX$VERSION$BASE_SUFFIX does not exist in current directory."
      exit 1
    fi
  fi
 
echo "  done"
sleep 1

echo "Step 2 : Unpackage the redis server source...."
  sleep 1
  if [ -d "$BASE_PREFIX$VERSION" ]; then
    rm -rf $BASE_PREFIX$VERSION
  fi
 
  if [ -f "$BASE_PREFIX$VERSION$BASE_SUFFIX" ]; then
    tar -zxvf $BASE_PREFIX$VERSION$BASE_SUFFIX
    wait $!
  else
    echo "  Error. $BASE_PREFIX$VERSION$BASE_SUFFIX does not exist."
    exit 1
  fi
 
echo "  done"
sleep 1

REDIS_DIR=$CURRENT_DIR/$BASE_PREFIX$VERSION

echo "Step 3 : Default redis configuration file create...."
  sleep 1
  mv $REDIS_DIR/redis.conf $REDIS_DIR/redis.conf.bak
  touch $REDIS_DIR/redis.conf
  make_default_config
echo "  done"
sleep 1

echo "Step 4 : Repackage the redis server source...."
  sleep 1
  cd $CURRENT_DIR
  mv $BASE_PREFIX$VERSION redis
  tar -zcvf redis.tar.gz redis
  wait $!
  rm -rf redis
echo "  done"

2014/07/08 15:43 2014/07/08 15:43
Trackback Address :: http://www.yongbi.net/trackback/597
[로그인][오픈아이디란?]
오픈아이디로만 댓글을 남길 수 있습니다
Name
Password
Homepage

Secret
< PREV |  1  |  ...  198  |  199  |  200  |  201  |  202  |  203  |  204  |  205  |  206  |  ...  566  |  NEXT >