1、简述CGI与FASTCGI区别
cgi:Common Gateway Interface公共网关接口 web服务器会根据这次请求的内容,然后fork一个新进程来运行外部的C程序或者bash,perl脚本等,这个进程会把处理完的数据返回给web服务器,最后web服务器把内容发送给用户,刚才fork的进程也随之退出。如果下次用户还请求改动态脚本,那么web服务器又再次fork一个新进程,周而复始的进行。 CGI可以让一个客户端,从网页浏览器通过http服务器向执行在网络服务器上的程序传输数据;CGI描述了客户端和服务器程序之间传输的一种标准。 请求流程: Client--(http协议)--httpd--(cgi协议)--application server(program file)--(mysql协议)--mysql fastcgi fastcgi的方式,web服务器收到一个请求时,不会重新fork一个进程(因为这个进程在web服务器启动时就开启了,而且不会退出),web服务器直接把内容传递给这个进程(进程间通信,但fastcgi使用了别的方式,tcp方式通行),这个进程收到请求后进行处理,把结果返回给web服务器,最后自己接着等待下一个请求的到来,而不是退出。 请求流程: Client--(http协议)--httpd--(fastcgi协议)--fastcgi服务器--(mysql协议)--mysql cgi和fastcgi的比较 cgi:兼职,一次性的服务 fastcgi:全职,持续性的服务
2、 编译安装基于fastcgi模式的多虚拟主机的wordpress和discuz的LAMP架构
1、修改host文件,ping测试连通性 修改C:\Windows\System32\drivers\etc\host 10.0.0.7 blog.magedu.org forum.magedu.org ping blog.magedu.org ping forum.magedu.org 2、10.0.0.8上安装mysql数据库,并建立blog、forum数据库 [root@centos8 ~]# ls anaconda-ks.cfg mysql-8.0.19-linux-glibc2.12-x86_64.tar install_mysql5.7or8.0_for_centos.sh [root@centos8 ~]# bash install_mysql5.7or8.0_for_centos.sh [root@centos8 ~]# mysql -uroot -pmagedu mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.19 MySQL Community Server - GPL Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database blog; Query OK, 1 row affected (0.00 sec) mysql> create database forum; Query OK, 1 row affected (0.00 sec) mysql> create user blog@'10.0.0.%' identified by '123456'; Query OK, 0 rows affected (0.01 sec) mysql> create user forum@'10.0.0.%' identified by '123456'; Query OK, 0 rows affected (0.01 sec) mysql> grant all on blog.* to blog@'10.0.0.%'; Query OK, 0 rows affected (0.00 sec) mysql> grant all on forum.* to forum@'10.0.0.%'; Query OK, 0 rows affected (0.00 sec) 3、安装httpd #首先把apr-util-1.6.1、apr-1.7.0、httpd-2.4.46三个安装包放到目录下 [root@centos7 ~]# ls anaconda-ks.cfg apr-util-1.6.1.tar.bz2 php-7.4.28 apr-1.7.0.tar.bz2 httpd-2.4.46.tar.bz2 php-7.4.28.tar.gz [root@centos7 ~]# bash install_httpd_20220331.sh [root@centos7 ~]# ss -lnt State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 [::1]:25 [::]:* LISTEN 0 128 [::]:80 [::]:* LISTEN 0 128 [::]:22 [::]:* [root@centos7 ~]# systemctl status httpd ● httpd.service - SYSV: apache Loaded: loaded (/etc/rc.d/init.d/httpd; bad; vendor preset: disabled) Active: active (running) since 四 2022-03-31 05:20:05 CST; 4min 27s ago [root@centos7 ~]# vim /usr/local/apache/conf/httpd.conf #去掉这两行注释 LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so #增加index.php作为默认页面 <IfModule dir_module> DirectoryIndex index.php index.html </IfModule> #文件最后增加这两行 AddType application/x-httpd-php .php ProxyRequests Off #实现第一个虚拟主机 <virtualhost *:80> servername blog.magedu.org documentroot /data/blog <directory /data/blog> require all granted </directory> ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/blog/$1 #实现status和ping页面 ProxyPassMatch ^/(fpm_status|ping)$ fcgi://127.0.0.1:9000/$1 CustomLog "logs/access_blog_log" common </virtualhost> #第二个虚拟主机 <virtualhost *:80> servername forum.magedu.org documentroot /data/forum <directory /data/forum/> require all granted </directory> ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/forum/$1 CustomLog "logs/access_forum_log" common </virtualhost> [root@centos7 ~]# systemctl restart httpd.service [root@centos7 ~]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 [::1]:25 [::]:* LISTEN 0 128 [::]:80 [::]:* 4、编译安装 fastcgi 方式的 php 7.4 #centos源不能安装libmcrypt-devel解决方案 [root@centos7 php-7.4.28]# wget http://www.atomicorp.com/installers/atomic [root@centos7 php-7.4.28]# sh ./atomic [root@centos7 php-7.4.28]# yum install libmcrypt-devel [root@centos7 ~]# yum -y install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel [root@centos7 ~]# tar xf php-7.4.28.tar.gz [root@centos7 ~]# cd php-7.4.28 [root@centos7 ~]# ./configure \ --prefix=/apps/php \ --enable-mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-zlib \ --with-config-file-path=/etc \ --with-config-file-scan-dir=/etc/php.d \ --enable-fpm \ [root@centos7 php-7.4.28]# make -j 4 && make install [root@centos7 php-7.4.28]# /apps/php/bin/php --version PHP 7.4.28 (cli) (built: Mar 31 2022 15:00:58) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies [root@centos7 php-7.4.28]# php --version PHP 7.4.28 (cli) (built: Mar 31 2022 05:43:16) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies [root@centos7 php-7.4.28]# vim /etc/profile.d/lamp.sh PATH=/apps/php/bin:/apps/httpd/bin:$PATH [root@centos7 php-7.4.28]# . /etc/profile.d/lamp.sh [root@centos7 php-7.4.28]# php --version PHP 7.4.28 (cli) (built: Mar 31 2022 15:00:58) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies [root@centos7 php-7.4.28]# pwd /root/php-7.4.28 [root@centos7 php-7.4.28]# cp php.ini-production /etc/php.ini [root@centos7 php-7.4.28]# cp sapi/fpm/php-fpm.service /lib/systemd/system/ [root@centos7 php-7.4.28]# cd /apps/php/etc/ [root@centos7 etc]# ls php-fpm.conf.default php-fpm.d [root@centos7 etc]# cp php-fpm.conf.default php-fpm.conf [root@centos7 etc]# cd php-fpm.d/ [root@centos7 php-fpm.d]# ls www.conf.default [root@centos7 php-fpm.d]# cp www.conf.default www.conf [root@centos7 php-fpm.d]# vim www.conf #修改进程所有者 user = apache group = apache #支持status和ping页面 pm.status_path = /fpm_status ping.path = /ping [root@centos7 php-fpm.d]# mkdir /etc/php.d/ [root@centos7 php-fpm.d]# vim /etc/php.d/opcache.ini [opcache] zend_extension=opcache.so opcache.enable=1 [root@centos7 php-fpm.d]# systemctl daemon-reload [root@centos7 php-fpm.d]# systemctl enable --now php-fpm.service [root@centos7 php-fpm.d]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 127.0.0.1:9000 *:* 5、安装配置wordpress和Discuz [root@centos7 php-fpm.d]# cd /data [root@centos7 data]# mkdir blog forum #准备好wordpress和Discuz安装包 [root@centos7 ~]# ls anaconda-ks.cfg apr-util-1.6.1.tar.bz2 install_httpd_20220331.sh apr-1.7.0 Discuz_X3.4_SC_UTF8_20220131.zip php-7.4.28 apr-1.7.0.tar.bz2 httpd-2.4.46 php-7.4.28.tar.gz apr-util-1.6.1 httpd-2.4.46.tar.bz2 wordpress-5.9.2-zh_CN.tar.gz [root@centos7 ~]# tar xf wordpress-5.9.2-zh_CN.tar.gz [root@centos7 ~]# ls anaconda-ks.cfg Discuz_X3.4_SC_UTF8_20220131.zip php-7.4.28.tar.gz apr-1.7.0 httpd-2.4.46 wordpress apr-1.7.0.tar.bz2 httpd-2.4.46.tar.bz2 wordpress-5.9.2-zh_CN.tar.gz apr-util-1.6.1 install_httpd_20220331.sh apr-util-1.6.1.tar.bz2 php-7.4.28 [root@centos7 ~]# mv wordpress/* /data/blog/ [root@centos7 opt]# mv Discuz_X3.4_SC_UTF8_20220131.zip /opt [root@centos7 opt]# cd /opt [root@centos7 opt]# unzip Discuz_X3.4_SC_UTF8_20220131.zip [root@centos7 opt]# mv upload/* /data/forum/ [root@centos7 opt]# chown -R apache.apache /data/*
3、通过loganalyzer展示数据库中的日志
[root@centos8 ~]# yum -y install httpd php-fpm php-mysqlnd [root@centos8 ~]# systemctl enable --now httpd php-fpm Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service. Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service. [root@centos8 ~]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 128 *:80 *:* [root@centos8 ~]# cd /var/www/html/ [root@centos8 html]# ls [root@centos8 html]# vim info.php <?php phpinfo(); ?>
#上传loganalyzer包
[root@centos8 ~]# ls anaconda-ks.cfg loganalyzer-4.1.12.tar.gz [root@centos8 ~]# tar xf loganalyzer-4.1.12.tar.gz [root@centos8 ~]# cd loganalyzer-4.1.12 [root@centos8 loganalyzer-4.1.12]# mv src/ /var/www/html/log
[root@centos8 ~]# touch /var/www/html/log/config.php [root@centos8 ~]# chmod 666 /var/www/html/log/config.php
[root@centos7 ~]# logger "this is test from 7 hi"
[root@centos8 ~]# yum -y install php-gd
#修改config.php防止文件被误改
[root@centos8 ~]# cd /var/www/html/log/ [root@centos8 log]# chmod 644 config.php