目錄
- PHP
- 編譯安裝
- nginx結合php-fpm
- php添加memcache功能模塊
- 構建nginx高速快取
- goaccess 日志可視化
- tomcat結合memcache
PHP
- PHP是一種在服務器端執行的嵌入HTML檔案的腳本語言
PHP-FPM
PHP-FPM是一個實作了Fastcgi的程式,PHP-FPM的管理物件是php-cgi,被PHP官方收了
后來PHP內核集成了PHP-FPM之后就方便多了,使用enalbe-fpm這個編譯引數即可
PHP-CGI
php-cgi 是解釋PHP腳本的程式,只是個CGI程式,他自己本身只能決議請求,回傳結果,不會行程管理
編譯安裝
[root@server1 /mnt]# yum install -y bzip2
[root@server1 /mnt]# tar jxf php-7.4.12.tar.bz2
[root@server1 /mnt]# yum install -y systemd-devel libxml2-devel sqlite-devel curl-devel libpng-devel
[root@server1 /mnt]# yum install -y oniguruma-*
軟體編譯
[root@server1 /mnt/php-7.4.12]# cd php-7.4.12/
[root@server1 /mnt/php-7.4.12]# ./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 /mnt/php-7.4.12]# make
[root@server1 /mnt/php-7.4.12]# make install
拷貝php-fpm組態檔,修改php-fpm啟動檔案
[root@server1 /mnt/php-7.4.12]# cd /usr/local/php/etc/
[root@server1 /usr/local/php/etc]# cp php-fpm.conf.default php-fpm.conf
[root@server1 /usr/local/php/etc]# vim php-fpm.conf

[root@server1 /usr/local/php/etc]# cd php-fpm.d/
[root@server1 /usr/local/php/etc/php-fpm.d]# cp www.conf.default www.conf
編輯php核心配置更改時區
[root@server1 /mnt/php-7.4.12]# cd /usr/local/php/etc/
[root@server1 /usr/local/php/etc]# vim php.ini

使用systemctl命令來控制nginx
[root@server1 ~]# cd /mnt/php-7.4.12/sapi/fpm/
[root@server1 /mnt/php-7.4.12/sapi/fpm]# cp php-fpm.service /usr/lib/systemd/system
[root@server1 /mnt/php-7.4.12/sapi/fpm]# systemctl daemon-reload
[root@server1 /mnt/php-7.4.12/sapi/fpm]# systemctl start php-fpm.service #出錯

多載服務的配置,讓服務的服務程式組態檔生效,可讓systemctl 管理
[root@server1 /usr/lib/systemd/system]# systemctl daemon-reload
[root@server1 /usr/lib/systemd/system]# systemctl start php-fpm.service

nginx結合php-fpm
[root@server1 /usr/lib/systemd]# cd /usr/local/nginx/conf/
[root@server1 /usr/local/nginx/conf]# vim nginx.conf
[root@server1 /usr/local/nginx/conf]# nginx -s reload

添加php測驗網頁
[root@server1 /usr/local/nginx/html]# vim index.php

多載nginx后訪問

php添加memcache功能模塊
傳統快取策略

[root@server1 /mnt]# tar zxf memcache-4.0.5.2.tgz
[root@server1 /mnt]# cd memcache-4.0.5.2/
[root@server1 /mnt/memcache-4.0.5.2]# phpize
-bash: phpize: command not found
配置環境變數
[root@server1 ~]# vim .bash_profile
[root@server1 ~]# source .bash_profile
[root@server1 ~]# which phpize
/usr/local/php/bin/phpize
[root@server1 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/usr/local/php/bin

安裝依賴項
phpize命令是準備php擴展安裝的編譯環境的,用于手動編譯安裝php擴展


[root@server1 /mnt/memcache-4.0.5.2]# ./configure --enable-memcache
[root@server1 /mnt/memcache-4.0.5.2]# make
[root@server1 /mnt/memcache-4.0.5.2]# make install
配置php加載模塊
[root@server1 /mnt/memcache-4.0.5.2]# php -m | grep memcache
[root@server1 /mnt/memcache-4.0.5.2]# cd /usr/local/php/etc/
[root@server1 /usr/local/php/etc]# ls
php-fpm.conf php-fpm.conf.default php-fpm.d php.ini
[root@server1 /usr/local/php/etc]# vim php.ini
[root@server1 /usr/local/php/etc]# systemctl reload php-fpm.service
[root@server1 /usr/local/php/etc]# php -m | grep memcache
memcache


將測驗頁面以及memcache復制至nginx html目錄
[root@server1 /usr/local/php/etc]# cd /mnt/memcache-4.0.5.2/
[root@server1 /mnt/memcache-4.0.5.2]# cp example.php memcache.php /usr/local/nginx/html/
[root@server1 /mnt/memcache-4.0.5.2]# cd /usr/local/nginx/html/
[root@server1 /usr/local/nginx/html]# ls
50x.html download example.php index.html index.php memcache.php
看不到,需要安裝memached使之連接

安裝啟用memcached
[root@server1 /usr/local/nginx/html]# yum install -y memcached.x86_64
[root@server1 /usr/local/nginx/html]# systemctl start memcached.service
[root@server1 /usr/local/nginx/html]# cat /etc/sysconfig/memcached
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""

編輯memcache.php,修改資訊
[root@server1 /usr/local/nginx/html]# vim memcache.php

多載nginx訪問memcache.php頁面,輸入上邊自己寫的用戶名密碼


多次訪問此時頁面,只有第一次是從后端拿的(因為第一次訪問快取查自己沒有所以去后端取),之后都是從快取里拿的(之后訪問快取查自己已經有了就不會去后端拿了)
重繪example界面,看到資料有所變化
所以快取命中率會越來越高






構建nginx高速快取
由于傳統快取是php從快取拿,回應時間由php決定,現在我們讓nginx直接去回應請求從快取里拿,
官網:傳送門

要換一個nginx實作,也就是openresty;其實就是nginx的加強版,nginx加了一個lua模塊,下載解壓進入解壓目錄可以看到自帶nginx
原始碼編譯安裝
[root@server1 /mnt]# tar zxf openresty-1.19.3.1.tar.gz
[root@server1 /mnt]# cd openresty-1.19.3.1/
為了不將老的nginx頂掉,我們不帶路徑模塊引數
[root@server1 /mnt/openresty-1.19.3.1]# ./configure
[root@server1 /mnt/openresty-1.19.3.1]# make && make install
組態檔從老的nginx拷一份出來,適當修改
并且之前現成的php測驗頁拷貝到openresty發布目錄下
[root@server1 /usr/local/openresty/nginx/conf]# cp /usr/local/nginx/conf/nginx.conf /usr/local/openresty/nginx/conf/
cp: overwrite ‘/usr/local/openresty/nginx/conf/nginx.conf’? yes
[root@server1 /usr/local/openresty/nginx/html]# cp /usr/local/nginx/html/index.php .
[root@server1 /usr/local/openresty/nginx/html]# cp /usr/local/nginx/html/example.php .
停掉之前的nginx,開啟openresty
[root@server1 /usr/local/openresty/nginx/conf]# vim nginx.conf



多載openresty
[root@server1 /usr/local/openresty/nginx/conf]# /usr/local/openresty/nginx/sbin/nginx
[root@server1 /usr/local/openresty/nginx/conf]# /usr/local/openresty/nginx/sbin/nginx -s reload
這回再做壓測,訪問靜態頁面速度快多了
動態頁面速度也實作了質的飛躍,也沒有丟包的現象了
[root@foundation25 mnt]# ab -c10 -n 5000 http://172.25.25.1/example.php

goaccess 日志可視化
原始碼編譯安裝
[root@server1 /mnt/goaccess-1.4]# tar zxf goaccess-1.4.tar.gz
[root@server1 /mnt/goaccess-1.4]# cd /mnt/goaccess-1.4
[root@server1 /mnt]# yum install -y GeoIP-devel-1.5.0-13.el7.x86_64.rpm
[root@server1 /mnt/goaccess-1.4]# yum install -y ncurses-devel
[root@server1 /mnt/goaccess-1.4]# ./configure --enable-utf8 --enable-geoip=legacy
[root@server1 /mnt/goaccess-1.4]# make
[root@server1 /mnt/goaccess-1.4]# make install
存在此檔案
[root@server1 ~]# cd /usr/local/bin/
[root@server1 /usr/local/bin]# ls
goaccess
后臺運行
cd /usr/local/openresty/nginx/conf
[root@server1 /usr/local/openresty/nginx/conf]# /usr/local/openresty/nginx/sbin/nginx -s stop
[root@server1 /usr/local/openresty/nginx/conf]# nginx
[root@server1 /usr/local/openresty/nginx/conf]# goaccess access.log -o /usr/local/nginx/html/report.html --log-format=COMBINED --real-time-html &

做壓測發現可視化界面有詳細的資料記錄
[root@foundation25 mnt]# ab -c10 -n 1000 http://172.25.25.1/index.html

tomcat結合memcache
tomcat是一種web服務器,也可以稱作運行在服務器(物理意義上的計算機)上的一種軟體包,用來對服務器上的HTML檔案提供訪問權限控制,
2、3上各啟用tomcat
[root@server2 /mnt]# rpm -ivh jdk-8u121-linux-x64.rpm
[root@server2 /mnt]# tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/
[root@server2 /mnt]# cd /usr/local/
[root@server2 /usr/local]# ln -s apache-tomcat-7.0.37/ tomcat
[root@server2 /usr/local]# ll
[root@server2 /usr/local]# cd tomcat/
[root@server2 /usr/local/tomcat]# bin/startup.sh


[root@server1 /usr/local/nginx/conf]# vim nginx.conf
[root@server1 /usr/local/nginx/conf]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server1 /usr/local/nginx/conf]# nginx -s reload



[root@server2 /usr/local/tomcat]# cd webapps/ROOT/
[root@server2 /usr/local/tomcat/webapps/ROOT]# ll test.jsp #測驗腳本檔案




server2、3都做
yum install -y memcached.x86_64
systemctl start memcached.service
vim /usr/local/tomcat/conf/context.xml


從250下一個jar的包到/usr/local/tomcat/lib目錄下
yum install -y telnet

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/298918.html
標籤:其他
上一篇:H5新增了哪些新特性
下一篇:樹莓派之搭建個人博客網站
