CentOS Make Install Memcached Server (Revised)

在centos手动安装 memcached server.

安装的时候报这个错的解决如下:

1
2
3
If it's already installed, specify its path using --with-libevent=/dir/

sudo yum -y install libevent-devel

下载安装文件

1
2
3
4
5
6
7
wget -c http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
tar xzf memcached-1.4.15.tar.gz
cd memcached-1.4.15
./configure --prefix=/usr/local/memcached

sudo make
sudo make install

手动启动

1
2
3
4
5
6
7
8
sudo /usr/local/memcached/bin/memcached -d -m 1024 -u root -l 127.0.0.1 -p 11211 -c 1024 -P /tmp/memcached.pid
-d选项是启动一个守护进程
-m分配给Memcache使用的内存数量,单位是MB
-u运行Memcache的用户
-l监听的服务器IP地址
-p设置Memcache监听的端口,最好是1024以上的端口
-c最大运行的并发连接数,默认是1024,按照你服务器的负载量来设定
-P设置保存Memcache的pid文件

service启动

1
2
3
4
5
6
7
8
9
10
11
sudo wget http://www.centos.bz/wp-content/uploads/2011/11/memcached -O /etc/init.d/memcached
sudo chmod +x /etc/init.d/memcached

###创建配置文件
sudo vi /usr/local/memcached/memcached.conf

PORT="11211"     #启动的端口
USER="memcached" #使用的用户
MAXCONN="2048"   #最大并发连接
CACHESIZE="1024" #最大使用内存
OPTIONS=""

建立用户memcached,加入启动项,并启动memcached

1
2
3
4
5
6
7
8
9
10
11
12
13
因为之前不是用root用户创建的,所以现在转入root中创建组
$ su -
# groupadd memcached
# useradd -g memcached memcached
# chkconfig --add memcached
# chkconfig memcached on
# service memcached start
# service memcached status


# netstat -lanpt|grep 11211
tcp        0      0 0.0.0.0:11211               0.0.0.0:*                   LISTEN      17514/memcached
tcp        0      0 :::11211                    :::*                        LISTEN      17514/memcached

done!

注:memcached文件 http://www.centos.bz/wp-content/uploads/2011/11/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
91
92
93
#!/bin/bash
#
# Init file for memcached
#
# Written by Dag Wieers <dag@wieers.com>
#
# chkconfig: - 80 12
# description: Distributed memory caching daemon
#
# processname: memcached
## config: /etc/sysconfig/memcached
## config: /etc/memcached.conf
# config: /usr/local/memcached/memcached.conf
# pidfile: /var/run/memcached.pid

source /etc/init.d/functions

### Default variables
PORT="11211"
USER="memcached"
MAXCONN="2048"
CACHESIZE="64"
OPTIONS=""

#BIN="/usr/local/bin"
BIN="/usr/local/memcached/bin"
SYSCONFIG="/usr/local/memcached/memcached.conf"

### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"

RETVAL=0
prog="memcached"
desc="Distributed memory caching"

start() {
        echo -n $"Starting $desc ($prog) on port $PORT: "
        daemon $BIN/$prog -d -p $PORT -u $USER -c $MAXCONN -m $CACHESIZE $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
        return $RETVAL
}

stop() {
        echo -n $"Shutting down $desc ($prog): "
        kill `ps -aef | grep $PORT | grep -v grep | awk '{print $2}'` > /dev/null 2>&1
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
        return $RETVAL
}

restart() {
        stop
        start
}

reload() {
        echo -n $"Reloading $desc ($prog): "
        killproc $prog -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  condrestart)
        [ -e /var/lock/subsys/$prog ] && restart
        RETVAL=$?
        ;;
  reload)
        reload
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
   *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        RETVAL=1
esac

exit $RETVAL
原文地址:http://dlj.bz/TNQ6gz

Comments