日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

nginx+php+memcache高速缓存openresty)

發布時間:2024/9/3 php 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx+php+memcache高速缓存openresty) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、php源碼編譯

1.軟件下載:軟件下載 (這里使用的時php-7.4.6版本)

如果系統已經裝了php請先卸載,以免與源碼編譯沖突

[root@server1 ~]# yum install bzip2 -y [root@server1 ~]# tar jxf php-7.4.6.tar.bz2 [root@server1 ~]# cd php-7.4.6/ [root@server1 php-7.4.6]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-curl --with-iconv --with-mhash --with-zlib --with-openssl --enable-mysqlnd --with-mysqli --with-pdo-mysql --disable-debug --enable-sockets --enable-soap --enable-inline-optimization --enable-xml --enable-ftp --enable-gd --enable-exif --enable-mbstring --enable-bcmath --with-fpm-systemd [root@server1 php-7.4.6]# yum install systemd-devel.x86_64 -y [root@server1 php-7.4.6]# yum install libxml2-devel.x86_64 -y [root@server1 php-7.4.6]# yum install sqlite-devel.x86_64 -y [root@server1 php-7.4.6]# yum install libcurl-devel.x86_64 -y [root@server1 php-7.4.6]# yum install /root/gd-devel-2.0.35-26.el7.x86_64.rpm -y [root@server1 php-7.4.6]# yum install /root/oniguruma-devel-6.8.2-1.el7.x86_64.rpm /root/oniguruma-6.8.2-1.el7.x86_64.rpm -y

編譯過程中會出現一些依賴性問題一個一個解決即可

[root@server1 php-7.4.6]# make [root@server1 php-7.4.6]# make instal

編譯


2.拷貝php-fpm配置文件:

[root@server1 php-7.4.6]# cd /usr/local/php/ [root@server1 php]# cd etc/ [root@server1 etc]# cp php-fpm.conf.default php-fpm.conf [root@server1 etc]# vim php-fpm.conf

[root@server1 etc]# cd php-fpm.d/ [root@server1 php-fpm.d]# cp www.conf.default www.conf

[root@server1 php-7.4.6]# cp php.ini-production /usr/local/php/etc/php.ini [root@server1 php-7.4.6]# cd sapi/fpm/ [root@server1 fpm]# cp php-fpm.service /etc/systemd/system/ [root@server1 fpm]# systemctl daemon-reload [root@server1 etc]# vim /etc/systemd/system/php-fpm.service

3.修改php-fpm啟動文件:


[root@server1 etc]# vim php.ini [root@server1 etc]# systemctl reload php-fpm.service

二、nginx結合php-fpm

1.修改nginx配置文件:

[root@server1 etc]# vim /usr/local/nginx/conf/nginx.conf location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;include fastcgi.conf;}[root@server1 html]# nginx -s reload



[root@server1 etc]# cd /usr/local/nginx/html/ [root@server1 html]# vim index.php <?php phpinfo() ?>

添加環境變量

[root@server1 ~]# vim ~/.bash_profile [root@server1 ~]# source ~/.bash_profile

測試:

三、php添加memcache功能模塊(高速緩存)

memcache介紹
memcache是一套分布式的高速緩存系統,由LiveJournal的Brad Fitzpatrick開發,但目前被許多網站使用以提升網站的訪問速度,尤其對于一些大型的、需要頻繁訪問數據庫的網站訪問速度提升效果十分顯著 [1] 。這是一套開放源代碼軟件,以BSD license授權發布。
軟件下載

1.軟件安裝:

這里用到的是memcache-4.0.5.2.tgz

[root@server1 ~]# tar zxf memcache-4.0.5.2.tgz [root@server1 ~]# cd memcache-4.0.5.2/ [root@server1 memcache-4.0.5.2]# phpize [root@server1 memcache-4.0.5.2]# yum install autoconf [root@server1 memcache-4.0.5.2]# phpize [root@server1 memcache-4.0.5.2]# ./configure [root@server1 memcache-4.0.5.2]# make [root@server1 memcache-4.0.5.2]# make install

phpize是用來擴展php擴展模塊的,通過phpize可以建立php的外掛模塊



2.配置php加載模塊

[root@server1 no-debug-non-zts-20190902]# cd /usr/local/php/etc/ [root@server1 etc]# vim php.ini extension=memcache.so [root@server1 etc]# systemctl reload php-fpm.service [root@server1 etc]# php -m |grep memcache memcache

加入memcache模塊

[root@server1 etc]# yum install memcached -y [root@server1 etc]# systemctl start memcached [root@server1 etc]# netstat -antlp | grep 11211

[root@server1 etc]# cp /root/memcache-4.0.5.2/example.php memcache.php /usr/local/nginx/html/ [root@server1 html]# vim memcache.php

配置memcache登陸信息

測試




此時的命中率為93,再次訪問時,查看命中率的改變:(即進入example.php界面刷新,然后再次進入memcache.php界面,查看命中率):此時,命中率有了一定的提高,意思是,所讀取的內容是從緩存中進行拿取的,提高了速度,也減輕了后臺服務器的壓力

[root@server1 ~]# yum install telnet -y ##高速緩存測試軟件 [root@server1 ~]# telnet localhost 11211 add key flag expiretime bytes key : 給這個值設置一個名字; flag : 標志,是一個整數; expiretime : 有效期,以秒為單位,0表示沒有延遲; bytes : 這是一個需要存儲在memcached的數據的長度; value : 是一個需要存儲的數據。數據需要將通過在新的一行后輸入

四、構建nginx高速緩存

使用memc-nginx和srcache-nginx模塊構建高效透明的緩存機制
傳統緩存策略

高效緩存策略

1.軟件下載(openresty)

OpenResty(又稱:ngx_openresty) 是一個基于 NGINX 的可伸縮的 Web 平臺,由中國人章亦春發起,提供了很多高質量的第三方模塊。

OpenResty 是一個強大的 Web 應用服務器,Web 開發人員可以使用 Lua 腳本語言調動 Nginx 支持的各種 C 以及 Lua 模塊,更主要的是在性能方面,OpenResty可以 快速構造出足以勝任 10K 以上并發連接響應的超高性能 Web 應用系統。

360,UPYUN,阿里云,新浪,騰訊網,去哪兒網,酷狗音樂等都是 OpenResty 的深度用戶。
軟件下載

軟件安裝:

# wget https://openresty.org/package/rhel/openresty.repo # mv openresty.repo /etc/yum.repos.d/ # yum install -y openresty # rpm -ql openresty-1.19.3.1-1.el7.x86_64 ##查看文件配置信息 # ps aux | grep nginx ##不能存在nginx 的進程,如果有的話,kill掉

軟件配置:

# cd /usr/local/openresty/nginx/conf # vim nginx.conf 其余部分和nginx 配置一樣,以下僅展示不同處 upstream memcache {server 127.0.0.1:11211;keepalive 512; //保持512個不立即關閉的連接用于提升性能} location /memc {internal; //表示只接受內部訪問memc_connect_timeout 100ms;memc_send_timeout 100ms;memc_read_timeout 100ms;set $memc_key $query_string; //使用內置的$query_string來作為keyset $memc_exptime 300; //表示緩存失效時間memc_pass memcache;} location ~ \.php$ {set $key $uri$args; srcache_fetch GET /memc $key; srcache_store PUT /memc $key;root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;include fastcgi.conf;} 當所請求的uri以“.php”結尾時,首先到memcache中查詢有沒有以$uri$args為key的數據,如果有則直接返回;否則,執行location的邏輯,如果返回的http狀態碼為200,則在輸出前以$uri$args為key,將輸入結果存入memcache。 # systemctl start openresty # vim /usr/local/openresty/nginx/html/index.php <?php phpinfo() ?>

測試:
ab -c 100 -n 10000 http://172.25.1.1/index.php
我們可以看到壓測速度很快,且沒有報錯,速度很快。


通過來回切換觀察兩者速度,及出錯數目。

nginx結合lua

location @client { proxy_pass http://172.25.0.3; } location ~ \.php$ { default_type text/html; content_by_lua 'ngx.say("this is westos.org")'; access_by_lua ' if ngx.var.remote_addr == "172.25.0.250" then ngx.exec("@client") end '; }

總結

以上是生活随笔為你收集整理的nginx+php+memcache高速缓存openresty)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 免费在线视频一区 | 国产精品久久久久久久免费大片 | 成人黄色小视频 | 亚洲日本中文字幕 | 日韩免费av在线 | 亚洲一区二区三区视频 | 亚洲第一黄 | 日韩高清二区 | 日韩精品电影在线观看 | 亚洲精品在线视频免费观看 | 久久无码人妻一区二区三区 | 日韩欧美三级在线 | 国产做受视频 | 日韩成人av一区 | 久草免费在线视频观看 | 捆绑中国女人hd视频 | 欧美三级一区二区三区 | 黄色一级片a | 天天综合网久久综合网 | 午夜在线免费观看视频 | av片大全| 精品综合久久 | 好吊日在线观看 | 午夜小视频在线 | 亚洲一区二区三区四区视频 | 中文字幕免费观看视频 | 好吊妞一区二区三区 | 日韩极品视频在线观看 | 欧美三日本三级少妇三级99观看视频 | 韩国三级在线播放 | 色诱视频在线观看 | 97自拍偷拍视频 | 顶级毛茸茸aaahd极品 | 亚洲精品男人的天堂 | 丝袜性爱视频 | 久久久久久久久蜜桃 | 激情欧美一区二区免费视频 | 91免费精品视频 | 黄网免费在线观看 | 看黄色a级片 | 四级黄色片 | 麻豆av免费看 | 国产黄色免费 | 国产在线无 | 欧美性生活一区二区三区 | 成人免费av在线 | 超碰女| 91在线不卡 | 不卡av影院 | 日韩精品久久久久久久 | 宅男噜噜噜66一区二区 | 国产aⅴ片| 亚洲少妇在线 | 欧美国产在线观看 | 日韩欧美午夜 | 日本伦理中文字幕 | 一级黄片毛片 | 国产黄色一级大片 | 超碰超碰超碰超碰 | 亚洲v欧美v另类v综合v日韩v | 寡妇高潮一级视频免费看 | 8x国产一区二区三区精品推荐 | 草逼网站 | 五月天国产精品 | 国产精品久久久久久久久久 | 人与动物黄色片 | 久久中文字幕视频 | 我们的2018中文免费看 | 久久久久久久国产精品 | 国产伦精品一区二区三区免.费 | 热播网| 久久国产免费观看 | 日韩精品人妻中文字幕有码 | 丰满人妻在公车被猛烈进入电影 | 97中文字幕在线观看 | 欧美日韩免费视频 | а√在线中文网新版地址在线 | 欧美精品在线一区二区 | 在线观看中文字幕一区二区 | 台湾一级视频 | 国产精品 欧美激情 | 日韩aa视频| 中文字幕一区二区在线老色批影视 | 色爱综合区 | 日韩欧美影院 | 国产日韩av一区二区 | 国产a一级| 日本三级中文字幕 | 精品中文一区二区三区 | 女人脱下裤子让男人桶 | 18岁免费观看电视连续剧 | www.brazzers.com| 久久久久亚洲AV | 丝袜熟女一区二区三区 | 精品人妻人人做人人爽夜夜爽 | 综合久久婷婷 | 日韩男人的天堂 | 亲切的金子餐桌片段的金子 | 中国一级特黄录像播放 |