我是靠谱客的博主 孤独大树,最近开发中收集的这篇文章主要介绍CentOS6.8下安装memcached并设置开机自启动,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

参考资料:http://www.cnblogs.com/handongyu/p/6419305.html

        http://coolnull.com/1986.html

一、安装libevent

首先检查系统中是否安装了libevent

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

如果安装了则查看libevent的安装路径,后续安装时需要用到

[root@yeebian ~]# rpm -ql libevent 

如果没有安装,则先安装libevent

[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

 

二、安装memcached

[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

 

三、设置memcached为开机自启动

[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启动脚本是我提前修改好上传到本地服务器的,脚本内容如下:

#! /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 $?

  

转载于:https://www.cnblogs.com/vurtne-lu/p/7251835.html

最后

以上就是孤独大树为你收集整理的CentOS6.8下安装memcached并设置开机自启动的全部内容,希望文章能够帮你解决CentOS6.8下安装memcached并设置开机自启动所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部