linux安装memcached服务

1. 准备安装文件node

下载memcached与libevent的安装文件linux

libevent-2.0.21-stable.tar.gzbash

memcached-server-1.4.31.tar.gz服务器

2. 具体安装步骤并发

1.因为memcached依赖于libevent,所以须要安装libevent。因为linux系统可能默认已经安装libevent,执行命令:memcached

rpm -qa|grep libevent.net

查看系统是否带有该安装软件,若是有执行命令:rest

rpm -e libevent-1.4.13-4.el6.x86_64 --nodeps(因为系统自带的版本旧,忽略依赖删除)code

3. 安装libevent命令:server

[root@localhost mysoft]# tar -zxvf libevent-2.0.21-stable.tar.gz 
[root@localhost mysoft]# cd libevent-2.0.21-stable
[root@localhost libevent-2.0.21-stable]# ./configure --prefix=/usr/local/libevent
[root@localhost libevent-2.0.21-stable]# make
[root@localhost libevent-2.0.21-stable]# make install

至此libevent安装完毕;

安装过程当中出现:configure: error : no acceptable C compiler found in $PATH错误时是没有安装gcc,运行以下命令:

yum install gcc* make*

4. 安装memcached命令:

[root@localhost mysoft]# tar -zxvf memcached-1.4.31.tar.gz 
[root@localhost memcached-1.4.31]# cd memcached-1.4.31
[root@localhost memcached-1.4.31]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
[root@localhost memcached-1.4.31]# make
[root@localhost memcached-1.4.31]# make install

5.当启动memcached时常常不能发现libevent.so;能够经过如下命令检查:

   进入/usr/local/memcached/bin目录

LD_DEBUG=help
./memcached -v
LD_DEBUG=libs  ./ memcached -v
解决方法:
ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /lib64/libevent-2.0.so.5

6. 启动memcached
1.打开一个终端,输入如下命令:
./usr/local/memcached/bin/memcached -d -m 256 -u root -l 192.168.1.1 -p 11211 -c 1024 –P /tmp/memcached.pid

7. 编写启动脚本

#!/bin/sh   
#   
# memcached:    MemCached Daemon   
#   
# chkconfig:    - 90 25    
# description:  MemCached Daemon   
#   
# Source function library.   
. /etc/rc.d/init.d/functions   
. /etc/sysconfig/network   
    
start()    
{   
        echo -n $"Starting memcached: "  
        daemon /usr/local/memcached/bin/memcached -d -m 256 -u root -l 10.26.240.137 -p 11211 -c 1024 -P /tmp/memcached.pid
        echo   
}   
    
stop()    
{   
        echo -n $"Shutting down memcached: "  
        killproc memcached    
        echo   
}   
    
[ -f /usr/local/bin/memcached ] || exit 0  
    
# See how we were called.   
case "$1" in   
  start)   
        start   
        ;;   
  stop)   
        stop   
        ;;   
  restart|reload)   
        stop   
        start   
        ;;   
  condrestart)   
        stop   
        start   
        ;;   
  *)   
        echo $"Usage: $0 {start|stop|restart|reload|condrestart}"  
        exit 1  
esac   
exit 0

 8. 添加的服务

[root@localhost ~]# chkconfig  --add memcached 
[root@localhost ~]# chkconfig  --level 235  memcached  on
[root@localhost ~]# chkconfig  --list | grep mem
memcached       0:off   1:off   2:on   3:on    4:off   5:on   6:off

接下来,能够用如下命令启动与中止 memcached

/etc/rc.d/init.d/memcached  start      ## 启动
/etc/rc.d/init.d/memcached  stop      ## 中止
/etc/rc.d/init.d/memcached  restart   ## 重启

[root@localhost ~]# /etc/rc.d/init.d/memcached  restart
Shutting down memcached: [  OK  ]
Starting memcached:      [  OK  ]


启动参数说明:
-d 选项是启动一个守护进程。
-u root 表示启动memcached的用户为root。
-m 是分配给Memcache使用的内存数量,单位是MB,默认64MB。
-M return error on memory exhausted (rather than removing items)。
-u 是运行Memcache的用户,若是当前为root 的话,须要使用此参数指定用户。
-p 是设置Memcache的TCP监听的端口,最好是1024以上的端口。
-c 选项是最大运行的并发链接数,默认是1024。
-P 是设置保存Memcache的pid文件。

-l是监听的服务器IP地址,若是有多个地址的话,我这里指定了服务器的IP地址192.168.0.200,

相关文章
相关标签/搜索