一、準備工作:
1.下載libevent:http://monkey.org/~provos/libevent/ (由於memcached與客戶端的通信是藉助libevent來實現的,所以此動作必須在memcached安裝前完成)
2.下載memcached:http://memcached.org/ (注意:memcache是由服務器端和客戶端共同組成,此處指memcache的服務器端,客戶端在memcache的官網也提供了下載地址)
二、libevent安裝:
1.解壓libevent安裝包:
shell > tar zxvf libevent-2.0.10-stable.tar.gz
2.進入解壓後的目錄並執行如下命令:
shell > ./configure (或./configure --prefix=libevent安裝目錄,默認安裝目錄爲/usr/local/lib)
shell > make && make install
3.查看安裝是否成功
測試libevent是否安裝成功:ls -al /usr/lib | grep libevent(或 ls -al /usr/local/lib | grep libevent)
4.Now we need to update /etc/ld.so.conf.d/libevent-i386.conf to add the path information for libevent. Use your favorite editor to edit /etc/ld.so.conf.d/libevent-i386.conf and add the following line if it doesn’t exist:
/usr/local/lib/,and then run ldconflg
注意:向libevent-i386.conf中添加的是libevent庫的安裝目錄(如:/usr/local/lib);ldconfig是一個動態鏈接庫管理命令
三、Memcached安裝:
1.解壓memcached安裝目錄:
shell > tar zxvf memcached-1.4.5.tar.gz
2.進入解壓後的目錄並執行如下命令:
shell > ./configure (或./configure --with-libevent=libevent安裝目錄
--prefix=memcached安裝目錄,默認安裝在/usr/local/bin目錄下)
shell > make && make install
3.測試memcached安裝是否成功:
shell > memcached -u root -vv後出現如下畫面則說明成功:
四、配置memcached自啓動
1.編寫memcached自啓動腳本或直接使用memcached安裝包中的腳本(位置如下,本文使用官方自帶的腳本)
2.修改自啓動腳本(紅色部分標識)
#! /bin/sh # # chkconfig: - 55 45 # description: The memcached daemon is a network memory cache service. # processname: memcached # config: /etc/sysconfig/memcached # Source function library. . /etc/rc.d/init.d/functions PORT=11211 USER=root MAXCONN=1024 CACHESIZE=64 OPTIONS="" if [ -f /etc/sysconfig/memcached ];then . /etc/sysconfig/memcached fi # Check that networking is up. if [ "$NETWORKING" = "no" ] then exit 0 fi RETVAL=0 start () { echo "Starting memcached ..." # insure that /var/run/memcached has proper permissions chown $USER /usr/local/bin/memcached /usr/local/bin/memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcached.pid $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached } stop () { echo "Stopping memcached ..." killproc memcached RETVAL=$? echo if [ $RETVAL -eq 0 ] ; then rm -f /var/lock/subsys/memcached rm -f /var/run/memcached.pid fi } restart () { stop start } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status memcached ;; restart|reload) restart ;; condrestart) [ -f /var/lock/subsys/memcached ] && restart || : ;; *) echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}" exit 1 esac exit $? |
3.將此腳本呢cp到/etc/init.d目錄下並改名爲memcached,然後執行chmod a+x memcached,如下:
shell > cp memcached.sysv /etc/init.d/memcached
shell > chmod 755 /etc/init.d/memcached
4.將memcached加入系統服務:
shell > chkconfig --add memcached
shell > chkconfig memcached on
5.以服務方式運行memcached
shell > service memcached start
以上如成功則重啓下系統後查看下memcached是否已隨系統啓動