天天看点

Memcached 安装脚本

一、目的

为简化memcached快速安装部署,并添加至服务启动项,开机自启动。

二、脚本

2.1 github地址

github链接

2.2 脚本内容

#!/bin/bashbr/>#mail:[email protected]

#function:auto install memcached

clear

echo "##########################################"

echo "# auto install memcached-1.4 ##"

echo "# press ctrl + c to cancel ##"

echo "# any key to continue ##"

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 <code>ls</code>

tar zxf $software -c /tmp

done

install() {

cd /tmp/libevent-2.1.8-stable

./configure --prefix=/usr/local/libevent

make &amp;&amp; make install

rm -rf /tmp/libevent-2.1.8-stable

echo "/usr/local/libevent/lib"&gt;/etc/ld.so.conf.d/libevent.conf

ldconfig

cd /tmp/memcached-1.4.0

./configure --with-libevent=/usr/local/libevent --prefix=/usr/local/memcached

rm -rf /tmp/memcached-1.4.0

echo "export path=$path:/usr/local/memcached/bin"&gt;/etc/profile.d/memcached.sh &amp;&amp; source /etc/profile.d/memcached.sh

start_server() {

cat &gt;/etc/init.d/memcached-server&lt;&lt;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}

stop() {

if test "x\${getpid}" != x; then

action $"stopping \$prog " /bin/true

killall memcached

retval=\$?

[ \$retval = 0 ] &amp;&amp; rm -rf \${lockfile} \${pidfile}

return \$retval

case "\$1" in

start)

start

;;

esac

exit \${retval}

eof

cd /

chmod +x /etc/init.d/memcached-server

chkconfig memcached-server on

service memcached-server start

main() {

sys_init

download_software

install

start_server

main

三、测试

Memcached 安装脚本
Memcached 安装脚本