服务器篇之memcache的安装
Memcache用到了libevent这个库用于Socket的处理,所以还需要安装libevent。
Memcache下载 :http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz
Libevent下载:http://www.monkey.org/~provos/libevent-1.3.tar.gz
1、分别下载memcache、libevent,放在/tmp目录:
1 [root@nosay /]# cd tmp 2 3 [root@nosay tmp]# wget http://www.danga.com/memcached/dist/memcached-1.2.0.tar.gz 4 5 [root@nosay tmp]# wget http://www.monkey.org/~provos/libevent-1.2.tar.gz
2、安装libevent:
解压软件包:
[root@nosay tmp]# tar zxvf libevent-1.2.tar.gz
进入目录:
[root@nosay tmp]# cd libevent-1.2
指定安装路径:
[root@nosay libevent-1.2]# ./configure -prefix=/usr
注意:这一步出现了错误提示:
1 configure: error: no acceptable C compiler found in $PATH 2 See `config.log' for more details.
解决方案:
安装GCC软件套件:
[root@nosay libevent-1.2]# yum install gcc
然后执行安装:
1 [root@nosay libevent-1.2]make 2 [root@nosay libevent-1.2]make install
检测libevent,是否安装成功:
[root@nosay libevent-1.2]# ls -al /usr/lib | grep libevent
检测结果:
[root@nosay libevent-1.2]# ls -al /usr/lib | grep libevent lrwxrwxrwx. 1 root root 21 10月 12 14:34 libevent-1.2.so.1 -> libevent-1.2.so.1.0.3 -rwxr-xr-x. 1 root root 264048 10月 12 14:34 libevent-1.2.so.1.0.3 -rw-r--r--. 1 root root 430244 10月 12 14:34 libevent.a -rwxr-xr-x. 1 root root 805 10月 12 14:34 libevent.la lrwxrwxrwx. 1 root root 21 10月 12 14:34 libevent.so -> libevent-1.2.so.1.0.3 [root@nosay libevent-1.2]#
说明安装成功。
3、安装memcache:
[root@nosay tmp]# tar zxvf memcached-1.2.0.tar.gz
[root@nosay tmp]# cd memcached-1.2.0
指定libevent的安装目录:
[root@nosay memcached-1.2.0]# ./configure -with-libevent=/usr
1 [root@nosay memcached-1.2.0]# make 2 [root@nosay memcached-1.2.0]# make install
安装完成后会把memcached放到 /usr/local/bin/memcached 。
检测memcache,是否安装成功:
[root@nosay bin]# ls -al /usr/local/bin/mem*
检测结果:
[root@nosay bin]# ls -al /usr/local/bin/mem* -rwxr-xr-x. 1 root root 113172 10月 12 14:45 /usr/local/bin/memcached -rwxr-xr-x. 1 root root 117527 10月 12 14:45 /usr/local/bin/memcached-debug [root@nosay bin]#
安装成功。
4、启动 memchache:
启动:
[root@nosay bin]# /usr/local/bin/memcached -d -u root -m 512 -p 11211
出现错误提示:
/usr/local/bin/memcached: error while loading shared libraries: libevent-1.2.so.1: cannot open shared object file: No such file or directory
解决方案:
(1):
[root@nosay bin]# LD_DEBUG=libs /usr/local/bin/memcached -v
(2):
[root@nosay bin]# ln -s /usr/lib/libevent-1.2.so.1 /usr/lib64/libevent-1.2.so.1
(3):
[root@nosay bin]# /usr/local/bin/memcached -d -u root -m 512 -p 11211 -P /tmp/memcached.pid
注:memcache 配置参数如下:
-d选项是启动一个守护进程, -m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB, -u是运行Memcache的用户,我这里是root, -l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.0.200, -p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口, -c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定, -P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,
检测 memcache 是否启动成功:
[root@nosay bin]# pgrep memcached 14752 [root@nosay bin]# netstat -tulpn | grep :11211 tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 14752/memcached udp 0 0 0.0.0.0:11211 0.0.0.0:* 14752/memcached [root@nosay bin]# ps -ef | grep memcached root 14752 1 3 16:49 ? 00:00:08 /usr/local/bin/memcached -d -u root -m 512 -p 11211 -P /tmp/memcached.pid root 14770 14613 0 16:53 pts/0 00:00:00 grep memcached [root@nosay bin]#
以上表示 memcache 启动成功。
5、安装 Memcache 的 PHP 扩展:
1> 在http://pecl.php.net/package/memcache 选择相应想要下载的memcache版本。
[root@nosay tmp]# wget http://pecl.php.net/get/memcache-3.0.8.tgz
2> 安装PHP的memcache扩展。
[root@nosay tmp]# tar vxzf memcache-3.0.8.tgz [root@nosay tmp]# cd memcache-3.0.8
错误提示时,执行下面两行的安装:
1 [root@nosay memcache-3.0.8]# yum install php-devel 2 [root@nosay memcache-3.0.8]# yum install zlib-devel
1 [root@nosay memcache-3.0.8]# phpize 2 [root@nosay memcache-3.0.8]# ./configure 3 [root@nosay memcache-3.0.8]# make 4 [root@nosay memcache-3.0.8]# make install
执行后:
[root@nosay memcache-3.0.8]# make install Installing shared extensions: /usr/lib64/php/modules/
修改PHP的配置文件:
vim /etc/php.ini
修改为:
extension_dir = "/usr/lib64/php/modules/"
添加一行,载入 memcache:
extension = memcache.so
6、centos 安装 tenlen
1>安装: [root@nosay html]# yum install telnet-server [root@nosay html]# yum install telnet 2>修改配置文件: [root@nosay html]# vim /etc/xinetd.d/telnet 修改 disable = yes 为 disable = no 3>启动: [root@nosay html]# service xinetd restart 4>连接,查看: [root@nosay html]# telnet 127.0.0.1 11211 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. 注:stats 为输入的命令,39833 为 memcache 的端口号 stats STAT pid 39833 STAT uptime 9676 STAT time 1414004085 STAT version 1.2.0 STAT pointer_size 64 STAT rusage_user 0.089986 STAT rusage_system 12.270134 STAT curr_items 0 STAT total_items 0 STAT bytes 0 STAT curr_connections 2 STAT total_connections 3 STAT connection_structures 3 STAT cmd_get 0 STAT cmd_set 0 STAT get_hits 0 STAT get_misses 0 STAT bytes_read 7 STAT bytes_written 0 STAT limit_maxbytes 536870912 END 注:quit 为退出 tenlen 的命令 quit