linux安裝memcached服務

1. 準備安裝文件node

下載memcached與libevent的安裝文件linux

libevent-2.0.21-stable.tar.gzbash

memcached-server-1.4.31.tar.gz服務器

2. 具體安裝步驟併發

1.因爲memcached依賴於libevent,所以須要安裝libevent。因爲linux系統可能默認已經安裝libevent,執行命令:memcached

rpm -qa|grep libevent.net

查看系統是否帶有該安裝軟件,若是有執行命令:rest

rpm -e libevent-1.4.13-4.el6.x86_64 --nodeps(因爲系統自帶的版本舊,忽略依賴刪除)code

3. 安裝libevent命令:server

[root@localhost mysoft]# tar -zxvf libevent-2.0.21-stable.tar.gz 
[root@localhost mysoft]# cd libevent-2.0.21-stable
[root@localhost libevent-2.0.21-stable]# ./configure --prefix=/usr/local/libevent
[root@localhost libevent-2.0.21-stable]# make
[root@localhost libevent-2.0.21-stable]# make install

至此libevent安裝完畢;

安裝過程當中出現:configure: error : no acceptable C compiler found in $PATH錯誤時是沒有安裝gcc,運行以下命令:

yum install gcc* make*

4. 安裝memcached命令:

[root@localhost mysoft]# tar -zxvf memcached-1.4.31.tar.gz 
[root@localhost memcached-1.4.31]# cd memcached-1.4.31
[root@localhost memcached-1.4.31]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
[root@localhost memcached-1.4.31]# make
[root@localhost memcached-1.4.31]# make install

5.當啓動memcached時常常不能發現libevent.so;能夠經過如下命令檢查:

   進入/usr/local/memcached/bin目錄

LD_DEBUG=help
./memcached -v
LD_DEBUG=libs  ./ memcached -v
解決方法:
ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /lib64/libevent-2.0.so.5

6. 啓動memcached
1.打開一個終端,輸入如下命令:
./usr/local/memcached/bin/memcached -d -m 256 -u root -l 192.168.1.1 -p 11211 -c 1024 –P /tmp/memcached.pid

7. 編寫啓動腳本

#!/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/memcached/bin/memcached -d -m 256 -u root -l 10.26.240.137 -p 11211 -c 1024 -P /tmp/memcached.pid
        echo   
}   
    
stop()    
{   
        echo -n $"Shutting down memcached: "  
        killproc memcached    
        echo   
}   
    
[ -f /usr/local/bin/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

 8. 添加的服務

[root@localhost ~]# chkconfig  --add memcached 
[root@localhost ~]# chkconfig  --level 235  memcached  on
[root@localhost ~]# chkconfig  --list | grep mem
memcached       0:off   1:off   2:on   3:on    4:off   5:on   6:off

接下來,能夠用如下命令啓動與中止 memcached

/etc/rc.d/init.d/memcached  start      ## 啓動
/etc/rc.d/init.d/memcached  stop      ## 中止
/etc/rc.d/init.d/memcached  restart   ## 重啓

[root@localhost ~]# /etc/rc.d/init.d/memcached  restart
Shutting down memcached: [  OK  ]
Starting memcached:      [  OK  ]


啓動參數說明:
-d 選項是啓動一個守護進程。
-u root 表示啓動memcached的用戶爲root。
-m 是分配給Memcache使用的內存數量,單位是MB,默認64MB。
-M return error on memory exhausted (rather than removing items)。
-u 是運行Memcache的用戶,若是當前爲root 的話,須要使用此參數指定用戶。
-p 是設置Memcache的TCP監聽的端口,最好是1024以上的端口。
-c 選項是最大運行的併發鏈接數,默認是1024。
-P 是設置保存Memcache的pid文件。

-l是監聽的服務器IP地址,若是有多個地址的話,我這裏指定了服務器的IP地址192.168.0.200,

相關文章
相關標籤/搜索