新聞中心
1.簡(jiǎn)介

創(chuàng)新互聯(lián)建站是一家網(wǎng)站設(shè)計(jì)公司,集創(chuàng)意、互聯(lián)網(wǎng)應(yīng)用、軟件技術(shù)為一體的創(chuàng)意網(wǎng)站建設(shè)服務(wù)商,主營(yíng)產(chǎn)品:成都響應(yīng)式網(wǎng)站建設(shè)公司、品牌網(wǎng)站建設(shè)、網(wǎng)絡(luò)營(yíng)銷(xiāo)推廣。我們專注企業(yè)品牌在網(wǎng)站中的整體樹(shù)立,網(wǎng)絡(luò)互動(dòng)的體驗(yàn),以及在手機(jī)等移動(dòng)端的優(yōu)質(zhì)呈現(xiàn)。網(wǎng)站制作、網(wǎng)站建設(shè)、移動(dòng)互聯(lián)產(chǎn)品、網(wǎng)絡(luò)運(yùn)營(yíng)、VI設(shè)計(jì)、云產(chǎn)品.運(yùn)維為核心業(yè)務(wù)。為用戶提供一站式解決方案,我們深知市場(chǎng)的競(jìng)爭(zhēng)激烈,認(rèn)真對(duì)待每位客戶,為客戶提供賞析悅目的作品,網(wǎng)站的價(jià)值服務(wù)。
1.1Memcached
Memcached是一款開(kāi)源的、高性能的純內(nèi)存緩存服務(wù)軟件。
mysql數(shù)據(jù)庫(kù)屬于磁盤(pán)上的數(shù)據(jù)庫(kù),數(shù)據(jù)的讀寫(xiě)較慢;而Memcached數(shù)據(jù)庫(kù)屬于內(nèi)存中的數(shù)據(jù)庫(kù),讀寫(xiě)速度快,但數(shù)據(jù)容易丟失。Memcached天生不支持分布式集群,只能通過(guò)程序支持分布式存儲(chǔ)。使用Memcached數(shù)據(jù)庫(kù),提高用戶訪問(wèn)網(wǎng)站速度,降低MySQL數(shù)據(jù)庫(kù)服務(wù)器壓力,提高網(wǎng)站的并發(fā)訪問(wèn),因此工作中,MySQL+Memcached搭配使用。
1.2Memcached工作過(guò)程
2.系統(tǒng)環(huán)境準(zhǔn)備
[root@cache01 ~]# cat /etc/re
RedHat-release resolv.conf
[root@cache01 ~]# cat /etc/re
redhat-release resolv.conf
[root@cache01 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@cache01 ~]# uname -r
3.10.0-327.el7.x86_64
[root@cache01 ~]# getenforce
Disabled
[root@cache01 ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
[root@cache01 ~]# ifconfig
eth0: flags=4163
inet 10.0.0.21 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fee1:ad7 prefixlen 64 scopeid 0x20
ether 00:0c:29:e1:0a:d7 txqueuelen 1000 (Ethernet)
RX packets 3228 bytes 815585 (796.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 419 bytes 52728 (51.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163
inet 172.16.1.21 netmask 255.255.255.0 broadcast 172.16.1.255
inet6 fe80::20c:29ff:fee1:ae1 prefixlen 64 scopeid 0x20
ether 00:0c:29:e1:0a:e1 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 23 bytes 1698 (1.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 0 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
3.服務(wù)端部署Memcached服務(wù)
3.1安裝memcached
[root@cache01 ~]# yum install -y memcached
3.2啟動(dòng)memcached服務(wù)
[root@cache01 ~]# systemctl start memcached.service
3.3測(cè)試
[root@cache01 ~]# printf "set fengfyu 0 0 5\r\n12345\r\n"|nc 10.0.0.21 11211 ---寫(xiě)入數(shù)據(jù)
STORED
[root@cache01 ~]# printf "get fengfyu 0 0 5\r\n12345\r\n"|nc 10.0.0.21 11211 ---讀取數(shù)據(jù)
VALUE fengfyu 0 5
12345
END
ERROR
4.web服務(wù)器客戶端部署memcached
4.1編譯安裝memcached
[root@web01 tools]# tar xf memcache-2.2.5.tgz
[root@web01 tools]# cd memcache-2.2.5/
[root@web01 memcache-2.2.5]# /application/php/bin/ph
[root@web01 memcache-2.2.5]# /application/php/bin/phpize
Configuring for:
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212
[root@web01 memcache-2.2.5]# ./configure --enable-memcache --with-php-config=/application/php/bin/php-config --with-zlib-dir && make && make install
4.2使php與memcached關(guān)聯(lián)
sed -i '$a extension=memcache.so' /application/php/lib/php.ini
4.3啟動(dòng)php
/application/php/sbin/php-fpm
4.4客戶端測(cè)試
[root@web01 www]# cat /application/nginx/html/www/mc.php
$memcache = new Memcache;
$memcache->connect('10.0.0.21', 11211) or die ("Could not connect");
$memcache->set('fengyu', 'hello,world');
$get_value = $memcache->get('fengyu');
echo $get_value;
?>
[root@web01 www]# printf "get fengyu\r\n"|nc 10.0.0.21 11211
VALUE fengyu 0 11
hello,world
END
5.web界面管理maceched
5.1解壓memadmin包到/application/nginx/html/www/目錄
[root@web01 tools]# tar xf memadmin-1.0.12.tar.gz -C /application/nginx/html/www/
5.2瀏覽器訪問(wèn)
http://10.0.0.7/memadmin
6.Memcached Session共享
6.1通過(guò)程序?qū)崿F(xiàn),web01只需要往memcahce寫(xiě)session,web02從memcahce讀session,當(dāng)作普通數(shù)據(jù)讀寫(xiě)(更具有通用性)
6.1通過(guò)php的配置文件,php默認(rèn)將session存儲(chǔ)在文件中,修改為存儲(chǔ)在memcached中
sed -i 's#session.save_handler = files#session.save_handler = memcache#;$a session.save_path = "tcp://10.0.0.21:11211"' /application/php/lib/php.ini
網(wǎng)頁(yè)名稱:CentOS7部署Memcached緩存服務(wù)器
標(biāo)題鏈接:http://fisionsoft.com.cn/article/coosodc.html


咨詢
建站咨詢
