第十四周学习作业

家资是何物,积帙列梁梠。这篇文章主要讲述第十四周学习作业相关的知识,希望能为你提供帮助。
1、简述CGI与FASTCGI区别
?CGI:Common Gateway Interface 公共网关接口?
CGI 在2000年或更早的时候用得比较多,以前web服务器一般只处理静态的请求,如果碰到一个动态请求怎么办呢?web服务器会根据这次请求的内容,然后会 fork 一个新进程来运行外部的 C 程序或者bash,perl脚本等,这个进程会把处理完的数据返回给web服务器,最后web服务器把内容发送给用户,刚才fork的进程也随之退出。 如果下次用户还请求改动态脚本,那么web服务器又再次fork一个新进程,周而复始的进行。CGI 可以让一个客户端,从网页浏览器通过http服务器向执行在网络服务器上的程序传输数据;CGI描述了客户端和服务器程序之间传输的一种标准
请求流程:

Client -- (http协议) --> httpd -- (cgi协议) --> application server (program file) -- (mysql协议) --> mysql

?fastcgi?的方式是,web服务器收到一个请求时,不会重新fork一个进程(因为这个进程在web服务器启动时就开启了,而且不会退出),web服务器直接把内容传递给这个进程(进程间通信,但fastcgi使用了别的方式,tcp方式通信),这个进程收到请求后进行处理,把结果返回给web服务器,最后自己接着等待下一个请求的到来,而不是退出。
请求流程:
Client -- (http协议) --> httpd -- (fastcgi协议) --> fastcgi服务器 -- (mysql协议) --> mysql

?CGI和fastcgi 比较:?
CGI: 兼职, 一次性的过河拆桥式的服务
FASTCGI: 专职,全周期的持续式的服务


在web服务器方面
在对数据进行处理的进程方面
CGI
  fork一个新的进程进行处理
读取参数,处理数据,然后就结束生命期
FASTCGI
用tcp方式跟远程机子上的进程或本地进程建立连接
要开启tcp端口,进入循环,等待数据的到来,处理数据
2、编译安装基于fastcgi模式的多虚拟主机的wordpress和discuz的LAMP架构
【第十四周学习作业】
  2.1安装前软件准备
[root@CentOS84 ~]# tree
.
├── install_offline_mysql5.7or8.0_for_centos.sh
└── mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz

[root@centos79 ~]# tree
.
├── apr-1.7.0.tar.gz
├── apr-util-1.6.1.tar.gz
├── httpd-2.4.53.tar.gz
├── install_httpd24.sh
├── install_php74.sh
├── latest-zh_CN.tar.gz
├── liboniguruma5-6.9.7.1-alt1.x86_64.rpm
├── liboniguruma-devel-6.9.7.1-alt1.x86_64.rpm
└── php-7.4.28.tar.gz

2.2二进制数据库安装
##安装脚本
[root@CentOS84 ~]# cat install_offline_mysql5.7or8.0_for_centos.sh

#!/bin/bash
# https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
# https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz

source /etc/init.d/functions

SRC_DIR=`pwd`
MYSQL=mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
#MYSQL=mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz
COLOR=echo -e \\E[01; 31m
END=\\E[0m
MYSQL_ROOT_PASSWORD=mysql123

check()

if [ $UID -ne 0 ]; then
action "当前用户不是root,安装失败" false
exit=1
fi

cd $SRC_DIR
if [ ! -e $SRC_DIR ]; then
$COLOR"缺少$MYSQL文件"$END
$COLOR"相关软件存放在$SRC_DIR目录下"$END
exit
elif [ -e /usr/local/mysql ]; then
action "数据库已存在,安装失败!" false
exit
else
return
fi

install_mysql()
$COLOR"开始安装MySQL数据库..."$END
yum -y -q install libaio numactl-libs
cd $SRC_DIR
tar xf $MYSQL -C /usr/local/
MYSQL_DIR=`echo $MYSQL | sed -nr s/^(.*[0-9]).*/\\1/p`
ln -s /usr/local/$MYSQL_DIR /usr/local/mysql
id mysql & > /dev/null ||useradd -s /sbin/nologin -r mysql ; action "创建mysql用户";
echo PATH=/usr/local/mysql/bin/:$PATH > /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
cat > /etc/my.cnf < < EOF
[mysqld]
server-id=1
log-bin
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
EOF
[ -d /data ] || mkdir /data
chown -R mysql.mysql /usr/local/mysql/
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
if [ $? -eq 0 ]; then
mysqladmin -uroot password $MYSQL_ROOT_PASSWORD & > /dev/null
action "数据库安装完成!口令:$MYSQL_ROOT_PASSWORD"
else
echo "数据库启动失败,退出!"
fi


check
install_mysql

##执行过程
[root@CentOS84 ~]# sh install_offline_mysql5.7or8.0_for_centos.sh
开始安装MySQL数据库...

Upgraded:
numactl-libs-2.0.12-13.el8.x86_64

创建mysql用户[OK]
Starting MySQL. SUCCESS!
数据库安装完成!口令:mysql123[OK]

2.2.1创建wordpress和discuz数据库及登录账户
[root@CentOS84 ~]# mysql -uroot -pmysql123
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 5
Server version: 5.7.36-log MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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>
mysql> create database workpress;
Query OK, 1 row affected (0.06 sec)

mysql> create database discuz;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on wokpress.* to workpress@10.10.10.% identified by "mysql123";
Query OK, 0 rows affected, 1 warning (0.05 sec)

mysql> grant all on discuz.* to discuz@10.10.10.% identified by "mysql123";
Query OK, 0 rows affected, 1 warning (0.00 sec)

2.3编译安装apache
##安装脚本
[root@centos79 ~]# cat install_httpd24.sh
#/bin/bash
#https://dlcdn.apache.org/httpd/httpd-2.4.53.tar.gz
#https://dlcdn.apache.org/apr/apr-1.7.0.tar.gz
#https://dlcdn.apache.org/apr/apr-util-1.6.1.tar.gz

source /etc/init.d/functions

SRC_DIR=`pwd`
HTTPD=httpd-2.4.53.tar.gz
APR=apr-1.7.0.tar.gz
APR_UTIL=apr-util-1.6.1.tar.gz
INSTALL_DIR=/apps/httpd
COLOR_Y=echo -e \\E[01; 33m
COLOR_G=echo -e \\E[01; 32m
END=\\E[0m

check()
if [ $UID -ne 0 ]; then
action "当前用户不是root,安装失败" false
exit=1
fi
cd $SRC_DIR
if [ ! = $SRC_DIR ]; then
action "缺少$HTTPD,$APR,$APR-UTIL 安装文件,相关文件请放在$SRC_DIR目录下" false
exit=1
fi
$COLOR_Y"开始安装依赖包..."$END
yum install gcc pcre-devel openssl-devel expat-devel vim -y & > /dev/null
$COLOR_G"依赖包,安装完成!"$END


install_httpd()
$COLOR_Y"开始安装配置httpd..."$END
tar xf $HTTPD & & tar xf $APR & & tar xf $APR_UTIL
mv $APR%.tar.* $HTTPD%.tar.*/srclib/apr
mv $APR_UTIL%.tar.* $HTTPD%.tar.*/srclib/apr-util
cd

    推荐阅读