#!/bin/bash# author:jian# date:2017-11-16# version:0.1# description: Automatically installs the memcached-1.4.13 and automatically hits the corresponding version of the repcached-1.4.13 patch, applies to CentOS64 bit system, passes test url1= "http://memcached.org/" on CENTOS6/7 Files/old/memcached-1.4.13.tar.gz "url2=" http://mdounin.ru/files/repcached-2.3.1-1.4.13.patch.gz "url3=" https:// Github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz "String= ' cat /etc/redhat-release ' vers= ' echo ${string##*release}|sed ' s/^[[:space:]]*//g ' |awk -F '. " ' {print $1} ' Download_dir=/usr/local/src/export path=/usr/local/sbin:/usr/local/bin:/usr/sbin :/usr/bin:/root/bin:/bin:/sbin:/usr/local/memcached/binif which memcached &>/dev/null ; then echo -e "\033[31myou have installed memcached on your system,please uninstall it first!\033[0m " exit 1ficheck_user () {if [ $UID -ne 0 ] ;then echo -e "\033[31myou must be root to run this script!\033[0m " 1>&2 exit 1fi}install_progs () {for prog in ' echo [email protected] ' doif ! which $prog &>/dev/null; then echo "installing $prog   ..." yum install $prog -y &>/dev/null if [ $? -eq 0 ];then echo "install $prog ok" else echo "download $prog failed,exit" exit 2 fifidone}download () { cd $download _dir for url in ' echo [email protected] ' do if [ ! -e ${download_dir}${url##*/} ];then echo "downloading ${url##*/}  ..." if wget -q -t 8 -c -T 3 $url ;then echo "Download ${ Url##*/} ok. " else echo -e "\033[31mdownload ${url##*/} failed.\033[0m" fi else echo "File ${download_dir}${url##*/} exists." fi done}# libevent-2.1.8-stable.tar.gzinstall_ Libevent () { cd $download _dir if [ -f /usr/local/libevent/lib/ libevent-2.1.so.6 ];then echo "Libevent has installed on your system " else echo " Installing libevent ... " tar xf ${url3##*/} &>/ dev/null cd $ (echo "${url3##*/}" |sed ' s/\.tar\.gz//g ') ./configure --prefix=/usr/local/libevent make && make install echo "/usr/ Local/libevent/lib " > /etc/ld.so.conf.d/libevent.conf ldconfig fi}install_memcached () {cd $download _dirtar xf ${url1##*/} & >/dev/nullgzip -d -c ${download_dir}${url2##*/} > ${download_dir}repcached-2.3.1-1.4.13.patchcd $ (echo "${ url1##*/} " |sed ' s/\.tar\.gz//g ') patch -p1 < /repcached-2.3.1-1.4.13.patch./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/ libevent --enable-replication --enable-64bitmake && make installecho ' Export path=/usr/local/memcached/bin: $PATH ' > /etc/profile.d/memcached.shsource /etc/ profile.d/memcached.sh}check_userinstall_progs wget gccdownload $url 1 $url 2 $url 3if [ -f ${download_dir}${url1##*/} ] && [ -f ${download_dir}${ url2##*/} ] && [ -f ${download_dir}${url3##*/} ];then install_libevent install_memcachedelse echo "There is a lack of necessary installation packageS,please check. " echo "You can download the package manually and put the package into: /usr/local/src " exit 1fiif [ -f / usr/local/memcached/bin/memcached ];then echo -e "\033[32mCongratulations,you have successfuly installed memcached!\033[0m " cd $download _ dir rm -rf ${download_dir}$ (echo "${url1##*/}" |sed ' s/\.tar\.gz//g ' ) rm -rf ${download_dir}$ (echo "${url3##*/}" |sed ' s/\.tar\.gz//g ') else echo -e "\033[31minstalled memcached failed,please check!\033[ 0m "fi echo ' port=" 11211 "' > /etc/sysconfig/memcachedecho ' user=" Nobody "' > > /etc/sysconfig/memcachedecho ' maxconn= ' " >> /etc/sysconfig/memcachedec"ho ' cachesize= ' >> /etc/sysconfig/memcachedecho ' options= ' ' >> /etc/sysconfig/memcached############################################################################## Below is a service script provided by CentOS6, CentOS7 ################################################################################# CENTOS6 The service script, writes it to the/etc/rc.d/init.d/memcached file ####!/bin/bash## init file for memcached## chkconfig: - 86 14# description: Distributed memory caching daemon## processname: memcached# config: /etc/sysconfig/memcached. /etc/rc.d/init.d/ Functions. /etc/sysconfig/memcached## default variablesretval=0prog= "/usr/local/memcached/bin/ Memcached "desc=" DISTRIBUTED&NBsp;memory caching "lockfile="/var/lock/subsys/memcached "Start () { echo -n $ "starting $desc (memcached): " daemon $prog -d -p $PORT -u $USER -c $MAXCONN -m $CACHESIZE $OPTIONS RETVAL=$? [ $RETVAL -eq 0 ] && success && touch $lockfile | | failure echo return $RETVAL}stop () { echo -n $ " shutting down $desc (memcached): " killproc $prog retval=$? [ $RETVAL &NBSP;-EQ&NBSP;0&NBSP;]&NBSP;&&&NBSP;SUCCESS&NBSP;&&&NBSP;RM -f $lockfile | | failure echo return $RETVAL}restart () { stop start}reload () { echo -n $ "reloading $desc ($prog): " killproc $prog -HUP RETVAL=$? [ $RETVAL -eq 0 ] && success | | failure echo return $RETVAL}case "$" in start) start ;; stop) stop ;; restart) restart ;; condrestart) [ -e $lockfile ] && restart RETVAL=$? ;; reload) reload ;; status) status $prog RETVAL=$? ;; *) echo $ "Usage: $0 {start|stoP|restart|condrestart|status} " RETVAL=1esacexit $RETVAL # # # Centos7 The service script, writes it to the/usr/lib/systemd/system/memcached.service file ###[unit]description=memcachedbefore= httpd.serviceafter=network.target[service]type=simpleenvironmentfile=-/etc/sysconfig/memcachedexecstart=/usr/ local/memcached/bin/memcached -u $USER -p $PORT -m $CACHESIZE -c $ maxconn $OPTIONS [Install]wantedby=multi-user.target
This article is from the "11819889" blog, please be sure to keep this source http://11829889.blog.51cto.com/11819889/1982597
memcached-1.4.13 + repcached Automatic installation script