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

 
#! /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 1
fi
##################################################################################
#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.gz

debug=true

url_libevent=http://10.10.83.84/libevent-2.0.18-stable.tar.gz
url_repcached=http://10.10.83.84/repcached-2.3-1.4.5.patch
url_memcached=http://10.10.83.84/memcached-1.4.5.tar.gz


path_software=/opt/software/memcloud/
if [ ! -L ~/memcloud ]; then
   /bin/ln -s $path_software ~/memcloud
fi
##################################################################################


curdir=$(pwd)
#make directory for $path_software
if [ ! -e $path_software ]; then
  /bin/mkdir -p $path_software   
fi

#Download libevent, repcached and memcached if they are not found in the specified path
file_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"]"
fi

ls $path_software | grep libevent
if [ $? -ne 0 ]; then
  /usr/bin/wget $url_libevent -P $path_software 
fi


ls $path_software | grep memcached
if [ $? -ne 0 ]; then
   /usr/bin/wget $url_memcached -P $path_software
fi


if [ ! -e $path_software$file_repcached ]; then 
  /usr/bin/wget $url_repcached -P $path_software
fi


#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_software
cp -r $path_software$file_repcached $path_software$unzipdir_memcached
cd $path_software$unzipdir_memcached
/usr/bin/patch --force -p1 -i repcached-2.3-1.4.5.patch

#install libevent
cd $path_software$unzipdir_libevent
./configure --prefix=/usr/local && make && make install

#install memcached with repcached patch
cd $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.5
fi

cd $curdir

inner_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 0
else 
   exit 2 
fi


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

#! /bin/bash
######################################################################################
###     version 1.0 memcloud.sh
######################################################################################

curdir=$(pwd)
isdebug=1

inner_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 1
fi

#local_addr and remote_addr
la=$1
ra=$2

if 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
  fi
fi

echo $ra | grep  -P '^(\d+\.){3}\d+:\d{1,8}$' > /dev/null
if [ $? -ne 0 ]; then
   echo "remote addr format error:<peer_ip:repc_port>"
   exit 4 
fi

peer_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"
fi

arg_mem=1024
arg_conn=256
arg_user=root

file_pid=/tmp/memcloud_${local_port}_${peer_ip}_${repc_port}.pid
if [ $# -ge 3 ]; then
   app_flag=$3
   file_pid=/tmp/memcloud_${app_flag}_${local_port}_${peer_ip}_${repc_port}.pid
fi

if [ 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=$curdir
pageName=${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 CODE
code=`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 -502
else
   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 CODE
code=`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 -503
else
   echo "append mem-instance into mem-monitor : ${cmd}"
fi

############################################################################
cd $curdir


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值