Memcached 安裝及啓動腳本

解析:Memcached是什麼? 
Memcached是由Danga Interactive開發的,高性能的,分佈式的內存對象緩存系統,用於在動態應用中減小數據庫負載,提高訪問速度。數據庫

1、軟件版本緩存

    libevent 穩定版安全

wget http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz

    memcached 穩定版bash

wget  http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz

2、軟件安裝分佈式

    Libevent安裝ide

[root@jw-test01 software]# tar zxvf libevent-1.4.14b-stable.tar.gz
[root@jw-test01 software]# cd libevent-1.4.14b-stable
[root@jw-test01 libevent]# ./configure --prefix=/usr/local/libevent/
[root@jw-test01 libevent]# make
[root@jw-test01 libevent]# make install

   Memcached安裝 memcached

[root@jw-test01 software]# tar -zxvf memcached-1.4.5.tar.gz
[root@jw-test01 software]# cd memcached-1.4.5
[root@jw-test01 memcached]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
[root@jw-test01 memcached]# make
[root@jw-test01 memcached]# make install

3、編寫Memcached啓動腳本性能

#!/bin/bash
# author:kuangl
# date:2013-05-30
# description: Starts and stops the Memcached services.
# pidfile: /tmp/memcached1.pid
# config:  /usr/local/memcached
# chkconfig: - 55 45
# source function library
. /etc/rc.d/init.d/functions
memcached="/usr/local/memcached/bin/memcached"
[ -e $memcached ] || exit 1
start()
{
echo "Starting memcached:"
daemon $memcached -d -m 1000 -u root -l 127.0.0.1 -p 11211 -c 1500 -P /tmp/memcached1.pid
}
stop()
{
echo "Shutting down memcached"
killproc memcached
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?

4、將腳本複製到init.d目錄下google

[root@jw-test01 scripts]# cp memcached.sh /etc/init.d/memcached

5、將memcached加入系統啓項spa

[root@jw-test01 scripts]# chkconfig  --add memcached
[root@jw-test01 scripts]# chkconfig --level 35 memcached on

6、啓動memcached 

[root@jw-test01 scripts]# service memcached restart
Shutting down memcached       [肯定]
Starting memcached:           [肯定]
[root@jw-test01 scripts]# ps -ef |grep memcached
root     27616     1  0 22:18 ?        00:00:00 /usr/local/memcached/bin/memcached -d -m 1000 -u root -l 127.0.0.1 -p 11211 -c 1500 -P /tmp/memcached1.pid

7、Memcached經常使用參數

參數 說明
-p <num> 設置端口號(默認不設置爲: 11211)
-U <num> UDP監聽端口(默認: 11211, 0 時關閉)
-l <ip_addr> 綁定地址(默認:全部都容許,不管內外網或者本機更換IP,有安全隱患,若設置爲127.0.0.1就只能本機訪問)
-d 獨立進程運行
-u <username> 綁定使用指定用於運行進程<username>
-m <num> 容許最大內存用量,單位M (默認: 64 MB)
-P <file> PID寫入文件<file>,這樣可使得後邊進行快速進程終止須要與-d 一塊兒使用
相關文章
相關標籤/搜索