时隔一年,终于享受了下当年写的自动安装memcloud脚本
2013-11-01 10:52
417 查看
#!/bin/bash
##################################################################################
###version1.0memcloud_install.sh
##################################################################################
#exitvaluemapping(youcangetthisvaluebyexecuting"echo$?"afterthisscriptexecuted)
#0SUCC
#1EXIST(Needlesstoinstallmemcached)
#2ERROR
if[-e/usr/local/bin/memcached];then
echo"/usr/local/bin/memcachedexist"
exit1
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)
#makedirectoryfor$path_software
if[!-e$path_software];then
/bin/mkdir-p$path_software
fi
#Downloadlibevent,repcachedandmemcachediftheyarenotfoundinthespecifiedpath
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"libeventversion:"$file_libevent
echo"repcachedversion:"$file_repcached
echo"memcachedversion:"$file_memcached
echo"unzipdir_libevent:["$unzipdir_libevent"]"
echo"["$path_software$unzipdir_libevent"]"
fi
ls$path_software|greplibevent
if[$?-ne0];then
/usr/bin/wget$url_libevent-P$path_software
fi
ls$path_software|grepmemcached
if[$?-ne0];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
#unziplibeventandmemcached(withrepcachedpatch)
/bin/tarzxvf$path_software$file_libevent-C$path_software
/bin/tarzxvf$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-irepcached-2.3-1.4.5.patch
#installlibevent
cd$path_software$unzipdir_libevent
./configure--prefix=/usr/local&&make&&makeinstall
#installmemcachedwithrepcachedpatch
cd$path_software$unzipdir_memcached
./configure--prefix=/usr/local--with-libevent=/usr/local--enable-replication&&make&&makeinstall
#createtheappropriatesymlinkforlibevent
#otherwiseyouwillget'memcached:errorwhileloadingsharedlibraries:libevent-2.0.so.5:cannotopensharedobjectfile:Nosuchfileordirectory'
#whileyouexecute'memcached-d-m100-uroot-l10.10.83.177-p11211-c256-P/tmp/memcached.pid'
#HELPREFER: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'inetaddr:(10.|192.)'|head-1|awk'{printf"%s",substr($2,6)}'`
if[-e/usr/local/bin/memcached];
then
echo"memcloudinstalledok:/usr/local/bin/memcached"
echo"/usr/local/bin/memcached-d-m100-uroot-l$inner_ip-p11211-c256-P/tmp/memcached.pid"
exit0
else
exit2
fi
上面是memcloud_install.sh接着运行memcloud.sh
#!/bin/bash
######################################################################################
###version1.0memcloud.sh
######################################################################################
curdir=$(pwd)
isdebug=1
inner_network=`ifconfig|grep-P'inetaddr:(10.|192.)'|head-1|awk'{printf"%s",substr($2,6)}'`
usage="Usage:memcloud.sh[local_ip:]<local_port><peer_ip:repc_port>example:memcloud.sh11211${inner_network}:11212"
if[$#-lt2];then
echo$usage
exit1
fi
#local_addrandremote_addr
la=$1
ra=$2
ifecho$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[$?-eq0];then
local_ip=`ifconfig|grep-P'inetaddr:(10.|192.)'|head-1|awk'{printf"%s",substr($2,6)}'`
local_port=$la
else
echo"localaddrformaterror:[local_ip:]<local_port>"
exit3
fi
fi
echo$ra|grep-P'^(\d+\.){3}\d+:\d{1,8}$'>/dev/null
if[$?-ne0];then
echo"remoteaddrformaterror:<peer_ip:repc_port>"
exit4
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"localaddris$local_ip:$local_portandremoteaddris$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[$#-ge3];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.log2>&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}
##############################################################################
###appendmem-instanceintomem-dnsthoughHTTPAPI
##############################################################################
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/curlhttp://10.10.83.177/memcloud/mem-create.xml--datacmd="${cmd}"--silent--connect-timeout30--dump-header${pageRoot}/${pageName}_new.head--output${pageRoot}/${pageName}_new.body
#CHECK:HTTPSTATUSCODE
code=`grepHTTP/1.${pageRoot}/${pageName}_new.head|tr-d'\n\r'|awk{'print$2'}`
if[$code-ne200]
then
echo"ErrorHTTPCode$codeon$pageName"
exit-502
else
echo"appendmem-instanceintomem-dns:${cmd}"
fi
##############################################################################
###appendmem-instanceintomem-monitorthoughHTTPAPI
##############################################################################
pageName=monitor_${local_ip}_${local_port}
/usr/bin/curlhttp://10.10.83.177:8081/memcloud/client-create.xml--dataparamId="${local_ip}:${local_port}"--silent--connect-timeout30--dump-header${pageRoot}/${pageName}_new.head--output${pageRoot}/${pageName}_new.body
#CHECK:HTTPSTATUSCODE
code=`grepHTTP/1.${pageRoot}/${pageName}_new.head|tr-d'\n\r'|awk{'print$2'}`
if[$code-ne200]
then
echo"ErrorHTTPCode$codeon$pageName"
exit-503
else
echo"appendmem-instanceintomem-monitor:${cmd}"
fi
############################################################################
cd$curdir
相关文章推荐
- linux中的自动安装虚拟机脚本
- Oracle 11g R2 for Linux 自动安装配置---完整shell脚本
- PPTP脚本自动安装
- ClamAV 0.99 反病毒软件自动安装脚本
- expect安装测试-自动登陆脚本
- linux下lamp 源码安装详解(次内容可以直接复制当作自动安装脚本)
- ubuntu 12.10 常用软件自动安装脚本
- 自动卸载安装apk脚本
- RPM包安装mysql,采用shell脚本实现自动安装、配置与卸载
- 自动vsftpd安装和匿名建立脚本
- 全自动安装Linux下expect的脚本
- mysql 自动安装脚本
- 自动安装nginx和varnish脚本
- shell写自动安装脚本自动读取license和自动输入回车
- 生产服务器LNMP全自动安装脚本 推荐
- hadoop自动安装的脚本与步骤
- Xcode文档自动安装脚本
- Ubuntu自动编译和安装Python的shell脚本
- lamp脚本自动安装
- zabbix agentd客户端插件Shell一键自动安装脚本