Skip to content


linux centos5.8 安装memcached

1.安装libevent
yum install libevent.x86_64 libevent-devel.x86_64
没有libevent编译memcached为出错

  1. checking for libevent directory... configure: error: libevent is required.  You can get it from http://www.monkey.org/~provos/libevent/
  2.       If it's already installed, specify its path using --with-libevent=/dir/

2.安装memcached

  1. wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
  2. tar zxvf memcached-1.4.15.tar.gz
  3. cd memcached-1.4.15
  4. ./configure --prefix=/opt/memcached-1.4.15
  5. make
  6. make install
  7.  
  8. ln -s /opt/memcached-1.4.15 /opt/memcached

3.配置文件
vi /opt/memcached/my.conf

  1. PORT="11200"
  2. IP="192.168.0.40"
  3. USER="root"
  4. MAXCONN="1524"
  5. CACHESIZE="3000"
  6. OPTIONS=""
  7. #memcached

4.启动/关闭脚本
vi /etc/init.d/memcached

  1. #!/bin/bash
  2. #
  3. # Save me to /etc/init.d/memcached
  4. # And add me to system start
  5. # chmod +x memcached
  6. # chkconfig --add memcached
  7. # chkconfig --level 35 memcached on
  8. #
  9. # Written by lei
  10. #
  11. # chkconfig: - 80 12
  12. # description: Distributed memory caching daemon
  13. #
  14. # processname: memcached
  15. # config: /usr/local/memcached/my.conf
  16.  
  17. source /etc/rc.d/init.d/functions
  18.  
  19. ### Default variables
  20. PORT="11211"
  21. IP="192.168.0.40"
  22. USER="root"
  23. MAXCONN="1524"
  24. CACHESIZE="64"
  25. OPTIONS=""
  26. SYSCONFIG="/opt/memcached/my.conf"
  27.  
  28. ### Read configuration
  29. [ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
  30.  
  31. RETVAL=0
  32. prog="/opt/memcached/bin/memcached"
  33. desc="Distributed memory caching"
  34.  
  35. start() {
  36.     echo -n $"Starting $desc ($prog): "
  37.     daemon $prog -d -p $PORT -l $IP -u $USER -c $MAXCONN -m $CACHESIZE $OPTIONS
  38.     RETVAL=$?
  39.     echo
  40.     [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
  41.     return $RETVAL
  42. }
  43.  
  44. stop() {
  45.     echo -n $"Shutting down $desc ($prog): "
  46.     killproc $prog
  47.     RETVAL=$?
  48.     echo
  49.     [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/memcached
  50.     return $RETVAL
  51. }
  52.  
  53. restart() {
  54.     stop
  55.     start
  56. }
  57.  
  58. reload() {
  59.     echo -n $"Reloading $desc ($prog): "
  60.     killproc $prog -HUP
  61.     RETVAL=$?
  62.     echo
  63.     return $RETVAL
  64. }
  65.  
  66. case "$1" in
  67.   start)
  68.     start
  69.     ;;
  70.   stop)
  71.     stop
  72.     ;;
  73.   restart)
  74.     restart
  75.     ;;
  76.   condrestart)
  77.     [ -e /var/lock/subsys/$prog ] && restart
  78.     RETVAL=$?
  79.     ;;
  80.   reload)
  81.     reload
  82.     ;;
  83.   status)
  84.     status $prog
  85.     RETVAL=$?
  86.     ;;
  87.    *)
  88.     echo $"Usage: $0 {start|stop|restart|condrestart|status}"
  89.     RETVAL=1
  90. esac
  91.  
  92. exit $RETVAL

5.添加iptables 充许192.168.0.0/24访问

  1. iptables -A INPUT -s 192.168.0.0/255.255.255.0 -p tcp -m tcp --dport 11200 -j ACCEPT

6.启动
/etc/init.d/memcached start

7.web 管理界面
http://www.junopen.com/memadmin/

Posted in Memcached/redis.

Tagged with .


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.