日志服务管理&CGI与FASTCGI区别

努力尽今夕,少年犹可夸。这篇文章主要讲述日志服务管理&CGI与FASTCGI区别相关的知识,希望能为你提供帮助。
1、简述CGI与FASTCGI区别
2、 编译安装基于fastcgi模式的多虚拟主机的wordpress和discuz的LAMP架构
3、通过loganalyzer展示数据库中的日志
1、简述CGI与FASTCGI区别CGI: 兼职, 一次性的过河拆桥式的服务
FASTCGI: 专职,全周期的持续式的服务

日志服务管理&CGI与FASTCGI区别

文章图片

2、 编译安装基于fastcgi模式的多虚拟主机的wordpress和discuz的LAMP架构 环境准备两台主机:
```html/xml
一台主机:httpd+php(fastcgi模式)
一台主机:mariadb 服务器
软件版本: ```html/xml CentOS 7.8 mariadb-10.2.27-linux-x86_64.tar.gz 通用二进制格式 apr-1.7.0.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.43.tar.gz php-7.4.7.tar.xz 或 php-7.3.10.tar.bz2 wordpress-5.4.2-zh_CN.tar.gz Discuz_X3.4_SC_UTF8【20191201】.zip

实现步骤1.1 二进制安装 mariadb
```html/xml
useradd -r -s /sbin/nologin mysql
tar xvf mariadb-10.2.27-linux-x86_64.tar.gz -C /usr/local
cd /usr/local
ln -sv mariadb-10.2.27-linux-x86_64 mysql
cd mysql
chown -R root.root ./*
mkdir /data/mysql -p
chown -R mysql.mysql /data/mysql
mkdir /etc/mysql
cp support-files/my-huge.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
[mysqld]
#加下面行
datadir =/data/mysql
skip_name_resolve = ON
#准备PATH变量
vim /etc/profile.d/lamp.sh
PATH=/usr/local/mysql/bin/:$PATH
. /etc/profile.d/lamp.sh
yum install libaio -y
cd /usr/local/mysql; scripts/mysql_install_db --user=mysql --datadir=/data/mysql
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
service mysqld start
#为wordprss和discuz应用准备数据库和用户帐号
mysql -uroot
mysql> create database wordpress;
mysql> create database discuz;
mysql> grant all on wordpress. to wordpress@10.0.0.% identified by " wppass" ;
mysql> grant all on discuz.
to discuz@10.0.0.% identified by dispass;
1.2 编译安装 httpd 2.4 ```html/xml #安装相关包 yum install gcc pcre-devel openssl-devel expat-devel -y#编译安装httpd tar xvf apr-1.7.0.tar.bz2 tar xvf apr-util-1.6.1.tar.bz2 tar xf httpd-2.4.43.tar.gz mv apr-1.7.0 httpd-2.4.43/srclib/apr mv apr-util-1.6.1 httpd-2.4.43/srclib/apr-util cd httpd-2.4.43/ ./configure \\ --prefix=/apps/httpd \\ --enable-so \\ --enable-ssl \\ --enable-cgi \\ --enable-rewrite \\ --with-zlib \\ --with-pcre \\ --with-included-apr \\ --enable-modules=most \\ --enable-mpms-shared=all \\ --with-mpm=eventmake & & make install#准备PATH变量 vim /etc/profile.d/lamp.sh PATH=/apps/httpd/bin:$PATH . /etc/profile.d/lamp.sh#创建和配置用户和组 useradd -s /sbin/nologin -r -u 88 apache vim /apps/httpd/conf/httpd.conf user apache group apache#修改为event模式,编译时已指定,此项不再需修改,可选项 vim /apps/httpd/conf/httpd.conf LoadModule mpm_event_module modules/mod_mpm_event.so#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so #LoadModule mpm_worker_module modules/mod_mpm_worker.sohttpd -M |grep mpm mpm_event_module (shared)apachectl start[root@centos7 ~]#vim /usr/lib/systemd/system/httpd.service [Unit] Description=The Apache HTTP Server After=network.target remote-fs.target nss-lookup.target Documentation=man:httpd(8) Documentation=man:apachectl(8) [Service] Type=forking #EnvironmentFile=/etc/sysconfig/httpd ExecStart=/apps/httpd/bin/apachectl start #ExecStart=/apps/httpd/bin/httpd $OPTIONS -k start ExecReload=/apps/httpd/bin/apachectl graceful #ExecReload=/apps/httpd/bin/httpd $OPTIONS -k graceful ExecStop=/apps/httpd/bin/apachectl stop KillSignal=SIGCONT PrivateTmp=true [Install] WantedBy=multi-user.target

1.3 编译安装 fastcgi 方式的 php 7.4
```html/xml
#安装相关包,依赖EPEL源
#php 7.4 相关包
yum -y install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel
oniguruma-devel
#php 7.3 相关包
yum -y install gcc libxml2-devel bzip2-devel libmcrypt-devel
#php7.4 编译
tar xvf php-7.4.7.tar.xz
cd php-7.4.7/
./configure \\
--prefix=/apps/php \\
--enable-mysqlnd \\
--with-mysqli=mysqlnd \\
--with-pdo-mysql=mysqlnd \\
--with-openssl \\
--with-zlib \\
--with-config-file-path=/etc \\
--with-config-file-scan-dir=/etc/php.d \\
--enable-mbstring \\
--enable-xml \\
--enable-sockets \\
--enable-fpm \\
--enable-maintainer-zts \\
--disable-fileinfo
#编译安装php 7.3
tar xvf php-7.3.10.tar.bz2
cd php-7.3.10
./configure --prefix=/apps/php \\
--enable-mysqlnd \\
--with-mysqli=mysqlnd \\
--with-pdo-mysql=mysqlnd \\
--with-openssl \\
--with-freetype-dir \\
--with-jpeg-dir \\
--with-png-dir \\
--with-zlib \\
--with-libxml-dir=/usr \\
--with-config-file-path=/etc \\
--with-config-file-scan-dir=/etc/php.d \\
--enable-mbstring \\
--enable-xml \\
--enable-sockets \\
--enable-fpm \\
--enable-maintainer-zts \\
--disable-fileinfo
make -j 4 & & make install
#准备PATH变量
#php7.4
vim /etc/profile.d/lamp.sh
PATH=/apps/php/bin:/apps/httpd/bin:$PATH
. /etc/profile.d/lamp.sh
#php7.3
vim /etc/profile.d/lamp.sh
PATH=/apps/php/bin:/apps/httpd/bin:$PATH
. /etc/profile.d/lamp.sh
#准备php配置文件和启动文件
cp php.ini-production /etc/php.ini
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
cd /apps/php/etc
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d/
cp www.conf.default www.conf
#修改进程所有者
vim /apps/php/etc/php-fpm.d/www.conf
user apache
group apache
#支持status和ping页面
pm.status_path = /fpm_status
ping.path = /ping
#支持opcache加速
mkdir /etc/php.d/
vim /etc/php.d/opcache.ini
[opcache]
zend_extension=opcache.so
opcache.enable=1
systemctl daemon-reload
systemctl status php-fpm.service
systemctl enable --now php-fpm.service
1.4 修改配置 httpd 支持 php-fpm ```html/xml vim /apps/httpd/conf/httpd.conf #取消下面两行的注释 LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so #修改下面行 < IfModule dir_module> DirectoryIndex index.php index.html < /IfModule> #加下面三行 AddType application/x-httpd-php .php #AddType application/x-httpd-php-source .phps ProxyRequests Off#实现第一个虚拟主机 < virtualhost *:80> servername blog.magedu.org documentroot /data/wordpress < directory /data/wordpress> require all granted < /directory> ProxyPassMatch ^/(.*\\.php)$ fcgi://127.0.0.1:9000/data/wordpress/$1 #实现status和ping页面 ProxyPassMatch ^/(fpm_status|ping)$ fcgi://127.0.0.1:9000/$1 CustomLog "logs/access_wordpress_log" common < /virtualhost> #第二个虚拟主机 < virtualhost *:80> servername forum.magedu.org documentroot /data/discuz < directory /data/discuz/> require all granted < /directory> ProxyPassMatch ^/(.*\\.php)$ fcgi://127.0.0.1:9000/data/discuz/$1 CustomLog "logs/access_discuz_log" common < /virtualhost> apachectl restart

1.5准备wordpress和discuz相关文件
```html/xml
#准备wordpress程序文件
mkdir /data/
tar xvf wordpress-5.4.2-zh_CN.tar.gz
mv wordpress/ /data
setfacl –R –m u:apache:rwx /data/wordpress/
#或者chown –R apache.apache /data/wordpress
#准备discuz!程序文件
unzip Discuz_X3.4_SC_UTF8【20191201】.zip
mv DiscuzX/upload/ /data/discuz
setfacl -R -m u:apache:rwx /data/discuz/
测试访问 ```html/xml vim /etc/hosts 10.0.0.7 blog.magedu.org forum.magedu.org

打开浏览器访问 http://blog.magedu.org 和http://forum.magedu.org 分别进行初始化和安装
3、通过loganalyzer展示数据库中的日志
日志服务管理&CGI与FASTCGI区别

文章图片

1.1 安装MySQL、rsyslog
```html/xml
yum -y install mariadb-server systemctl enable --now mariadb & & systemctl status mariadb yum -y install rsyslog-mysql#将sql脚本复制到数据库服务器
scp /usr/share/doc/rsyslog/mysql-createDB.sql 10.0.0.28:/root/
1.2 配置MySQL和rsyslog ```html/xml # mysql -uroot < mysql-createDB.sql # mysql -e "show databases; " +--------------------+ | Database| +--------------------+ | Syslog| | information_schema | | mysql| | performance_schema | +--------------------+#授权用户 # mysql -e "create user rsyslog@10.0.0.% identified by 123456; " # mysql -e "grant all on Syslog.* to rsyslog@10.0.0.%; " # mysql -e "select user,host from mysql.user; "#配置日志服务器将日志发送至指定数据库 [root@ rsyslog-server ~]#vim /etc/rsyslog.conf ####MODULES#####在 MODULES 语言下面添加 module(load="ommysql")#在RULES语句块下面添加 #### RULES #### #facility.priority :ommysql:DBHOST,DBNAME,DBUSER, PASSWORD *.info :ommysql:10.0.0.28,Syslog,rsyslog,123456[root@ rsyslog-server ~]# systemctl restart rsyslog.service#在日志服务器上生成日志 # logger "test log"#在数据库上查询到上面的测试日志 $> mysql -e "select count(*) from Syslog.SystemEvents; " +----------+ | count(*) | +----------+ |1907 | +----------+ # 可以看到测试日记已经存到Mysql的Syslog库中 # mysql -e "select *fromSyslog.SystemEvents\\G" | grep -C10 "test log"

1.3 安装LogAnalyzer
```html/xml
wget https://download.adiscon.com/loganalyzer/loganalyzer-4.1.10.tar.gz tar xvf loganalyzer-4.1.10.tar.gz mkdir /var/www/html/log mv loganalyzer-4.1.10/src/* /var/www/html/log#安装相关服务
yum -y install httpd php-fpm php-mysqlnd php-gd systemctl enable --now httpd php-fpm & & systemctl status httpd php-fpm#测试
php是使用套接字和httpd通讯的,并非监听在9000端口。
需要监听在端口,修改配置文件/etc/php-fpm.d/www.conf,监听端修改为:listen = 127.0.0.1:9000
cat > /var/www/html/info.php < < EOF< ?php phpinfo() ?>
EOF
打开浏览器访问http://10.0.0.38/info.php,没问题继续下一步操作
1.4 web 页面初始化LogAnalyzer 访问http://10.0.0.38/log 实现初始化 ![image.png](https://s2.51cto.com/images/20220313/1647172094639693.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ![image.png](https://s2.51cto.com/images/20220313/1647172105687888.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ![image.png](https://s2.51cto.com/images/20220313/1647172118845495.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ```html/xml 缺失文件 # touch /var/www/html/log/config.php # chmod 666 /var/www/html/log/config.php 重试

日志服务管理&CGI与FASTCGI区别

文章图片

日志服务管理&CGI与FASTCGI区别

文章图片

日志服务管理&CGI与FASTCGI区别

文章图片

【日志服务管理&CGI与FASTCGI区别】1.5 测试
```html/xml
[root@reyslog ~]# logger " this is a test log"
[root@reyslog ~]# logger " this is a newtest log
![image.png](https://s2.51cto.com/images/20220313/1647172272282256.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)


    推荐阅读