memcached安装过程

1.下载:

libevent-2.0.21-stable.tar.gz

memcached-1.4.15.tar.gz

 

2.解压缩

 

tar zxvf libevent-2.0.21-stable.tar.gz

 

3.编译

cd libevent-2.0.21-stable

./configure --prefix=/usr 

make 

make install 

 

4.测试libevent是否安装成功:

[root@caocao-web libevent-2.0.21-stable]# ls -al /usr/lib | grep libevent

lrwxrwxrwx   1 root root      21 Aug 20 18:55 libevent-2.0.so.5 -> libevent-2.0.so.5.1.9

-rwxr-xr-x   1 root root  968861 Aug 20 18:55 libevent-2.0.so.5.1.9

-rw-r--r--   1 root root 1574410 Aug 20 18:55 libevent.a

lrwxrwxrwx   1 root root      26 Aug 20 18:55 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.1.9

-rwxr-xr-x   1 root root  571966 Aug 20 18:55 libevent_core-2.0.so.5.1.9

-rw-r--r--   1 root root  957882 Aug 20 18:55 libevent_core.a

-rwxr-xr-x   1 root root     970 Aug 20 18:55 libevent_core.la

lrwxrwxrwx   1 root root      26 Aug 20 18:55 libevent_core.so -> libevent_core-2.0.so.5.1.9

lrwxrwxrwx   1 root root      27 Aug 20 18:55 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.1.9

-rwxr-xr-x   1 root root  417375 Aug 20 18:55 libevent_extra-2.0.so.5.1.9

-rw-r--r--   1 root root  616600 Aug 20 18:55 libevent_extra.a

-rwxr-xr-x   1 root root     977 Aug 20 18:55 libevent_extra.la

lrwxrwxrwx   1 root root      27 Aug 20 18:55 libevent_extra.so -> libevent_extra-2.0.so.5.1.9

-rwxr-xr-x   1 root root     935 Aug 20 18:55 libevent.la

lrwxrwxrwx   1 root root      29 Aug 20 18:55 libevent_openssl-2.0.so.5 -> libevent_openssl-2.0.so.5.1.9

-rwxr-xr-x   1 root root   87014 Aug 20 18:55 libevent_openssl-2.0.so.5.1.9

-rw-r--r--   1 root root  122732 Aug 20 18:55 libevent_openssl.a

-rwxr-xr-x   1 root root    1006 Aug 20 18:55 libevent_openssl.la

lrwxrwxrwx   1 root root      29 Aug 20 18:55 libevent_openssl.so -> libevent_openssl-2.0.so.5.1.9

lrwxrwxrwx   1 root root      30 Aug 20 18:55 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.1.9

-rwxr-xr-x   1 root root   18102 Aug 20 18:55 libevent_pthreads-2.0.so.5.1.9

-rw-r--r--   1 root root   18694 Aug 20 18:55 libevent_pthreads.a

-rwxr-xr-x   1 root root     998 Aug 20 18:55 libevent_pthreads.la

lrwxrwxrwx   1 root root      30 Aug 20 18:55 libevent_pthreads.so -> libevent_pthreads-2.0.so.5.1.9

lrwxrwxrwx   1 root root      21 Aug 20 18:55 libevent.so -> libevent-2.0.so.5.1.9

5.编译memecached

cd memcached-1.4.15

./configure --with-libevent=/usr 

make 

make install

6.测试是否安装成功

 ls -al /usr/local/bin/mem*

 

-rwxr-xr-x 1 root root 200727 Dec  1  2011 /usr/local/bin/memaslap

-rwxr-xr-x 1 root root 298349 Aug 20 18:58 /usr/local/bin/memcached

-rwxr-xr-x 1 root root 116918 Dec  1  2011 /usr/local/bin/memcapable

-rwxr-xr-x 1 root root  43001 Dec  1  2011 /usr/local/bin/memcat

-rwxr-xr-x 1 root root  47935 Dec  1  2011 /usr/local/bin/memcp

-rwxr-xr-x 1 root root  41161 Dec  1  2011 /usr/local/bin/memdump

-rwxr-xr-x 1 root root  34224 Dec  1  2011 /usr/local/bin/memerror

-rwxr-xr-x 1 root root  40935 Dec  1  2011 /usr/local/bin/memflush

-rwxr-xr-x 1 root root  47012 Dec  1  2011 /usr/local/bin/memparse

-rwxr-xr-x 1 root root  41612 Dec  1  2011 /usr/local/bin/memrm

-rwxr-xr-x 1 root root  68257 Dec  1  2011 /usr/local/bin/memslap

-rwxr-xr-x 1 root root  51269 Dec  1  2011 /usr/local/bin/memstat

 

7.启动Memcached服务:

.启动Memcache的服务器端:

# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.141.64 -p 12000 -c 256 -P /tmp/memcached.pid

 

-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,

/usr/local/bin/memcached -d -m 1024 -u root -l 221.122.114.80 -p 12000 -c 500 -P /usr/local/lol/memcached/memcached.pid (注意最后一个P是大写)

8.如果要结束Memcache进程,执行:

 

# kill `cat /tmp/memcached.pid`

 

ps -aux | grep memcache 

 

也可以启动多个守护进程,不过端口不能重复。

 

 

常见问题:

 

1.如果启动Memcached服务的时候遇到了

 

/usr/local/bin/memcached: error while loading shared libraries: libevent-1.2.so.1: cannot open shared object file: No such file or directory;

 

解决方案:

 

复制代码

[root@localhost bin]# LD_DEBUG=libs memcached -v 

[root@localhost bin]# ln -s /usr/lib/libevent-1.2.so.1 /usr/lib64/libevent-1.2.so.1

[root@localhost bin]# /usr/local/bin/memcached -d -m 100 -u root -p 12000 -c 1000 -P /tmp/memcached.pid

[root@localhost bin]# ps -aux

复制代码

可以看到启动的Memcached服务了.

 

 

 

2.把Memcached服务加载到Linux的启动项中.万一机器断电系统重启.那么Memcached就会自动启动了.

 

假如启动Memcache的服务器端的命令为:

# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.141.64 -p 12000 -c 256 -P /tmp/memcached.pid容来自17jquery

 

想开机自动启动的话,只需在/etc/rc.d/rc.local中加入一行,下面命令

/usr/local/memcached/bin/memcached -d -m 10 -p 12000 -u apache -c 256 

上面有些东西可以参考一下:即,ip不指定时,默认是本机,用户:最好选择是:apache 或 deamon

这样,也就是属于哪个用户的服务,由哪个用户启动。

 

 

 

 

 

你可能感兴趣的:(memcached)