设为首页 收藏本站
查看: 1602|回复: 0

[经验分享] Memcached1.4安装笔记

[复制链接]

尚未签到

发表于 2015-11-19 08:40:39 | 显示全部楼层 |阅读模式
系统安装需求,CentOS6.5,能连接互联网,下面是安装步骤
1.yum install libevent-devel

2.wget http://memcached.org/latest

3.wget http://www.memcached.org/files/memcached-1.4.20.tar.gz
下载最新的安装文件memcached-1.4.20.tar.gz
4.tar -zxvf memcached-1.4.20.tar.gz
5.cd memcached-1.4.20
6。       ./configure && make && make test && sudo make install

提示报错:
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/opt/memcached-1.4.20':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.

7.yum -y install gcc
系统会下载gcc安装包,自动安装。时间较漫长,大约装30分钟。(只能吐槽国内网速)
8.yum -y install gcc-c++
再下一遍安装包,这次速度快点。

9。再次执行第6步,直到看到成功编译的提示。
......
prove ./t
make: prove: Command not found
make: *** [test] Error 127

10.第9步报错误, 重新执行make install
没有提示错误。


11.启动和停止memcached
# ./memcached -d -m 1024 -u root -l 10.11.1.219 -p 11211 -c 256 -P /tmp/memcached.pid //启动memcached 启动参数说明:

   启动参数说明:
   -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版本新增)

  也可以启动多个守护进程,但是端口不能重复


停止Memcache进程:
   kill `cat /tmp/memcached.pid`

12.测试memcached,
使用另外一台机器,telnet 10.11.1.219 11211
如果需要,先关闭linux防火墙。关闭linux防火墙的命令:service iptables stop

连接成功输入命令:
stats

显示正常结果,说明服务成功启动了。
stats
STAT pid 2940
STAT uptime 407
STAT time 1409821965
STAT version 1.4.20
STAT libevent 1.4.13-stable
STAT pointer_size 64
STAT rusage_user 0.000000
STAT rusage_system 0.029995
STAT curr_connections 5
STAT total_connections 6
STAT connection_structures 6
STAT reserved_fds 20
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0

13。java客户端上的开发
java memcached client下载地址https://github.com/gwhalin/Memcached-Java-Client/downloads
将下载的ava_memcached-release_2.6.6.zip解压,jar包全部导入到java项目。

测试程序:
import java.util.ArrayList;

import com.danga.MemCached.*;

public class MyClass {
    // create a static client as most installs only need
    // a single instance
    protected static MemCachedClient mcc = new MemCachedClient();
    // set up connection pool once at class load
    static {
        // server list and weights
//        String[] servers = { &quot;server1.mydomain.com:1624&quot;,
//                &quot;server2.mydomain.com:1624&quot;, &quot;server3.mydomain.com:1624&quot; };
        String[] servers = { &quot;10.11.1.219:11211&quot; };        
//        Integer[] weights = { 3, 3, 2 };
        Integer[] weights = { 3};
        // grab an instance of our connection pool
        SockIOPool pool = SockIOPool.getInstance();
        // set the servers and the weights
        pool.setServers(servers);
        pool.setWeights(weights);
        // set some basic pool settings
        // 5 initial, 5 min, and 250 max conns
        // and set the max idle time for a conn
        // to 6 hours
        pool.setInitConn(5);
        pool.setMinConn(5);
        pool.setMaxConn(250);
        pool.setMaxIdle(1000 * 60 * 60 * 6);
        // set the sleep for the maint thread
        // it will wake up every x seconds and
        // maintain the pool size
        pool.setMaintSleep(30);
        // set some TCP settings
        // disable nagle
        // set the read timeout to 3 secs
        // and don't set a connect timeout
        pool.setNagle(false);
        pool.setSocketTO(3000);
        pool.setSocketConnectTO(0);
        // initialize the connection pool
        pool.initialize();
        // lets set some compression on for the client
        // compress anything larger than 64k
//        mcc.setCompressEnable(true);
//        mcc.setCompressThreshold(64 * 1024);
    }

    // from here on down, you can call any of the client calls
    public static void examples() {
        mcc.set(&quot;foo&quot;, &quot;This is a test String&quot;);
        ArrayList a1=new ArrayList();
        a1.add(0);
        a1.add(388);
        a1.add(989);
        a1.add(&quot;中文内容&quot;);
        
        mcc.set(&quot;foo2&quot;, a1);
        String bar = (String)mcc.get(&quot;foo&quot;);
        ArrayList a2 = (ArrayList)mcc.get(&quot;foo2&quot;);
        System.out.println(bar);
        System.out.println(a2.toString());
        
    }
   
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        MyClass cs1=new MyClass();
        cs1.examples();
    }
   
}

运行结果:
This is a test String
[0, 388, 989, 中文内容]
说明:本程序在jdk7下测试通过,由于只使用了一个节点的memcached ,所以去掉了集群配置。         版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-140898-1-1.html 上篇帖子: Redis缓存、MemCached和.Net内部缓存的切换使用 下篇帖子: tlinux(CentOS)下memcached 安装与使用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表