linux安装memcached服务

时光总嘲笑我的痴心妄想 提交于 2019-12-05 07:12:42

1. 准备安装文件

下载memcached与libevent的安装文件

libevent-2.0.21-stable.tar.gz

memcached-server-1.4.31.tar.gz

2. 具体安装步骤

1.由于memcached依赖于libevent,因此需要安装libevent。由于linux系统可能默认已经安装libevent,执行命令:

rpm -qa|grep libevent

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

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

3. 安装libevent命令:

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


 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!