memcached 的总结
来源:互联网 发布:java list移除元素 编辑:程序博客网 时间:2024/06/03 14:26
1、memcached在Linux下安装
-u是运行Memcache的用户,我这里是root,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.0.200,
-p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid
首先安装libevent
#tar -zxvf libevent-2.0.12-stable.tar.gz
#cd /libevent
#./configuer --prefix=/usr/local/libevent
#make
#make install
然后安装memcached
#tar -zxvf memcached-1.4.14.tar.gz
#cd memcached
#./configure --with-libevent=/usr/local/libevent
#make
#make install
2、启动memcached
#/usr/local/bin/memcached -d -m 1024 -l 127.0.0.1 -p 20001 -u root -c 1024 -p memcached.pid
-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,-u是运行Memcache的用户,我这里是root,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.0.200,
-p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid
3、连接memcached服务器
#telnet 127.0.0.1 20001
#set key1 0 60 4
zhou
#get key1
#add userId 0 0 5
zhou
#replace userId 0 0 5
wu
#delete wu
#gets userId
#cas userId 0 0 5 6
wang
#stats
#flush_all
#quit
4、memcached自启动脚本
- #!/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/src/memcached-1.4.14/memcached -u daemon -d -m 1024 -l 127.0.0.1 -p 58728
- echo
- }
- stop()
- {
- echo -n $"Shutting down memcached: "
- killproc memcached
- echo
- }
- [ -f /usr/local/src/memcached-1.4.14/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
来源: <http://www.cnblogs.com/technet/archive/2011/09/11/2173485.html>
新建/etc/init.d/memcached文件
#chmod u+x memcached
#chkconfig --add memcached
#chkconfig --add memcached
#chkconfig --level 235 memcached on
#service memcached start/stop/restart
#/etc/init.d/memcached start/stop/restart
5、Java客户端Xmemcached与spring集成
Xmemcached在多线程下效果更好。
spring配置文件如下:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="xmemcachedDao" class="com.iqiyi.itv.terminal4.memcache.dao.XMemcachedDao">
<property name="memCachedClientList">
<list>
<ref bean="memcachedClient1" />
</list>
</property>
</bean>
<bean name="memcachedClientBuilder1" class="net.rubyeye.xmemcached.XMemcachedClientBuilder">
<constructor-arg>
<list>
<bean class="java.net.InetSocketAddress">
<constructor-arg>
<value>192.168.58.130</value> <!--虚拟机IP-->
</constructor-arg>
<constructor-arg>
<value>20001</value>
</constructor-arg>
</bean>
</list>
</constructor-arg>
<constructor-arg>
<list>
<value>1</value>
</list>
</constructor-arg>
<property name="connectionPoolSize" value="8"></property>
<property name="sessionLocator">
<bean class="net.rubyeye.xmemcached.impl.KetamaMemcachedSessionLocator"></bean>
</property>
<property name="transcoder">
<bean class="net.rubyeye.xmemcached.transcoders.SerializingTranscoder">
<property name="compressionThreshold" value="1048576"></property>
</bean>
</property>
<property name="bufferAllocator">
<bean class="net.rubyeye.xmemcached.buffer.SimpleBufferAllocator"></bean>
</property>
</bean>
<bean name="memcachedClient1" factory-bean="memcachedClientBuilder1"
factory-method="build" destroy-method="shutdown">
<property name="opTimeout" value="30000"></property>
</bean>
<beans>
获取到memcachedClient就可以进行add、set、delete、replace等操作。
0 0
- memcached 的总结
- Redis PK Memcached的总结
- 【学习总结-memcached】 memcached的总结和分布式一致hash
- memcached总结
- memcached 总结
- memcached总结
- 对Memcached的使用的总结
- memcached完全剖析--1. memcached的基础 和 memcached全面剖析--PDF总结篇
- memcached总结和与spring的集成
- redis和memcached的区别与总结
- memcached的总结和分布式一致性hash
- nginx+tomcat+memcached不成功的总结
- Redis和Memcached的区别(总结)
- redis和memcached的区别(总结)
- redis和memcached的区别(总结)
- redis和memcached的区别(总结)
- redis和memcached的区别(总结)
- 【memcached】memcached的分布式
- Java程序执行Linux命令调用EasyPR程序识别车牌号
- 【Cherry云计算】阿里云产品体系
- CCS如何打开已建好的工程
- 浏览器console调试
- 网络环境较差时,优化网络加载图片
- memcached 的总结
- 并查集讲解
- jdk下载与安装
- Mathematician QSC(欧拉定理+矩阵快速幂)
- mean-shift based tracking回顾
- 数据挖掘
- gdiplus exception
- Intellij idea:Method breakpoints my dramatically slow down debugging
- 深度学习笔记3torch实现多层感知器