Centos7 编译安装memcached

  • 内容
  • 评论
  • 相关

安装必要的依赖

wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz

tar zxvf libevent-2.1.12-stable.tar.gz

cd libevent-2.1.12-stable

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

make && make install

错误提示:

make all-am
make[1]: Entering directory `/data/memcached/libevent-2.1.12-stable'
CCLD test/regress
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: warning: libssl.so.10, needed by ./.libs/libevent_openssl.so, may conflict with libssl.so.1.1
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: test/regress-regress_ssl.o: undefined reference to symbol 'SSL_library_init@@libssl.so.10'
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: /usr/lib64/libssl.so.10: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[1]: *** [test/regress] Error 1
make[1]: Leaving directory `/data/memcached/libevent-2.1.12-stable'
make: *** [all] Error 2


这是由于之前安装了OpenSSL1.1,与系统的OpenSSL1.0发生冲突

#卸载低版本
yum remove -y openssl openssl-devel

# 重新编译
make && make install

下载 & 安装 memcached

wget http://www.memcached.org/files/memcached-1.6.7.tar.gz

tar zxvf memcached-1.6.7.tar.gz

cd memcached-1.6.7

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

make && make install

#添加用户

useradd -s /sbin/nologin memcached

#创建脚本

vim /etc/init.d/memcached

脚本内容:

#!/bin/bash
# memcached  - This shell script takes care of starting and stopping memcached.
#
# chkconfig: 2345 90 10
# description: Memcache provides fast memory based storage.
# processname: memcached

# Author:   PandaMan
# website:  https://xmyunwei.com

# 以下配置根据实际情况调整

memcached_user="memcached"
memcached_path="/server/memcached/bin/memcached"
memcached_pid="/var/run/memcached.pid"
#分配多少内存(默认:64MB)根据服务器情况调整
memcached_memory="256"
#最大同时连接数,默认是1024
memcached_conn="1024"
#指定监听的地址
memcached_listen="0.0.0.0"
###参数配置结束

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

[ -x $memcached_path ] || exit 0

RETVAL=0
prog="memcached"

# Start daemons.
start() {
    if [ -e $memcached_pid -a ! -z $memcached_pid ];then
        echo $prog" already running...."
        exit 1
    fi
    echo -n $"Starting $prog "
    # Single instance for all caches
    $memcached_path -m $memcached_memory -c $memcached_conn -l $memcached_listen -p 11211 -u $memcached_user -d -P $memcached_pid
    RETVAL=$?
    [ $RETVAL -eq 0 ] && {
        touch /var/lock/subsys/$prog
        success $"$prog"
    }
    echo
    return $RETVAL
}

# Stop daemons.
stop() {
    echo -n $"Stopping $prog "
    killproc -d 10 $memcached_path
    echo
    [ $RETVAL = 0 ] && rm -f $memcached_pid /var/lock/subsys/$prog


    RETVAL=$?
    return $RETVAL
}


# See how we were called.
case "$1" in
        start)
            start
            ;;
        stop)
            stop
            ;;
        status)
            status $prog
            RETVAL=$?
            ;;
        restart)
            stop
            start
            ;;
        *)
            echo $"Usage: $0 {start|stop|status|restart}"
            exit 1
esac
exit $RETVAL

添加权限

chmod a+x /etc/init.d/memcached

设置开机启动

systemctl daemon-reload
systemctl start memcached
chkconfig --add memcached

评论

0条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注