Linux安装Memcached

来源:互联网 发布:辣妈拾宝 淘宝达人 编辑:程序博客网 时间:2024/06/17 08:51

安装memcached(需要GCC)

安装GCCyum -y install gcc

安装libevent

安装memcached服务前需要先安装libevent函数库,如果安装过libevent无需再安装。(如果遇到无法下载在系统中下载了之后上传到centos上)下载libevent(libevent官网:http://libevent.org/)wget https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz解压tar -zxvf libevent-2.1.8-stable.tar.gz -C /usr/local/创建安装目录mkdir /usr/local/libevent切换到解压目录cd /usr/local/libevent-2.1.8-stable设置libevent安装路径./configure -prefix=/usr/local/libevent编译make安装make install

安装memcached

下载memcached(memcached官网:http://www.memcached.org/downloads)wget http://www.memcached.org/files/memcached-1.5.1.tar.gz解压tar -zxvf memcached-1.5.1.tar.gz -C /usr/local/创建安装目录mkdir /usr/local/memcached切换到解压目录cd /usr/local/memcached-1.5.1指定libevent的安装位置(与安装libevent位置保持一致)./configure  -prefix=/usr/local/memcached -with-libevent=/usr/local/libevent编译make安装make install启动命令(我这里是安装到/usr/local/memcached写自己安装的位置)/usr/local/memcached/bin/memcached -d -m 10 -u root -l 192.168.79.130 -p 11211 -c 256 -P /tmp/memcached.pid启动参数:-d  选项是启动一个守护进程,-m  是分配给Memcache使用的内存数量,单位是MB,默认64MB-M  return error on memory exhausted (rather than removing items)-u  是运行Memcache的用户,如果当前为root 的话,需要使用此参数指定用户。-l  是监听的服务器IP地址,默认为所有网卡。-p  是设置Memcache的TCP监听的端口,最好是1024以上的端口-c  选项是最大运行的并发连接数,默认是1024-P  是设置保存Memcache的pid文件-f  <factor>  chunk size growth factor (default: 1.25)-I  Override the size of each slab page. Adjusts max item size(1.4.2版本新增)也可以启动多个守护进程,但是端口不能重复-p 指定端口号(默认11211)  -m 指定最大使用内存大小(默认64MB,最大2G)  -t 线程数(默认4)  -l 连接的IP地址, 默认是本机  -d start 启动memcached服务(缺省值为start)-d restart 重起memcached服务-d stop|shutdown 关闭正在运行的memcached服务-d uninstall 卸载memcached服务-m 最大内存使用,单位MB。默认64MB-M 内存耗尽时返回错误,而不是删除项-c 最大同时连接数,默认是1024  -f 块大小增长因子,默认是1.25  -n 最小分配空间,key+value+flags默认是48-h 显示帮助查看memcached进程ps -ef|grep memcached防火墙设置,开放11211端口通过windows的telnet命令连接memcached服务telnet 192.168.79.130 11211

memcached开机自启脚本(1)

#!/bin/sh   #   # memcached:    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="192.168.137.98"SERVER_PORT="11211"[ -f $MEMCACHED ] || exit1  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           sleep3          start           ;;       *)           echo$"Usage: $0 {start|stop|restart}"          exit1  esac   exit 0设置服务启动1   chmod 755 /etc/init.d/memcached  #增加执行权限 2   chkconfig --add memcached  #添加memcached到服务项3   chkconfig --level 2345 memcached on #设置开机启动4   chkconfig --list memcached  #查看是否设置成功服务管理命令1   service memcached start   # 启动memcached2   service memcached stop   # 关闭memcached3   service memcached restart   # 重启memcached

memcached开机自启脚本(2)

这种方式我只是在网上到了并没有尝试在 /etc/rc.d/rc.local 文件中追加启动命令    /usr/local/memcached/bin/memcached  -u root -d -m 2048 -l 192.168.137.99 -p 11211 -P /tmp/memcached.pid也可不指定IP,默认是本机,如     /usr/local/memcached/bin/memcached  -u deamon -d -m 2048 -p 11211 -P /tmp/memcached.pid

原创粉丝点击