时隔一年,终于享受了下当年写的自动安装memcloud脚本

来源:互联网 发布:mac安装农行安全控件 编辑:程序博客网 时间:2024/05/06 01:25
 
#! /bin/bash##################################################################################### version 1.0 memcloud_install.sh###################################################################################exit value mapping (you can get this value by executing "echo $?" after this script executed)#0 SUCC#1 EXIST (Needless to install memcached)#2 ERROR if [ -e /usr/local/bin/memcached ]; then   echo "/usr/local/bin/memcached exist"   exit 1fi###################################################################################CONFIGURATIONS#url_libevent=https://github.com/downloads/libevent/libevent/libevent-2.0.19-stable.tar.gz#url_repcached=http://mdounin.ru/files/repcached-2.3-1.4.5.patch.gz#url_memcached=http://memcached.googlecode.com/files/memcached-1.4.5.tar.gzdebug=trueurl_libevent=http://10.10.83.84/libevent-2.0.18-stable.tar.gzurl_repcached=http://10.10.83.84/repcached-2.3-1.4.5.patchurl_memcached=http://10.10.83.84/memcached-1.4.5.tar.gzpath_software=/opt/software/memcloud/if [ ! -L ~/memcloud ]; then   /bin/ln -s $path_software ~/memcloudfi##################################################################################curdir=$(pwd)#make directory for $path_softwareif [ ! -e $path_software ]; then  /bin/mkdir -p $path_software   fi#Download libevent, repcached and memcached if they are not found in the specified pathfile_libevent=`echo $url_libevent | grep -P -o 'libevent.*$'`file_repcached=`echo $url_repcached | grep -P -o 'repcached.*$'`file_memcached=`echo $url_memcached | grep -P -o 'memcached.*$'`unzipdir_libevent=`echo $file_libevent | awk -F'.tar' '{ printf "%s", $1 }'`unzipdir_memcached=`echo $file_memcached | awk -F'.tar' '{ printf "%s", $1 }'`if [ debug ]; then   echo "path_software:["$path_software"]"   echo "libevent version: "$file_libevent   echo "repcached version: "$file_repcached   echo "memcached version: "$file_memcached   echo "unzipdir_libevent:["$unzipdir_libevent"]"   echo "["$path_software$unzipdir_libevent"]"fils $path_software | grep libeventif [ $? -ne 0 ]; then  /usr/bin/wget $url_libevent -P $path_software fils $path_software | grep memcachedif [ $? -ne 0 ]; then   /usr/bin/wget $url_memcached -P $path_softwarefiif [ ! -e $path_software$file_repcached ]; then   /usr/bin/wget $url_repcached -P $path_softwarefi#unzip libevent and memcached (with repcached patch)/bin/tar zxvf $path_software$file_libevent -C $path_software/bin/tar zxvf $path_software$file_memcached -C $path_softwarecp -r $path_software$file_repcached $path_software$unzipdir_memcachedcd $path_software$unzipdir_memcached/usr/bin/patch --force -p1 -i repcached-2.3-1.4.5.patch#install libeventcd $path_software$unzipdir_libevent./configure --prefix=/usr/local && make && make install#install memcached with repcached patchcd $path_software$unzipdir_memcached./configure --prefix=/usr/local --with-libevent=/usr/local --enable-replication && make && make install#create the appropriate symlink for libevent#otherwise you will get 'memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory'#while you execute 'memcached -d -m 100 -u root -l 10.10.83.177 -p 11211 -c 256 -P /tmp/memcached.pid'#HELP REFER: http://www.nigeldunn.com/2011/12/11/libevent-2-0-so-5-cannot-open-shared-object-file-no-such-file-or-directory/if [ -e /usr/local/lib/libevent-2.0.so.5 ]; then   ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5   ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5ficd $curdirinner_ip=`ifconfig | grep -P 'inet addr:(10.|192.)' | head -1 | awk '{ printf "%s", substr($2,6) }'`if [ -e /usr/local/bin/memcached ]; then   echo "memcloud installed ok: /usr/local/bin/memcached"   echo "/usr/local/bin/memcached -d -m 100 -u root -l $inner_ip -p 11211 -c 256 -P /tmp/memcached.pid"   exit 0else    exit 2 fi


上面是memcloud_install.sh 接着运行 memcloud.sh

#! /bin/bash#########################################################################################     version 1.0 memcloud.sh######################################################################################curdir=$(pwd)isdebug=1inner_network=`ifconfig | grep -P 'inet addr:(10.|192.)' | head -1 | awk '{ printf "%s", substr($2,6) }'`usage="Usage: memcloud.sh [local_ip:]<local_port> <peer_ip:repc_port> example: memcloud.sh 11211 ${inner_network}:11212"if [ $# -lt 2 ]; then   echo  $usage   exit 1fi#local_addr and remote_addrla=$1ra=$2if echo $la | grep -P '^(\d+\.){3}\d+:\d{1,8}$' > /dev/null ; then   local_ip=`echo $la | awk -F':' '{ printf "%s", $1}'`  local_port=`echo $la | awk -F':' '{ printf "%s", $2}'`else  echo $la | grep -P '^\d{1,8}$' > /dev/null  if [ $? -eq 0 ]; then      local_ip=`ifconfig | grep -P 'inet addr:(10.|192.)' | head -1 | awk '{ printf "%s", substr($2,6) }'`      local_port=$la     else        echo "local addr format error: [local_ip:]<local_port>"       exit 3  fifiecho $ra | grep  -P '^(\d+\.){3}\d+:\d{1,8}$' > /dev/nullif [ $? -ne 0 ]; then   echo "remote addr format error:<peer_ip:repc_port>"   exit 4 fipeer_ip=`echo -n $ra | awk -F':' '{ printf "%s", $1}'`repc_port=`echo -n $ra | awk -F':' '{ printf "%s", $2}'`if [ isdebug ]; then   echo "local addr is $local_ip:$local_port and remote addr is $peer_ip:$repc_port"fiarg_mem=1024arg_conn=256arg_user=rootfile_pid=/tmp/memcloud_${local_port}_${peer_ip}_${repc_port}.pidif [ $# -ge 3 ]; then   app_flag=$3   file_pid=/tmp/memcloud_${app_flag}_${local_port}_${peer_ip}_${repc_port}.pidfiif [ isdebug ]; then   echo "/usr/local/bin/memcached -d -p ${local_port} -m ${arg_mem} -x ${peer_ip} -X ${repc_port} -u ${arg_user} -l ${local_ip}  -c ${arg_conn} -P ${file_pid}"   echo "/usr/local/bin/memcached -d -p ${local_port} -m ${arg_mem} -x ${peer_ip} -X ${repc_port} -u ${arg_user} -l ${local_ip}  -c ${arg_conn} -P ${file_pid} -v >> ./memdebug.log  2>&1"fi/usr/local/bin/memcached -d -p ${local_port} -m ${arg_mem} -x ${peer_ip} -X ${repc_port} -u ${arg_user} -l ${local_ip}  -c ${arg_conn} -P ${file_pid} ################################################################################# append mem-instance into mem-dns though HTTP API ##############################################################################cmd="/usr/local/bin/memcached -d -p ${local_port} -m ${arg_mem} -x ${peer_ip} -X ${repc_port} -u ${arg_user} -l ${local_ip}  -c ${arg_conn} -P ${file_pid}"pageRoot=$curdirpageName=${local_port}_${peer_ip}_${repc_port}/usr/bin/curl http://10.10.83.177/memcloud/mem-create.xml --data cmd="${cmd}" --silent --connect-timeout 30 --dump-header ${pageRoot}/${pageName}_new.head --output ${pageRoot}/${pageName}_new.body#CHECK: HTTP STATUS CODEcode=`grep HTTP/1. ${pageRoot}/${pageName}_new.head | tr -d '\n\r' | awk {'print $2'}`if [ $code -ne 200 ]then   echo "Error HTTP Code $code on $pageName"   exit -502else   echo "append mem-instance into mem-dns : ${cmd}"fi################################################################################# append mem-instance into mem-monitor though HTTP API ##############################################################################pageName=monitor_${local_ip}_${local_port}/usr/bin/curl http://10.10.83.177:8081/memcloud/client-create.xml --data paramId="${local_ip}:${local_port}" --silent --connect-timeout 30 --dump-header ${pageRoot}/${pageName}_new.head --output ${pageRoot}/${pageName}_new.body#CHECK: HTTP STATUS CODEcode=`grep HTTP/1. ${pageRoot}/${pageName}_new.head | tr -d '\n\r' | awk {'print $2'}`if [ $code -ne 200 ]then   echo "Error HTTP Code $code on $pageName"   exit -503else   echo "append mem-instance into mem-monitor : ${cmd}"fi############################################################################cd $curdir