Memcached installation script (with server startup)

The purpose of,

To simplify the installation and deployment of Memcached, add Memcached to the service boot option.

Second, the script

2.1 making address

Making a link

2.2 Script Content

#! /bin/bash #mail:[email protected] #function:auto install memcached clea echo "##########################################" Echo "# Auto Install Memcached-1.4 ##" echo "# Press Ctrl + C to cancel ## echo "# Any key to continue ## echo "##########################################" read -n 1 softdir="/software" Memcached \ _url = "http://www.danga.com/memcached/dist/memcached-1.4.0.tar.gz" Libevent \ _url = "https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz"  sys\_version=$(rpm -q centos-release|cut -d- -f3) sys\_init() { [ -f /etc/init.d/functions ] && . /etc/init.d/functions  [ ${sys\_version} != "6" ] && echo "Please use centos6.x" && exit 1 [ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1 sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config setenforce 0 yum install -y gcc gcc-c++ wget } download\_software() { if [ ! -d ${softdir} ]; then mkdir ${softdir} && cd ${softdir} else cd ${softdir} fi for software\_url in ${memcached\_url} ${libevent\_url} do wget -c ${software\_url} if [ $? -eq 0 ]; Then for software in 'ls' do tar ZXF $software -c/TMP done fi done} install() {CD/TMP /libevent-2.1.8-stable /configure --prefix=/usr/local/libevent make && make install rm -rf/TMP /libevent-2.1.8-stable echo "/ usr/local/lib/libevent" > / etc/ld. So. Conf. D/libevent. Conf ldconfig CD/TMP/memcached - 1.4.0. / configure --with-libevent=/usr/local/libevent --prefix=/usr/local/memcached make && make install rm -rf/TMP /memcached-1.4.0 echo "export PATH=$PATH:/usr/local/memcached/bin">/etc/profile.d/memcached.sh && source /etc/profile.d/memcached.sh } start\_server() { cat >/etc/init.d/memcached-server<<EOF #! /bin/bash #auth:kaliarch # memcached Startup script for memcached processes # # chkconfig: - 90 10 # description: Memcache provides fast memory based storage. # processname: memcached . /etc/rc.d/init.d/functions memcached="/usr/local/memcached/bin/memcached" prog="memcached" port=11211 user=nobody mem=20 lockfile=\${LOCKFILE-/var/lock/subsys/memcached} pidfile=\${PIDFILE-/tmp/memcached.pid} getpid=\$(pidof memcached) start() { action $"Starting \$prog: " /bin/true # Starting memcached with 64MB memory on port 11211 as deamon and user nobody \$memcached -d -m \$mem -p \$port -u \$user -P \${pidfile} RETVAL=$? [ \$RETVAL = 0 ] && touch \${lockfile} return \$RETVAL } stop() { if test "x\${getpid}" ! = x; then action $"Stopping \$prog " /bin/true killall memcached fi RETVAL=\$? [ \$RETVAL = 0 ] && rm -rf \${lockfile} \${pidfile} return \$RETVAL } case "\$1" in start) start ;; stop) stop ;; status) status -p \${pidfile} \${memcached} RETVAL=\$? ;; restart) stop start ;; condrestart) if test "x\${getpid}" ! = x; then stop start fi ;; \*) echo $"Usage: \$0 {start|status|stop|restart|condrestart}" exit 1 esac exit \${RETVAL} EOF cd / chmod +x /etc/init.d/memcached-serve chkconfig memcached-server on service memcached-server start } main() { sys\_init download\_software install start\_serve } mainCopy the code

Three, test,



Original statement, this article is the author authorized cloud + community – column published, without permission, shall not be reproduced.

If there is infringement, please contact [email protected] to delete.

7
share

    To report