安装环境:Centos 6.4 32位 memcached-1.4.25 libevent-2.0.22-stable
memcached是基于libevent的,所以要安装libevent,而memcached和libevent是由C编写的,所以系统要安装gcc。
一、下载libevent,memcached,安装gcc
查看是否已安装gcc
[pfq@pfq ~]$ rpm -qa|grep gcc gcc-gfortran-4.4.7-3.el6.i686 libgcc-4.4.7-3.el6.i686 compat-libgcc-296-2.96-144.el6.i686 gcc-4.4.7-3.el6.i686 gcc-c++-4.4.7-3.el6.i686
如果没有安装gcc,直接yum安装即可
[pfq@pfq ~]$ sudo yum -y install gcc [pfq@pfq ~]$ sudo yum -y install gcc-c++
下载memcached-1.4.25 libevent-2.0.22-stable
[pfq@pfq ~]$ wget http://memcached.org/files/memcached-1.4.25.tar.gz [pfq@pfq ~]$ wget http://nchc.dl.sourceforge.net/project/levent/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz
二、编译安装 libevent-2.0.22-stable
查看是否已安装libevent,如已安装旧版本,可以删去
[pfq@pfq ~]$ rpm -qa|grep libevent libevent-1.4.13-4.el6.i686 [pfq@pfq ~]$ rpm -e --nodeps libevent-1.4.13-4.el6.i686
解压、编译安装libevent
[pfq@pfq ~]$ tar zxf libevent-2.0.22-stable.tar.gz [pfq@pfq ~]$ cd libevent-2.0.22-stable [pfq@pfq libevent-2.0.22-stable]$ ./configure --prefix=/usr [pfq@pfq libevent-2.0.22-stable]$ echo $? 0 [pfq@pfq libevent-2.0.22-stable]$ sudo make [pfq@pfq libevent-2.0.22-stable]$ echo $? 0 [pfq@pfq libevent-2.0.22-stable]$ sudo make install [pfq@pfq libevent-2.0.22-stable]$ echo $? 0 [pfq@pfq ~]$ sudo su - [root@pfq ~]# cd /usr/lib 如有以下文件即安装成功 [root@pfq lib]# ll|grep libevent lrwxrwxrwx. 1 root root 21 Nov 30 20:07 libevent-2.0.so.5 -> libevent-2.0.so.5.1.9 -rwxr-xr-x. 1 root root 756947 Nov 30 20:07 libevent-2.0.so.5.1.9 -rw-r--r--. 1 root root 986992 Nov 30 20:07 libevent.a lrwxrwxrwx. 1 root root 26 Nov 30 20:07 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.1.9 -rwxr-xr-x. 1 root root 464122 Nov 30 20:07 libevent_core-2.0.so.5.1.9 -rw-r--r--. 1 root root 620796 Nov 30 20:07 libevent_core.a -rwxr-xr-x. 1 root root 970 Nov 30 20:07 libevent_core.la lrwxrwxrwx. 1 root root 26 Nov 30 20:07 libevent_core.so -> libevent_core-2.0.so.5.1.9 lrwxrwxrwx. 1 root root 27 Nov 30 20:07 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.1.9 -rwxr-xr-x. 1 root root 310856 Nov 30 20:07 libevent_extra-2.0.so.5.1.9 -rw-r--r--. 1 root root 366268 Nov 30 20:07 libevent_extra.a -rwxr-xr-x. 1 root root 977 Nov 30 20:07 libevent_extra.la lrwxrwxrwx. 1 root root 27 Nov 30 20:07 libevent_extra.so -> libevent_extra-2.0.so.5.1.9 -rwxr-xr-x. 1 root root 935 Nov 30 20:07 libevent.la lrwxrwxrwx. 1 root root 30 Nov 30 20:07 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.1.9 -rwxr-xr-x. 1 root root 14577 Nov 30 20:07 libevent_pthreads-2.0.so.5.1.9 -rw-r--r--. 1 root root 12166 Nov 30 20:07 libevent_pthreads.a -rwxr-xr-x. 1 root root 998 Nov 30 20:07 libevent_pthreads.la lrwxrwxrwx. 1 root root 30 Nov 30 20:07 libevent_pthreads.so -> libevent_pthreads-2.0.so.5.1.9 lrwxrwxrwx. 1 root root 21 Nov 30 20:07 libevent.so -> libevent-2.0.so.5.1.9
三、编译安装 memcached-1.4.25
[pfq@pfq ~]$ tar zxf memcached-1.4.25.tar.gz [pfq@pfq ~]$ cd memcached-1.4.25 [pfq@pfq memcached-1.4.25]$ ./configure --with-libevent=/usr --prefix=/home/pfq/memcached [pfq@pfq memcached-1.4.25]$ echo $? 0 [pfq@pfq memcached-1.4.25]$ sudo make [pfq@pfq memcached-1.4.25]$ echo $? 0 [pfq@pfq memcached-1.4.25]$ sudo make install [pfq@pfq memcached-1.4.25]$ echo $? 0 如有以下文件即安装成功 [pfq@pfq ~]$ ll memcached total 12 drwxr-xr-x. 2 root root 4096 Nov 30 20:28 bin drwxr-xr-x. 3 root root 4096 Nov 30 20:28 include drwxr-xr-x. 3 root root 4096 Nov 30 20:28 share
四、memcached启动与停止
[pfq@pfq ~]$ memcached/bin/memcached -d -m 10 -u pfq -l 192.168.88.141 -p 12000 -c 256 -P /tmp/memcached.pid [pfq@pfq ~]$ telnet 192.168.88.141 12000 -bash: telnet: command not found [pfq@pfq ~]$ sudo yun install -y telnet sudo: yun: command not found [pfq@pfq ~]$ sudo yum install -y telnet [pfq@pfq ~]$ telnet 192.168.88.141 12000 Trying 192.168.88.141... Connected to 192.168.88.141. Escape character is '^]'. 输入stats STAT pid 8162 STAT uptime 128 STAT time 1448887058 STAT version 1.4.25 STAT libevent 2.0.22-stable STAT pointer_size 32 STAT rusage_user 0.001999 STAT rusage_system 0.037994 STAT curr_connections 5 STAT total_connections 6 STAT connection_structures 6 STAT reserved_fds 20 STAT cmd_get 0 STAT cmd_set 0 STAT cmd_flush 0 STAT cmd_touch 0 STAT get_hits 0 STAT get_misses 0 STAT delete_misses 0 STAT delete_hits 0 STAT incr_misses 0 STAT incr_hits 0 STAT decr_misses 0 STAT decr_hits 0 STAT cas_misses 0 STAT cas_hits 0 STAT cas_badval 0 STAT touch_hits 0 STAT touch_misses 0 STAT auth_cmds 0 STAT auth_errors 0 STAT bytes_read 7 STAT bytes_written 0 STAT limit_maxbytes 10485760 STAT accepting_conns 1 STAT listen_disabled_num 0 STAT time_in_listen_disabled_us 0 STAT threads 4 STAT conn_yields 0 STAT hash_power_level 16 STAT hash_bytes 262144 STAT hash_is_expanding 0 STAT malloc_fails 0 STAT bytes 0 STAT curr_items 0 STAT total_items 0 STAT expired_unfetched 0 STAT evicted_unfetched 0 STAT evictions 0 STAT reclaimed 0 STAT crawler_reclaimed 0 STAT crawler_items_checked 0 STAT lrutail_reflocked 0 END quit Connection closed by foreign host. 这表示启动成功 [pfq@pfq ~]$ kill -9 8162(即上面STAT pid) [pfq@pfq ~]$ telnet 192.168.88.141 12000 Trying 192.168.88.141... telnet: connect to address 192.168.88.141: Connection refused memcached已停止
启动参数说明:
-d是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB;
-u是运行Memcache的用户;
-l是监听的服务器IP地址;
-p是设置Memcache监听的端口最好是1024以上的端口;
-c选项是最大运行的并发连接数,默认是1024,按照服务器的负载量来设定;
-P是设置保存Memcache的pid文件;