linux下安装memcache
首先的下软件
libevent: http://libevent.org/
memcached :http://memcached.org/
我的文件名是 :libevent-2.0.22-stable.tar.gz
memcached-1.4.24.tar.gz
1).memcached依赖libevent文件,所以必须得先安装libevent。
解压: tar zxvf libevent-2.0.22-stable.tar.gz
预编译: ./configure --prefix=/usr/local/libevent
安装: make&&make install
至此libevent 已经安装完成。
2). 安装memcached
解压: tar zxvf memcached-1.4.24.tar.gz
预编译: ./configure -with-libevent=/usr/local/libevent -prefix=/usr/local/memcached
安装: make && make install
至此memcached已经安装完成。
五星级提醒:
查看libevent是否安装成功
ls -al /usr/local/libevent/lib | grep libevent
出现如下类似代码表示安装成功
lrwxrwxrwx. 1 root root 21 7月 27 16:04 libevent-2.0.so.5 -> libevent-2.0.so.5.1.9
-rwxr-xr-x. 1 root root 971951 7月 27 16:04 libevent-2.0.so.5.1.9
-rw-r--r--. 1 root root 1575808 7月 27 16:04 libevent.a
lrwxrwxrwx. 1 root root 26 7月 27 16:04 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.1.9
-rwxr-xr-x. 1 root root 588276 7月 27 16:04 libevent_core-2.0.so.5.1.9
-rw-r--r--. 1 root root 982096 7月 27 16:04 libevent_core.a
-rwxr-xr-x. 1 root root 985 7月 27 16:04 libevent_core.la
lrwxrwxrwx. 1 root root 26 7月 27 16:04 libevent_core.so -> libevent_core-2.0.so.5.1.9
lrwxrwxrwx. 1 root root 27 7月 27 16:04 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.1.9
-rwxr-xr-x. 1 root root 405038 7月 27 16:04 libevent_extra-2.0.so.5.1.9
-rw-r--r--. 1 root root 593784 7月 27 16:04 libevent_extra.a
-rwxr-xr-x. 1 root root 992 7月 27 16:04 libevent_extra.la
lrwxrwxrwx. 1 root root 27 7月 27 16:04 libevent_extra.so -> libevent_extra-2.0.so.5.1.9
-rwxr-xr-x. 1 root root 950 7月 27 16:04 libevent.la
lrwxrwxrwx. 1 root root 30 7月 27 16:04 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.1.9
-rwxr-xr-x. 1 root root 18446 7月 27 16:04 libevent_pthreads-2.0.so.5.1.9
-rw-r--r--. 1 root root 18694 7月 27 16:04 libevent_pthreads.a
-rwxr-xr-x. 1 root root 1013 7月 27 16:04 libevent_pthreads.la
lrwxrwxrwx. 1 root root 30 7月 27 16:04 libevent_pthreads.so -> libevent_pthreads-2.0.so.5.1.9
lrwxrwxrwx. 1 root root 21 7月 27 16:04 libevent.so -> libevent-2.0.so.5.1.9
卸载低版本的libevent
#ls -al /usr/local/libevent/lib |grep libevent
lrwxrwxrwx 1 root root libevent-1.1a.so.1 -> libevent-1.1a.so.1.0.2
-rwxr-xr-x 1 root root libevent-1.1a.so.1.0.2
查看当前libevent版本,如果版本低于1.3,建议先卸载
#rpm -e libevent --nodeps
卸载libevent,
#ls -al /usr/local/libevent/lib |grep libevent
再次查看,卸载成功
查看memcached是否安装成功
ls -al /usr/local/memcached/bin
出现如下类似代码表示安装成功
-rwxr-xr-x. 1 root root 360838 7月 27 16:17 /usr/local/memcached/bin/memcached
配置开启启动服务
打开vi编辑器: vi /etc/init.d/memcached
写入以下服务脚本 (提示 SERVER_IP已你本机ip为主)
#!/bin/sh # #ched: MemCached Daemon # # chkconfig: - 90 25 # description: MemCached Daemon # # Source function library. . /etc/rc.d/init.d/functions . /etc/sysconfig/network #[ ${NETWORKING} = "no" ] && exit 0 #[ -r /etc/sysconfig/dund ] || exit 0 #. /etc/sysconfig/dund #[ -z "$DUNDARGS" ] && exit 0 MEMCACHED="/usr/local/memcached/bin/memcached" SERVER_IP="127.0.0.1" SERVER_PORT="11211" [ -f $MEMCACHED ] || exit 1 start() { echo -n $"Starting memcached: " daemon $MEMCACHED -u daemon -d -m 2048 -l $SERVER_IP -p $SERVER_PORT -P /tmp/memcached.pid echo } stop() { echo -n $"Shutting down memcached: " killproc memcached echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; restart) stop sleep 3 start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 esac exit 0
#设置启动服务
chmod 755 /etc/init.d/memcached #增加执行权限
chkconfig --add memcached #添加memcached到服务项
chkconfig --level 2345 memcached on #设置开机启动
chkconfig --list memcached #查看是否设置成功
#服务管理命令
service memcached start # 启动memcached
service memcached stop # 关闭memcached
service memcached restart # 重启memcached
ps -ef | grep memcached 查看memcached进程是否存在
下面对命令选项进行说明:
-e 显示所有进程。
-f 全格式。
ps e 列出程序时,显示每个程序所使用的环境变量。
ps f 用ASCII字符显示树状结构,表达程序间的相互关系
grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来。
grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限是所有用户。
ps -ef | grep httpd : 检查httpd进程是否存在
netstat -tnlp 查看端口使用情况