博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第 6 章 Memcached
阅读量:7120 次
发布时间:2019-06-28

本文共 5374 字,大约阅读时间需要 17 分钟。

目录

6.1. 安装 Memcached
6.1.1. CentOS 下编译
6.1.2. Ubuntu 下编译安装
6.1.3. debian/ubuntu
6.1.4. yum install
6.2. Memcached 代理
6.2.1. moxi
6.2.2. memagent

6.1. 安装 Memcached

6.1.1. CentOS 下编译

libevent

# yum install libevent libevent-devel -y

memcache

# wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz# tar zxf memcached-1.4.5.tar.gz# cd memcached-1.4.5# ./configure --prefix=/usr/local/memcached-1.4.5# make && make install

start

# ln -s /usr/local/memcached-1.4.5 /usr/local/memcached# /usr/local/memcached/bin/memcached -d -m 128 -p 11211 -u nobody -l 172.16.0.1

6.1.2. Ubuntu 下编译安装

http://www.monkey.org/~provos/libevent/

cd /usr/local/src/wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gztar zxf libevent-1.4.13-stable.tar.gzcd libevent-1.4.13-stable./configure --prefix=/usr/local/libevent-1.4.13-stablemakemake installmake verifyln -s /usr/local/libevent-1.4.13-stable /usr/local/libeventln -s /usr/local/libevent/lib/* /usr/lib/ln -s /usr/local/libevent/include/* /usr/include/ln -s /usr/local/libevent/lib/* /usr/local/lib/ln -s /usr/local/libevent/include/* /usr/local/include/

http://www.danga.com/memcached/

cd /usr/local/src/wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gztar zxf memcached-1.4.5.tar.gzcd memcached-1.4.5./configure --prefix=/usr/local/memcached-1.4.5 --with-libevent=/usr/local/libeventmakemake installln -s /usr/local/memcached-1.4.5/ /usr/local/memcachedln -s /usr/local/memcached/bin/memcached /usr/sbin/memcached
/usr/local/memcached/bin/memcached -d -m 2048 -l 127.0.0.1 -p 11211 -u root -c 15000 -P /tmp/memcached.pid

例 6.1. /etc/init.d/memcached

#!/bin/bash# memcached init file for memcached## chkconfig: - 100 100# description: a distributed memory object caching system# author: Neo Chen
## processname: /usr/sbin/memcached# config:# pidfile: /var/run/memcached# source function library. /etc/init.d/functionsOPTIONS="-d -m 2048 -l 127.0.0.1 -p 11211 -u root -c 4096 -P /var/run/memcached"USER=daemonRETVAL=0prog="memcached"start() { echo -n $"Starting $prog: " if [ $UID -ne 0 ]; then RETVAL=1 failure else daemon --user=$USER /usr/sbin/memcached $OPTIONS RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached fi; echo return $RETVAL}stop() { echo -n $"Stopping $prog: " if [ $UID -ne 0 ]; then RETVAL=1 failure else killproc /usr/sbin/memcached RETVAL=$? [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/memcached fi; echo return $RETVAL}reload(){ echo -n $"Reloading $prog: " killproc /usr/sbin/memcached -HUP RETVAL=$? echo return $RETVAL}restart(){ stop start}condrestart(){ [ -e /var/lock/subsys/memcached ] && restart return 0}case "$1" in start) start ;; stop) stop ;; restart) restart ;;# reload)# reload# ;; condrestart) condrestart ;; status) status memcached RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart}" RETVAL=1esacexit $RETVAL

/etc/init.d/memcached

chmod +x /etc/init.d/memcached

flush_all指令清空memcache中的数据

$ telnet 172.16.3.51 11511Trying 172.16.3.51...Connected to 172.16.3.51.Escape character is '^]'.flush_allOKquitConnection closed by foreign host.

6.1.3. debian/ubuntu

$ sudo apt-get install memcache

/etc/memcached.conf

$ cat /etc/memcached.conf# memcached default config file# 2003 - Jay Bonci 
# This configuration file is read by the start-memcached script provided as# part of the Debian GNU/Linux distribution.# Run memcached as a daemon. This command is implied, and is not needed for the# daemon to run. See the README.Debian that comes with this package for more# information.-d# Log memcached's output to /var/log/memcachedlogfile /var/log/memcached.log# Be verbose# -v# Be even more verbose (print client commands as well)# -vv# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default# Note that the daemon will grow to this size, but does not start out holding this much# memory-m 64# Default connection port is 11211-p 11211# Run the daemon as root. The start-memcached will default to running as root if no# -u command is present in this config file-u nobody# Specify which IP address to listen on. The default is to listen on all IP addresses# This parameter is one of the only security measures that memcached has, so make sure# it's listening on a firewalled interface.-l 127.0.0.1# Limit the number of simultaneous incoming connections. The daemon default is 1024# -c 1024# Lock down all paged memory. Consult with the README and homepage before you do this# -k# Return error when memory is exhausted (rather than removing items)# -M# Maximize core file limit# -r

restart

$ sudo /etc/init.d/memcached restart

6.1.4. yum install

# yum install memcached# chkconfig memcached on# chkconfig --list memcached# cat /etc/sysconfig/memcachedPORT="11211"USER="memcached"MAXCONN="1024"CACHESIZE="64"OPTIONS=""# /etc/init.d/memcached startStarting memcached:                                        [  OK  ]

原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

你可能感兴趣的文章
记OC迁移至swift中笔记20tips
查看>>
C# ToString格式字符串整理(Format)(数字、日期和枚举的标准格式设置说明符)
查看>>
VS2010中的顺序图
查看>>
Django 初识
查看>>
第二阶段个人总结10
查看>>
su,sudo
查看>>
用pyqt5做一个能python程序能插入图片的ide
查看>>
mysql学习(2)-Navicat Premium 12 链接MySQL8.0.11数据库报2059错误
查看>>
asp.net中GridView多行表头导出Excel表头显示不全问题解决方法
查看>>
mathnet杂记
查看>>
Wpf 简单制作自己的窗体样式
查看>>
HDU1693 Eat The Trees(插头dp)
查看>>
Unity 可重复随机数
查看>>
unity基础开发----Unity获取PC,Ios系统的mac地址等信息
查看>>
compile error
查看>>
nodejs总结之redis模块
查看>>
GIT 添加多个git账号
查看>>
【分享】免费建立自己的站点
查看>>
UiPath如何实现暂停功能?
查看>>
MySQL事务及隔离级别详解
查看>>