linux 在64位安裝memcached問題解決

來源:互聯網
上載者:User

1.安裝memcached所依賴的libevent

官網:http://libevent.org/

解壓源碼包至/usr/local,進入解壓後的目錄,執行:
./configure
make
make install

configure檔案中的預設prefix是/usr/local,因此,安裝完成之後,你可以在/usr/local/bin 和 /usr/local/lib 下找到libevent的相關檔案

2.安裝memcached

官網:http://code.google.com/p/memcached/

解壓源碼包至/usr/local,進入解壓後的目錄,執行:
./configure
make
make install
configure檔案中的預設prefix也是/usr/local,因此,安裝完成之後,你可以在/usr/local/bin 和 /usr/local/lib 下找到memcached的相關檔案

3.解決:memcached: error while loading shared libraries: libevent-2.0.so.5 錯誤

當安裝完成後,啟動程式memcached -m 128   -l 10.250.2.18  -p 11211卻發現報錯:

memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory

解決辦法:執行命令 ldd /usr/local/bin/memcached

[root@localhost memcached-1.4.15]# ldd /usr/local/bin/memcached
linux-vdso.so.1 =>  (0x00007fff04b24000)
libhugetlbfs.so => /usr/lib64/libhugetlbfs.so (0x00007f1458609000)
libevent-2.0.so.5 =>
/usr/lib64/libevent-2.0.so.5 (0x00007f14583c4000)
librt.so.1 => /lib64/librt.so.1 (0x000000384e600000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x000000384da00000)
libc.so.6 => /lib64/libc.so.6 (0x000000384d600000)
libdl.so.2 => /lib64/libdl.so.2 (0x000000384d200000)
/lib64/ld-linux-x86-64.so.2 (0x000000384ce00000)
[root@localhost memcached-1.4.15]# 

發現64位下載入的目錄為/usr/lib64/,我們已經知道當前安裝的程式路徑為 /usr/local/lib/libevent-2.0.so.5.1.9 故執行命令

ln -s /usr/local/lib/libevent-2.0.so.5.1.9  /usr/lib64/libevent-2.0.so.5 即可正常啟動了

memcached -m 128   -l 10.250.2.18  -p 11211

參數說明: 
      -d 啟動守護進程(後台運行) 
      -m 分配給memcache使用的記憶體,單位是MB 
      -u 運行memcached的使用者 
      -l 監聽的伺服器IP 
      -p 監聽的伺服器連接埠,預設是11211
      -c 最大啟動並執行並發串連數,預設是1024
      -P(大寫) 儲存Memcache的pid檔案,後面跟路徑

4.檢查安裝情況

下載 java-memcached-2.5.1.jar,編寫測試程式:


import com.danga.MemCached.MemCachedClient;
import com.danga.MemCached.SockIOPool;

public class TestMemcached {

    public static void main(String[] args) {

        /** 初始化SockIOPool,管理memcached的串連池 **/
        String[] servers = { "10.250.2.18:11211" };// 主機10.250.2.18,連接埠11211
        SockIOPool pool = SockIOPool.getInstance();
        pool.setServers(servers);
        pool.setFailover(true);
        pool.setInitConn(10);
        pool.setMinConn(5);
        pool.setMaxConn(250);
        pool.setMaintSleep(30);
        pool.setNagle(false);
        pool.setSocketTO(3000);
        pool.setAliveCheck(true);
        pool.initialize();

        /** 建立MemcachedClient執行個體 **/
        MemCachedClient memCachedClient = new MemCachedClient();
        for (int i = 0; i < 10; i++) {
            /** 將對象加入到memcached緩衝 **/
            boolean success = memCachedClient.set("" + i, "Hello!");
            /** 從memcached緩衝中按key值取對象 **/
            String result = (String) memCachedClient.get("" + i);
            System.out.println(String.format("set( %d ): %s", i, success));
            System.out.println(String.format("get( %d ): %s", i, result));
        }
    }

}


運行 結果:

com.schooner.MemCached.SchoonerSockIOPool Fri Jun 14 16:00:32 CST 2013 - ++++ failed to get SockIO obj for: 10.250.2.18:11211
set( 0 ): false
get( 0 ): null

串連 失敗,原來是新裝的linux上沒有關閉iptables使用 service iptables stop

[root@localhost ~]# service iptables stop
iptables:清除防火牆規則:                                 [確定]
iptables:將鏈設定為政策 ACCEPT:filter                    [確定]
iptables:正在卸載模組:                                   [確定]
[root@localhost ~]#

再次運行:

set( 0 ): true
get( 0 ): Hello!
set( 1 ): true
get( 1 ): Hello!

....

運行 成功!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.