操作系統(tǒng):CentOS release 6.8 (Final)
成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比北鎮(zhèn)網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式北鎮(zhèn)網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋北鎮(zhèn)地區(qū)。費用合理售后完善,十余年實體公司更值得信賴。虛擬機:VM
任務(wù):服務(wù)與客戶端在一臺虛擬機主安裝和配置。
Memcached 是一個高性能的分布式內(nèi)存對象緩存系統(tǒng),用于動態(tài)Web應(yīng)用以減輕數(shù)據(jù)庫負載。它通過在內(nèi)存中緩存數(shù)據(jù)和對象來減少讀取數(shù)據(jù)庫的次數(shù),從而提高動態(tài)、數(shù)據(jù)庫驅(qū)動網(wǎng)站的速度。
Memcached服務(wù)安裝
[root@localhost ~]# yum install libevent libevent-devel nc –y
[root@localhost ~]# rpm -qa libevent libevent-devel nc
libevent-1.4.13-4.el6.x86_64
libevent-devel-1.4.13-4.el6.x86_64
nc-1.84-24.el6.x86_64
#可以通過yum安裝或編譯安裝,yum安裝的版本比較低,可以從官網(wǎng)上下載安裝下載最新版本編譯安裝http://memcached.org/downloads或者http://pecl.php.net/package/memcached
[root@localhost ~]# yum install memcached –y
[root@localhost ~]# which memcached
/usr/bin/memcached
[root@localhost ~]# memcached -m 16m -p 11211 -d -u root -c 8192 #啟動第一個實例
[root@localhost ~]# lsof -i:11211 #查看啟動情況
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
memcached 1857 root 26u IPv4 14225 0t0 TCP *:memcache (LISTEN)
memcached 1857 root 27u IPv6 14226 0t0 TCP *:memcache (LISTEN)
memcached 1857 root 28u IPv4 14229 0t0 UDP *:memcache
memcached 1857 root 29u IPv6 14230 0t0 UDP *:memcache
[root@localhost ~]# ps -ef|grep memcached|grep -v grep #查看進程
root 1857 1 0 19:14 ? 00:00:00 memcached -m 16m -p 11211 -d -u root -c 8192
[root@localhost ~]# memcached -m 16m -p 11212 -d -u root -c 8192 #啟動第二個實例
[root@localhost ~]# ps -ef|grep memcached|grep -v grep
root 1857 1 0 19:14 ? 00:00:00 memcached -m 16m -p 11211 -d -u root -c 8192
root 1868 1 0 19:15 ? 00:00:00 memcached -m 16m -p 11212 -d -u root -c 8192
[root@localhost ~]# lsof -i :11211
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
memcached 1737 root 26u IPv4 12689 0t0 TCP *:memcache (LISTEN)
memcached 1737 root 27u IPv6 12690 0t0 TCP *:memcache (LISTEN)
memcached 1737 root 28u IPv4 12693 0t0 UDP *:memcache
memcached 1737 root 29u IPv6 12694 0t0 UDP *:memcache
[root@localhost ~]# lsof -i :11212
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
memcached 1739 root 26u IPv4 12698 0t0 TCP *:11212 (LISTEN)
memcached 1739 root 27u IPv6 12699 0t0 TCP *:11212 (LISTEN)
memcached 1739 root 28u IPv4 12702 0t0 UDP *:11212
memcached 1739 root 29u IPv6 12703 0t0 UDP *:11212
[root@localhost ~]# tail -2 /etc/rc.local
[root@localhost ~]# vi /etc/rc.local #開機可以自動啟動兩個實例
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
memcached -m 16m -p 11211 -d -u root -c 8192
memcached -m 16m -p 11212 -d -u root -c 8192
------------------------------------------------------------------------
memcached參數(shù)說明:
-d選項是啟動一個守護進程
-m是分配給Memcache使用的內(nèi)存數(shù)量,單位是MB,我這里是16MB
-u是運行Memcache的用戶,我這里是root
-l是監(jiān)聽的服務(wù)器IP地址
-p是設(shè)置Memcache監(jiān)聽的端口,最好是1024以上的端口
-c選項是大運行的并發(fā)連接數(shù),默認是1024,按照你服務(wù)器的負載量來設(shè)定
-P是設(shè)置保存Memcache的pid文件
其他參數(shù)省略說明。
[root@localhost ~]# chkconfig --level 2345 memcached on #開機啟動服務(wù)
#向memcached中寫入數(shù)據(jù)
[root@localhost ~]# printf "set key1 0 0 6\r\n skyboy\r\n"|nc 127.0.0.1 11211
CLIENT_ERROR bad data chunk
ERROR
[root@localhost ~]# printf "set key1 0 0 6\r\nskyboy\r\n"|nc 127.0.0.1 11211
STORED
[root@localhost ~]# printf "set key2 0 0 5\r\nskyboy\r\n"|nc 127.0.0.1 11211
CLIENT_ERROR bad data chunk
ERROR
[root@localhost ~]# printf "get key1\r\n"|nc 127.0.0.1 11211
VALUE key1 0 6
skyboy
END
[root@localhost ~]# printf "delete key1\r\n"|nc 127.0.0.1 11211
DELETED
[root@localhost ~]# printf "get key1\r\n"|nc 127.0.0.1 11211
END
通過telnet命令寫入數(shù)據(jù)
Connection closed by foreign host.
[root@localhost ~]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
set user01 0 0 7
oldgirl
STORED
get user01
VALUE user01 0 7
oldgirl
END
delete user01
DELETED
get user01
END
quit
Connection closed by foreign host.
安裝Memcached客戶端
http://pecl.php.net/package/memcache#下載所有版本地址
[root@localhost tools]#wgethttp://pecl.php.net/get/memcache-2.2.4.tgz
[root@localhost tools]# tar zxf memcache-2.2.4.tgz
[root@localhost tools]# cd memcache-2.2.4
[root@localhost memcache-2.2.4]#
#phpize是用來擴展PHP擴展模塊的,通過phpize可以建立PHP的外掛模塊。
[root@localhost memcache-2.2.4]# /application/php/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
[root@localhost memcache-2.2.4]# ./configure --enable-memcache \
--with-php-config=/application/php/bin/php-config
[root@localhost memcache-2.2.4]# make
[root@localhost memcache-2.2.4]# make install
Installing shared extensions: /application/php5.3.27/lib/php/extensions/no-debug-non-zts-20090626/
[root@localhost memcache-2.2.4]# ls /application/php/lib/php/extensions/no-debug-non-zts-20090626/
memcache.so #生成了.so模塊
[root@localhost memcache-2.2.4]#cd /application/php/lib/
[root@localhost lib]# vi php.ini #在末尾添加以下兩行
extension_dir="/application/php/lib/php/extensions/no-debug-non-zts-20090626/"
extension=memcache.so
[root@localhost lib]# /application/php/sbin/php-fpm -t #檢查語法
[19-Jan-2017 19:50:52] NOTICE: configuration file /application/php5.3.27/etc/php-fpm.conf test is successful
[root@localhost lib]# /application/php/sbin/php-fpm #啟動服務(wù)
[root@localhost lib]# ps -ef|grep php-fpm|grep -v grep
root 4624 1 0 19:51 ? 00:00:00 php-fpm: master process (/application/php5.3.27/etc/php-fpm.conf)
nginx 4625 4624 0 19:51 ? 00:00:00 php-fpm: pool www
nginx 4626 4624 0 19:51 ? 00:00:00 php-fpm: pool www
重啟fpm
[root@localhost ~]# pkill php-fpm
[root@localhost ~]# ps -ef|grep php-fpm|grep -v grep
[root@localhost ~]# /application/php/sbin/php-fpm
[root@localhost ~]# ps -ef|grep php-fpm|grep -v grep
root 2186 1 0 23:39 ? 00:00:00 php-fpm: master process (/application/php5.3.27/etc/php-fpm.conf)
nginx 2187 2186 0 23:39 ? 00:00:00 php-fpm: pool www
nginx 2188 2186 0 23:39 ? 00:00:00 php-fpm: pool www
測試Memcached客戶端安裝是否成功?http://192.168.222.130/phpinfo.php
Phpinfo.php文件內(nèi)容如下:
<?php
Phpinfo();
?>
測試LNMP環(huán)境是否連接Memcached服務(wù)成功?
[root@localhost www]# vi op_mem.php
<?php
$memcache=new memcache;
$memcache->connect('192.168.222.130',11211) or die ("Could not connect Mc Server");
$memcache->set('key','學習Memcached');
$get=$memcache->get('key');
echo $get;
?>
[root@localhost www]# /application/php/bin/php op_mem.php
學習Memcached
或者瀏覽器訪問:http://192.168.222.130/op_mem.php
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
分享標題:Memcached安裝配置-創(chuàng)新互聯(lián)
網(wǎng)頁路徑:http://jinyejixie.com/article26/peicg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、手機網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、服務(wù)器托管、網(wǎng)站策劃、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)