Linux下安裝Memcache
阿新 • • 發佈:2019-02-13
Linux下的Memcache安裝
準備安裝程式
memcached-1.4.20.tar.gz memcache伺服器端
libevent的最新版本是libevent-2.0.21
libevent
官網:http://libevent.org/
下載地址:https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
memcache
官網:http://www.memcached.org/
下載地址:http://memcached.org/latest
安裝Memcached步驟:
1.編譯安裝Libevent
# wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
# tar -zxvf libevent-2.0.21-stable.tar.gz
# cd libevent-2.0.21-stable
# ./configure -prefix=/usr/local/libevent && make && make test && sudo make install
如果提示如下錯誤:
configure: error: in `/opt/memcached/libevent-2.0.21-stable':
configure: error: no acceptable C compiler found in $PATH
因為是centos linux,預設可以採用yum方式安裝,則採用如下命令安裝gcc編譯器即可:
# yum -y install gcc
測試是否安裝成功
# ls -alR /usr/local/libevent | grep libevent
2.編譯安裝Memcache
# wget http://www.memcached.org/files/memcached-1.4.21.tar.gz
# tar -zxvf memcached-1.4.21.tar.gz
# cd memcached-1.4.21
# ./configure --with-libevent=/usr/local/libevent 或者指定目錄安裝./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
# make && make test && sudo make install
測試是否成功安裝memcached:
# ls -al /usr/local/bin/mem*
-rwxr-xr-x 1 root root 249785 05-10 18:09 /usr/local/bin/memcached
7.memcached的基本設定:
1.啟動Memcached的伺服器端:
/usr/local/bin/memcached -d -m 100 -u root -l 192.168.0.111 -p 12000 -c 512 -P /MEMPID/ memcached.pid
-d選項是啟動一個守護程序,
-m是分配給Memcache使用的記憶體數量(預設:64MB),單位是MB,我這裡是10MB,
-u是執行Memcache的使用者,我這裡是root,
-l監聽伺服器IP地址,如果有多個地址的話,這裡指定了伺服器IP地址192.168.70.178
-p是設定Memcache監聽的埠(預設:11211),我這裡設定了12000,最好是1024以上的埠,
-c選項是最大執行的併發連線數,預設是1024,此次512,按照伺服器的負載量來設定,
-P是設定儲存Memcache的pid檔案,我這裡是儲存在 / MEMPID/ memcached.pid
2.檢查是否執行成功
ps -ef|grep memcached 或者 ps aux|grep memcached
3.連線到 memcached:
telnet ip 埠,如telnet 192.168.0.111 12000
(沒有安裝telnet可以參考如下頁面操作:http://jingyan.baidu.com/album/9f63fb91ac7ebcc8400f0e94.html?picindex=1)
stats檢視狀態,flush_all:清楚快取
4.停止memcached
kill -9 pid (-9表示強制殺死,pid 為程序的程序識別符號)
kill ‘cat MEMPID/ memcached.pid’
killall memcached #殺死所有memcache程序
到這裡 memcached就已經安裝好了。
增加到開機啟動
# vi /etc/rc.local
增加:
/usr/local/bin/memcached -d -m 100 -u root -l 192.168.0.111 -p 12000 -c 512 -P /MEMPID/ memcached.pid
準備安裝程式
memcached-1.4.20.tar.gz memcache伺服器端
libevent的最新版本是libevent-2.0.21
libevent
官網:http://libevent.org/
下載地址:https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
memcache
官網:http://www.memcached.org/
下載地址:http://memcached.org/latest
安裝Memcached步驟:
1.編譯安裝Libevent
# wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
# tar -zxvf libevent-2.0.21-stable.tar.gz
# cd libevent-2.0.21-stable
# ./configure -prefix=/usr/local/libevent && make && make test && sudo make install
如果提示如下錯誤:
configure: error: in `/opt/memcached/libevent-2.0.21-stable':
configure: error: no acceptable C compiler found in $PATH
因為是centos linux,預設可以採用yum方式安裝,則採用如下命令安裝gcc編譯器即可:
# yum -y install gcc
測試是否安裝成功
# ls -alR /usr/local/libevent | grep libevent
2.編譯安裝Memcache
# wget http://www.memcached.org/files/memcached-1.4.21.tar.gz
# tar -zxvf memcached-1.4.21.tar.gz
# cd memcached-1.4.21
# ./configure --with-libevent=/usr/local/libevent 或者指定目錄安裝./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
# make && make test && sudo make install
測試是否成功安裝memcached:
# ls -al /usr/local/bin/mem*
-rwxr-xr-x 1 root root 249785 05-10 18:09 /usr/local/bin/memcached
7.memcached的基本設定:
1.啟動Memcached的伺服器端:
/usr/local/bin/memcached -d -m 100 -u root -l 192.168.0.111 -p 12000 -c 512 -P /MEMPID/ memcached.pid
-d選項是啟動一個守護程序,
-m是分配給Memcache使用的記憶體數量(預設:64MB),單位是MB,我這裡是10MB,
-u是執行Memcache的使用者,我這裡是root,
-l監聽伺服器IP地址,如果有多個地址的話,這裡指定了伺服器IP地址192.168.70.178
-p是設定Memcache監聽的埠(預設:11211),我這裡設定了12000,最好是1024以上的埠,
-c選項是最大執行的併發連線數,預設是1024,此次512,按照伺服器的負載量來設定,
-P是設定儲存Memcache的pid檔案,我這裡是儲存在 / MEMPID/ memcached.pid
2.檢查是否執行成功
ps -ef|grep memcached 或者 ps aux|grep memcached
3.連線到 memcached:
telnet ip 埠,如telnet 192.168.0.111 12000
(沒有安裝telnet可以參考如下頁面操作:http://jingyan.baidu.com/album/9f63fb91ac7ebcc8400f0e94.html?picindex=1)
stats檢視狀態,flush_all:清楚快取
4.停止memcached
kill -9 pid (-9表示強制殺死,pid 為程序的程序識別符號)
kill ‘cat MEMPID/ memcached.pid’
killall memcached #殺死所有memcache程序
到這裡 memcached就已經安裝好了。
增加到開機啟動
# vi /etc/rc.local
增加:
/usr/local/bin/memcached -d -m 100 -u root -l 192.168.0.111 -p 12000 -c 512 -P /MEMPID/ memcached.pid