Memcached

Memcached

八月 08, 2019

Memcached

目录

[隐藏]

  • [1安装依赖包]
  • [2创建账户]
  • [3下载安装]
  • [4配置文件]
  • [5目录权限]
  • [6系统服务配置文件]
  • [7配置为系统服务]
  • [8启动memcached]

安装依赖包

1
yum -y install libevent libevent-devel

创建账户

1
2
groupadd memcached
useradd -gmemcached -s /sbin/nologin -M memcached

下载安装

1
2
3
4
5
6
7
wget http://www.memcached.org/files/memcached-1.5.12.tar.gz
tar xzf memcached-1.5.12.tar.gz
cd memcached-1.5.12
./configure --prefix=/data/soft/memcached
make
make install
ln -s /data/soft/memcached/bin/memcached /usr/bin/

配置文件

1
2
3
4
5
6
7
8
cat > /data/soft/memcached/memcached.conf << EOF
PORT="22122"
USER="memcached"
MAXCONN="65535"
CACHESIZE="8192"
OPTIONS=""

EOF

目录权限

1
2
3
mkdir -p /var/run/memcached
chown -R memcached.memcached /data/soft/memcached
chown -R memcached.memcached /var/run/memcached

系统服务配置文件

vim /etc/init.d/memcached

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#! /bin/sh
#
# chkconfig: - 55 45
# description: The memcached daemon is a network memory cache service.
# processname: memcached
# config: /data/soft/memcached/memcached.conf
# pidfile: /var/run/memcached/memcached.pid

# Standard LSB functions
#. /lib/lsb/init-functions

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

PORT="22122"
USER="memcached"
MAXCONN="65535"
CACHESIZE="8192"
OPTIONS=""

if [ -f /data/soft/memcached/memcached.conf ];then
. /data/soft/memcached/memcached.conf
fi

# Check that networking is up.
. /etc/sysconfig/network

if [ "$NETWORKING" = "no" ]
then
exit 0
fi

RETVAL=0
prog="memcached"
pidfile=${PIDFILE-/var/run/memcached/memcached.pid}
lockfile=${LOCKFILE-/var/lock/subsys/memcached}

start () {
[ "$EUID" != "0" ] && exit 4
echo -n $"Starting $prog: "
# Ensure that /var/run/memcached has proper permissions
if [ "`stat -c %U /var/run/memcached`" != "$USER" ]; then
chown $USER /var/run/memcached
fi

daemon --pidfile ${pidfile} memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P ${pidfile} $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch ${lockfile}
}
stop () {
[ "$EUID" != "0" ] && exit 4
echo -n $"Stopping $prog: "
killproc -p ${pidfile} /usr/bin/memcached
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f ${lockfile} ${pidfile}
fi
}
restart () {
stop
start
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} memcached
RETVAL=$?
;;
restart|reload|force-reload)
restart
;;
condrestart|try-restart)
[ -f ${lockfile} ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart|try-restart}"
RETVAL=2
;;
esac

exit $RETVAL

配置为系统服务

1
2
3
chmod u+x /etc/init.d/memcached
chkconfig --add memcached
chkconfig memcached on

启动memcached

1
service memcached start