CentOS6.8下安裝memcached並設置開機自啓動

參考資料:http://www.cnblogs.com/handongyu/p/6419305.htmlhtml

        http://coolnull.com/1986.htmllinux

1、安裝libeventweb

首先檢查系統中是否安裝了libevent服務器

[root@yeebian ~]# rpm -qa | grep libevent  

若是安裝了則查看libevent的安裝路徑,後續安裝時須要用到memcached

[root@yeebian ~]# rpm -ql libevent 

若是沒有安裝,則先安裝libeventrest

[root@yeebian ~]# cd /opt
[root@yeebian opt]# wget http://192.168.10.173:8080/website/linux/libevent-1.4.12-stable.tar.gz
[root@yeebian opt]# tar -zxvf libevent-1.4.12-stable.tar.gz
[root@yeebian opt]# cd libevent-1.4.12-stable
[root@yeebian libevent-1.4.12-stable]# ./configure -prefix=/opt/libevent/
[root@yeebian libevent-1.4.12-stable]# make && make install
[root@yeebian libevent-1.4.12-stable]# ldconfig   #爲了讓動態連接庫爲系統所共享,須要執行如下動態連接庫的管理命令ldconfig

 

2、安裝memcachedhtm

[root@yeebian libevent-1.4.12-stable]# cd /opt
[root@yeebian opt]# wget http://192.168.10.173:8080/website/linux/memcached-1.4.33.tar.gz
[root@yeebian opt]# tar -zxvf memcached-1.4.33.tar.gz
[root@yeebian opt]# cd memcached-1.4.33
[root@yeebian memcached-1.4.33]#./configure --prefix=/opt/memcached-1.4.33/  --with-libevent=/opt/libevent/
[root@yeebian memcached-1.4.33]# make && make install
[root@yeebian memcached-1.4.33]# /opt/memcached-1.4.33/memcached -u root -d -m 128 -p 11211

 

3、設置memcached爲開機自啓動blog

[root@yeebian memcached-1.4.33]# cd /opt/
[root@yeebian opt]# wget http://192.168.10.173:8080/website/linux/memcached.sysv
[root@yeebian opt]# mv memcached.sysv /opt/memcached-1.4.33/scripts/memcached.sysv
[root@yeebian opt]# chmod 775 /opt/memcached-1.4.33/scripts/memcached.sysv
[root@yeebian opt]# cp /opt/memcached-1.4.33/scripts/memcached.sysv /etc/rc.d/init.d/memcached
[root@yeebian opt]# chkconfig --add memcached
[root@yeebian opt]# chkconfig memcached on
[root@yeebian opt]# service memcached restart
Stopping memcached:                                        [  OK  ]
Starting memcached:                                        [  OK  ]
[root@yeebian opt]# chkconfig | grep memcached
Self-starter configuration...
memcached       0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@yeebian opt]# ps aux | grep memcached | grep 11211
Memcached progress...
root      9394  1.0  0.0 341484  3368 ?        Ssl  16:31   0:00 /opt/memcached-1.4.33/memcached -d -p 11211 -u root -m 128 -c 1024 -P /var/run/memcached/memcached.pid

memcached.sysv啓動腳本是我提早修改好上傳到本地服務器的,腳本內容以下:ip

#! /bin/sh
#
# chkconfig: - 55 45
# description:  The memcached daemon is a network memory cache service.
# processname: memcached
# config: /etc/sysconfig/memcached

# Source function library.
. /etc/rc.d/init.d/functions

PORT=11211
USER=root
MAXCONN=1024
CACHESIZE=128
OPTIONS=""

if [ -f /etc/sysconfig/memcached ];then
    . /etc/sysconfig/memcached
fi

# Check that networking is up.
if [ "$NETWORKING" = "no" ]
then
    exit 0
fi

RETVAL=0
prog="memcached"

start () {
    echo -n $"Starting $prog: "
    # insure that /var/run/memcached has proper permissions
    # chown $USER /var/run/memcached
    daemon /opt/memcached-1.4.33/memcached -d -p $PORT -u $USER  -m $CACHESIZE -c $MAXCONN -P /var/run/memcached/memcached.pid $OPTIONS
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
}
stop () {
    echo -n $"Stopping $prog: "
    killproc memcached
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ] ; then
        rm -f /var/lock/subsys/memcached
        rm -f /var/run/memcached/memcached.pid
    fi
}

restart () {
    stop
    start
}


# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
    stop
    ;;
    status)
    status memcached
    ;;
    restart|reload)
    restart
    ;;
    condrestart)
    [ -f /var/lock/subsys/memcached ] && restart || :
    ;;
    *)
    echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"
    exit 1
esac

exit $?
相關文章
相關標籤/搜索