第十四周

一卷旌收千骑虏,万全身出百重围。这篇文章主要讲述第十四周相关的知识,希望能为你提供帮助。
第十四周 1.简述CGI与FASTCGI区别 CGI

CGI: Common Gateway Interface 公共网关接口,为http服务器与其他机器上的程序服务通信交流的一种协议,CGI程序必须运行在网络服务器上,以前web服务器一般只处理静态的请求,如果要处理动态请求,web服务器根据请求的内容,会fork一个新的进程来运行外部C程序或者其他程序等,整个进程会把处理完的数据返回给web服务器,最后web服务器把内容发送给客户端,刚才fork的进程也随之退出。如果下次用户还请求是动态资源,那么web服务器又再次fork一个子进程,周而复始的进行,不适合高并发场景,效率极其低下。CGI 可以让一个客户端,从网页浏览器通过http服务器向执行在网络服务器上的程序传输数据,CGI 描述了客户端和服务器程序之间的传输的一种标准请求流程: client --> (httpd协议)--> httpd--(cgi协议)--> application server(program file)--(mysql协议)--> mysql

fastcgi
fastcgi 的方式是,web服务器收到一个请求时,不会重新 fork 一个进程(因为整个进程在web服务启动时就开启了,而且不会退出),web服务器直接把内容传递给整个进程(进程间通信,但fastcgi使用了别的方式,tcp方式通信),这个进程收到请求后进行处理,把结果返回给web服务器,最后自己接着等待下一个请求的到来,而不是退出 fastcgi 是一个可伸缩地,高速地在 http服务器和动态脚本语言间通信的接口(在linux 下 fastCGI接口即为 socket ,整个socket 可以是文件 socket 也可以是iP socket),主要优点就是把动态语言和http服务器分离开来。多数流行的http服务器都支持fastCGI,包括apache nginx 等。 同时,fastcgi也被许多脚本语言所支持,例如php. fastcgi接口采用的是C/S架构,他可以将http服务器和脚本解析分开,同时还能在脚本解析服务器上启动一个或多个脚本来解析守护进程。当http服务器遇到童泰程序时,可以量其直接交付给 fastcgi进程来执行,然后将得到的结果返回给浏览器,这种方式可以让 http服务器专一地处理静态请求,或者将动态脚本服务器的结果返回给客户端,这在很大程度上提高了整个应用系统的性能.#fastcgi的重要特点如下 http服务器和动态脚本语言间通信的接口或工具 可把动态语言解析和http服务器分开 nginxapache 以及多数动态语言都支持 fastcgi fastcgi 接口方式采用c/s结构,分为客户端(http服务器)和服务器端(动态语言解析服务器) php动态语言服务器端可以启动多个 fastcgi的守护进程(php-fpm) http服务器通过(nginx fastcgi_pass) fastcgi客户端和动态语言 fastcgi服务器端通信(php-fpm)请求流程: client--(http协议)--> httpd--(fastcgi 协议)--> fastcgi服务器--(mysql协议)---> mysql

CGI与fastcgi 比较
CGI:兼职,一次性的服务方式 fastCGI:专值,全周期的持续式的服务

名称 在web服务器方面 在对数据进行处理的进程方面
cgi fork一个新的进程进程处理 读取参数、处理数据、然后就结束生命周期
fastcgi 用tcp方式跟远程机器上得进行或本地进程建立连接 要开启tcp端口、进入循环、等待数据的到来,处理数据
2.编译安装基于fastcgi模式的多虚拟主机的wordpress和discuz的LAMP/lnmp架构 0.环境要求
#wordpress discuz 开源php程序,用于博客、论坛 #可以采用lamp/lnmp架构 #以下采用 lamp 架构需要服务器2台: node00 192.168.80.100 数据库服务器 caserver 192.168.80.111 httpd+php(fastcgi模式)服务器 #软件版本 CentOS Linux release 7.9.2009 (Core) mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.51.tar.gz php-7.4.21.tar.gz wordpress-5.8.2-zh_cn.tar.gz Discuz_X3.4_SC_UTF8_20210926.zip

1.源码编译安装httpd
#源码编译安装httpd #文件 #install_httpd_wordpress_discuz.sh #Discuz_X3.4_SC_UTF8_20210926.zip #https://www.discuz.net/(打不开啊) #wordpress-5.8.2-zh_cn.tar.gz #https://cn.wordpress.org/download/[root@caserver ~]# ls -1 apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz Discuz_X3.4_SC_UTF8_20210926.zip httpd-2.4.51 httpd-2.4.51.tar.gz install_httpd_wordpress_discuz.sh install_php7.4.21.sh php-7.4.21.tar.gz wordpress-5.8.2-zh_cn.tar.gz

#install_httpd_wordpress_discuz.sh [root@caserver ~]# cat install_httpd_wordpress_discuz.sh #!/bin/bash #===================================================================================================== #File Name:install_httpd_wordpress_discuz.sh #Date:2021-10-22 17-00-42 #Author:Create by gong hai rong #Description:This script function is #Shell Version:GNU bash version 4.1.2(2)-release x86_64-redhat-linux-gnu #Copyright (C):2021 All rights reserved #===================================================================================================== #------------------------------------------------------------------------------------------------------------------ src_dir=`pwd` httpd_file=httpd-2.4.51.tar.gz apr_file=apr-1.7.0.tar.gz apr_util_file=apr-util-1.6.1.tar.gz #wordpress_file=latest-zh_CN.tar.gz wordpress_file=wordpress-5.8.2-zh_cn.tar.gz discuz_file=Discuz_X3.4_SC_UTF8_20210926.zip #------------------------------------------------------------------------------------------------------------------ httpd_name=$(echo ${httpd_file%*.tar.gz}) apr_name=$(echo ${apr_file%*.tar.gz}) apr_util_name=$(echo ${apr_util_file%*.tar.gz}) wordpress_name=$(echo ${wordpress_file%*.tar.gz}) url_httpd=https://mirrors.aliyun.com/apache/httpd/$httpd_file url_apr=https://mirrors.aliyun.com/apache/apr/$apr_file url_apr_util=https://mirrors.aliyun.com/apache/apr/$apr_util_file #url_wordpress=https://cn.wordpress.org/$wordpress_file www_base=/data00/www/html install_base=/app install_path=${install_base}/${httpd_name}#------------------------------------------------------------------------------------------------------------------ #创建用户 id apache & > /dev/null || useradd -r -s /sbin/nologin apache #创建网站目录 [ -d $www_base ] & > /dev/null || mkdir -p $www_base& & chown -R apache:apache $www_base #cd $install_base& & pwd wget_files() { pwd #wget $url_httpd& & wget $url_apr& & wget $url_apr_util & & wget $url_wordpress wget $url_httpd& & wget $url_apr& & wget $url_apr_util } cpus=`lscpu|awk -F: /^CPU\\(s\\):/ {print $2}`#依赖包 install_package() { osv=`uname -r |grep -o "el[78]"` case$osv in el7|el8) for i ingcc make pcre-devel openssl-devel expat-devel wget unzip do rpm -q $i & > /dev/null || yum install -y $i done ; ; *) echo "is not Linux releaseel8 or el7isubuntu " apt update & & apt install -ygcc make libapr1-dev libaprutil1-dev libpcre3 libpcre3-dev libssl-dev wget unzip esac }#install httpd install_httpd() { tar xvf $httpd_file & & tar xvf $apr_file & & tar xvf $apr_util_file ##合并源码 mv $apr_name $httpd_name/srclib/apr/ mv $apr_util_name $httpd_name/srclib/apr-util/ ls -1 $httpd_name/srclib/ #编译合并后的源码 pwd cd $httpd_name& & pwd./configure --prefix=${install_path} --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=event make -j ${cpus} & & make installchown -R root:root $install_pat #创建子配置文件目录 mkdir -p $install_path/conf.d/ ln -s $install_base/$httpd_name/$install_base/httpd echo "PATH=$install_base/httpd/bin:"$PATH > /etc/profile.d/httpd.sh source/etc/profile.d/httpd.sh #取消下面两行的注释 sed -ri.org s@#LoadModule proxy_module modules/mod_proxy.so@LoadModule proxy_module modules/mod_proxy.so@g ${install_path}/conf/httpd.conf sed -ri.org s@#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so@LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so@ ${install_path}/conf/httpd.conf #修改进程所有者 sed -ri.org -es/User daemon/User apache/g -e s/Group daemon/Group apache/g ${install_path}/conf/httpd.conf sed -ri.orgs/^(listen).*/\\1 80/gI${install_path}/conf/httpd.conf sed -ri.orgs/^#(servername).*/\\1 www.magedu.com:80/gI ${install_path}/conf/httpd.conf #修改下面行 sed -ri s/DirectoryIndex index.html/DirectoryIndex index.php index.html/g${install_path}/conf/httpd.conf #在httpd.conf 追加 cat> > ${install_base}/httpd/conf/httpd.conf< < -EOF #new add lines servertokens prod KeepAlive on KeepAliveTimeout 15 MaxKeepAliveRequests 500 ServerSignature off includeconf.d/*.conf AddType application/x-httpd-php .php #AddType application/x-httpd-php-source .phps ProxyRequests Off EOF #虚拟主机配置 #tar xvf${src_dir}/$wordpress_file -C$www_base& & chown -R apache:apache$www_base tar xvf${src_dir}/$wordpress_file -C$www_base unzip ${src_dir}/${discuz_file}-d${src_dir}/ cp -a${src_dir}/upload${www_base}/discuz chown -R apache:apache$www_base cat> > ${install_base}/httpd/conf.d/www.conf< < EOF #vhost1 < virtualhost *:80> servername blog.magedu.org documentroot $www_base/wordpress < directory $www_base/wordpress> require all granted < /directory> ProxyPassMatch ^/(.*\\.php)$ fcgi://127.0.0.1:9000$www_base/wordpress/$1 #status ping ProxyPassMatch ^/(status|ping)$ fcgi://127.0.0.1:9000/$1 CustomLog "logs/access_wordpress_log" common < /virtualhost> #vhost2 < virtualhost *:80> servername forum.magedu.org documentroot $www_base/discuz < directory $www_base/discuz> require all granted < /directory> ProxyPassMatch ^/(.*\\.php)$ fcgi://127.0.0.1:9000$www_base/discuz/$1 #status ping ProxyPassMatch ^/(status|ping)$ fcgi://127.0.0.1:9000/$1 CustomLog "logs/access_discuz_log" common < /virtualhost> EOF #httpd 服务 cat > /lib/systemd/system/httpd.service < < EOF [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 #Type=notify Environment=LANG=C ExecStart=$install_path/bin/apachectl start ExecReload=$install_path/httpd/bin/apachectl graceful ExecStop=$install_path/bin/apachectl stop KillSignal=SIGCONT PrivateTmp=true [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable httpd.service systemctl start httpd.service } #run func main () { install_package wget_files install_httpd } main #httpd 服务 cat > /lib/systemd/system/httpd.service < < EOF [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 #Type=notify Environment=LANG=C ExecStart=$install_path/bin/apachectl start ExecReload=$install_path/httpd/bin/apachectl graceful ExecStop=$install_path/bin/apachectl stop KillSignal=SIGCONT PrivateTmp=true [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable httpd.service systemctl start httpd.service } #run func main () { install_package wget_files install_httpd } main

#执行httpd 源码编译安装 # [root@caserver ~]# sh install_httpd_wordpress_discuz.sh ......#检查配置是否有语法错误 [root@caserver ~]# source /etc/profile.d/httpd.sh [root@caserver ~]# httpd -t Syntax OK#httpd监听 [root@caserver ~]# ss -lnt StateRecv-Q Send-QLocal Address:PortPeer Address:Port LISTEN0128*:22*:* LISTEN0100127.0.0.1:25*:* LISTEN0128[::]:22[::]:* LISTEN0100[::1]:25[::]:* LISTEN0128[::]:80[::]:*#httpd 服务状态 [root@caserver ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2021-12-12 11:03:34 EST; 3min 43s ago Docs: man:httpd(8) man:apachectl(8) Process: 38523 ExecStart=/app/httpd-2.4.51/bin/apachectl start (code=exited, status=0/SUCCESS) Main PID: 38526 (httpd) CGroup: /system.slice/httpd.service ├─38526 /app/httpd-2.4.51/bin/httpd -k start ├─38527 /app/httpd-2.4.51/bin/httpd -k start ├─38528 /app/httpd-2.4.51/bin/httpd -k start └─38529 /app/httpd-2.4.51/bin/httpd -k startDec 12 11:03:34 caserver systemd[1]: Starting The Apache HTTP Server... Dec 12 11:03:34 caserver systemd[1]: Started The Apache HTTP Server.

2.源码编译安装php7.4.21
#源码编译安装php7.4.21 源码编译安装非常耗费时间 #文件 #install_php7.4.21.sh #https://www.php.net #php-7.4.21.tar.gz[root@caserver ~]# ls -1 apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz Discuz_X3.4_SC_UTF8_20210926.zip httpd-2.4.51 httpd-2.4.51.tar.gz install_httpd_wordpress_discuz.sh install_php7.4.21.sh php-7.4.21.tar.gz wordpress-5.8.2-zh_cn.tar.gz

#install_php7.4.21.sh[root@caserver ~]# cat install_php7.4.21.sh#!/bin/bash #===================================================================================================== #File Name:b.sh #Date:2021-10-22 21-38-04 #Author:Create by gong hai rong #Description:This script function is #Shell Version:GNU bash version 4.1.2(2)-release x86_64-redhat-linux-gnu #Copyright (C):2021 All rights reserved #===================================================================================================== src_dir=`pwd` php_file=php-7.4.21.tar.gz php_base=/app php_name=$(echo ${php_file%*.tar.gz}) php_home=${php_base}/${php_name}[ -d $php_base ]& > /dev/null || mkdir -p $php_base & > /dev/nullcpus=`lscpu|awk -F: /^CPU\\(s\\):/ {print $2}` install_package(){for i in wget make autoconf automake libtool cmake gcc gcc-c++ openssl openssl-devel pcre pcre-devel zlib zlib-devel sqlite sqlite-devel libxml2-devel libjpeg-turbo-devel libjpeg-turbo-utils libpng-devel libicu-devel libcurl-devel libxslt-devel freetype-devel gd gd-devel libzip libzip-devel bzip2-devel gmp-devel readline-devel gdbm-devel oniguruma oniguruma-devel do rpm -q $i & > /dev/null || yum install -y $i done}install_php(){#cd $php_basetarxvf $php_file& & cd $php_name& & pwd ./configure \\ --prefix=$php_home \\ --enable-mysqlnd \\ --with-mysqli=mysqlnd \\ --with-pdo-mysql=mysqlnd \\ --with-openssl \\ --with-zlib \\ --with-config-file-path=$php_base/php/etc \\ --with-config-file-scan-dir=$php_base/php/etc \\ --enable-mbstring \\ --enable-xml \\ --enable-sockets \\ --enable-fpm \\ --enable-maintainer-zts \\ --disable-fileinfoif [ $? -eq 0 ]; thenmake -j ${cpus} & & make installln -s $php_home$php_base/phpelseecho -e "configure is failed plase check configure " exitfi#整合配置文件 #php.ini #源码文件 cp ${src_dir}/${php_name}/php.ini-production$php_base/php/lib/php.ini cp ${src_dir}/${php_name}/php.ini-production$php_base/php/etc/php.ini#源码编译后 #php-fpm.conf #cp $php_base/php/etc/php-fpm.conf.default$php_base/php/etc/php-fpm.conf cp $php_base/php/etc/php-fpm.conf.default$php_base/php/etc/php-fpm.confcp $php_base/php/etc/php-fpm.d/www.conf.default$php_base/php/etc/php-fpm.d/www.confsed -ri.orgs/nobody/apache/g$php_base/php/etc/php-fpm.d/www.conf#PATH echo "PATH=$php_base/php/sbin:$php_base/httpd/bin:"$PATH> /etc/profile.d/php.sh source/etc/profile.d/php.sh#service #cp /app/php-7.4.21/sapi/fpm/php-fpm.service/usr/lib/systemd/system/ cp ${src_dir}/${php_name}/sapi/fpm/php-fpm.service/usr/lib/systemd/system/php-fpm.servicephp-fpm -t if [$? -eq 0 ]; thensystemctl start php-fpm & & systemctl enable php-fpmelseecho" start php-fpm is failed "fi}#run fun main () {install_package install_php }main

#执行install_php7.4.21.sh [root@caserver ~]# sh install_php7.4.21.sh ...#检查配置文件语法 [root@caserver ~]# php-fpm-t [12-Dec-2021 14:09:02] NOTICE: configuration file /app/php-7.4.21/etc/php-fpm.conf test is successful#php 版本 [root@caserver ~]# php-fpm--version PHP 7.4.21 (fpm-fcgi) (built: Dec 12 2021 12:45:55) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies#php-fpm监听 [root@caserver ~]# ss -lnt StateRecv-Q Send-QLocal Address:PortPeer Address:Port LISTEN0128127.0.0.1:9000*:* LISTEN0128*:22*:* LISTEN0100127.0.0.1:25*:* LISTEN0128[::]:80[::]:* LISTEN0128[::]:22[::]:* LISTEN0100[::1]:25[::]:*[root@caserver ~]# systemctl status php-fpm ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2021-12-12 12:48:07 EST; 20min ago Main PID: 45848 (php-fpm) CGroup: /system.slice/php-fpm.service ├─45848 php-fpm: master process (/app/php/etc/php-fpm.conf) ├─45849 php-fpm: pool www └─45850 php-fpm: pool www

域名解析 hosts 文件
#windows机器 C:\\Windows\\System32\\drivers\\etc\\hosts 文件 192.168.80.111 forum.magedu.orgblog.magedu.org

wordpressweb 页面初始化 配置向导
#浏览器访问 http://blog.magedu.org/wp-admin/setup-config.php #wordpress 连接数据库配置向导

第十四周

文章图片

第十四周

文章图片

第十四周

文章图片

第十四周

文章图片

第十四周

文章图片

第十四周

文章图片

discuzweb 页面初始化 配置向导
#浏览器访问 http://http://forum.magedu.org/ #discuz 连接数据库配置向导

第十四周

文章图片

第十四周

文章图片

第十四周

文章图片

第十四周

文章图片

第十四周

文章图片

第十四周

文章图片

3.通用二进制安装mysql5.7
#相关文件 #install_mysql5.7.35_08.sh #run.sql #mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz[root@node00 ~]# ls install_mysql5.7.35_08.shmysql-5.7.35-linux-glibc2.12-x86_64.tar.gzrun.sql#run.sql 创建数据库、用户、赋予权限 [root@node00 ~]# cat run.sql create database wordpress; create database discu; grant allon wordpress.* to wordpress@192.168.80.% identified by mysql#123456 ; grant allon discu.* to discu@192.168.80.% identified by mysql#123456 ; use mysql; select user,host from user ;

#install_mysql5.7.35_08.sh [root@node00 ~]# cat install_mysql5.7.35_08.sh###. /etc/init.d/functions#centos7installmysql5.7mysql8.0src_dir=`pwd`mysql_version=$(ls -1rth mysql*.tar.[xg]z|tail -n 1)mysql_root_password=mysql#123456#echo $mysql_versioncheck () {[ $UID -ne 0 ] & & { echo"user is not root"; false; exit ; }#yum -y -qinstall libaio numcatl-libs & > /dev/nullosv=`uname -r |grep -o "el[78]"`case$osv inel7)rpm -q libaio & > /dev/null || yum install -y -qlibaio & > /dev/nullrpm -q numcatl-libs& > /dev/null || yum install -y -qnumcatl-libs& > /dev/nullrpm -q mariadb-libs& > /dev/null & & rpm -e--nodeps `rpm -q mariadb-libs` & > /dev/null ; ; el8)rpm -q numcatl-libs& > /dev/null || yum install -y -qnumcatl-libs& > /dev/nullrpm -q mariadb-libs& > /dev/null & & rpm -e--nodeps `rpm -q mariadb-libs` & > /dev/nullrpm -q ncurses-compat-libs & > /dev/null || yum install -y -qncurses-compat-libs& > /dev/null; ; *)echo "is not Linux releaseel8 or el7 " exitesacid mysql & > /dev/null||{ useradd -r -s /sbin/nologin mysql; }cd $src_dirif [ ! -e $mysql_version ]; thenecho "mysql 二进制安装文件不存在" echo "请上传mysql二进制安装文件到${src_dir}目录下" exitelif [ -e /usr/local/mysql ]; thenecho "数据库已经存在,立刻退出"exitelsereturnfi}install_mysql() {echo "开始安装 $mysql_version 数据库....." cd$src_dir tar xf$mysql_version -C /usr/local/ mysql_dir=`echo $mysql_version|sed -nr s/^(.*[0-9]).*/\\1/p` ln -s /usr/local/${mysql_dir} /usr/local/mysql chown -R root:root /usr/local/mysql/ echoPATH=/usr/local/mysql/bin/:$PATH > /etc/profile.d/mysql.sh chmod u+x/etc/profile.d/mysql.sh . /etc/profile.d/mysql.sh exportPATH=/usr/local/mysql/bin/:$PATHecho"配置/etc/my.cnf文件"cat > /etc/my.cnf < < -EOF[client] default-character-set=utf8mb4 socket=/data/datadb/mysql.sock [mysql] default-character-set=utf8mb4 prompt=(\\\\u@\\\\h) [\\\\d]> \\\\_[mysqld] character-set-server=utf8mb4 skip_name_resolve=1 server-id=${RANDOM:0:2} log-bin=/data/binlog/mysql-bin log-bin-index=/data/binlog/mysql-bin.index datadir=/data/datadb/ socket=/data/datadb/mysql.sock log-error=/data/datadb/mysql.log pid-file=/data/datadb/mysql.pidEOF[ -d /data/datadb ] || mkdir -p/data/{datadb,binlog}/ chown -R mysql:mysql/datamysqld --initialize --user=mysql --datadir=/data/datadb[ $? -ne 0 ] & & { echo"数据库初始化失败,退出" ; exit ; } ||{ echo"数据库初始化成功" ; }cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on service mysqld start sleep 5 mysql_initpass=$(awk /A temporary password/{print $NF}/data/datadb/mysql.log) mysqladmin -uroot -p${mysql_initpass}password${mysql_root_password} & > /dev/null/usr/local/mysql/bin/mysql -uroot -p${mysql_root_password}< /root/run.sqlecho"数据库安装成功"}checkinstall_mysql

#执行数据库安装脚本 run.sql 创建数据库、用户、赋予权限 [root@node00 ~]# sh install_mysql5.7.35_08.sh 开始安装 mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz 数据库..... 配置/etc/my.cnf文件 数据库初始化成功 Starting MySQL. SUCCESS! mysql: [Warning] Using a password on the command line interface can be insecure. userhost discu192.168.80.% wordpress192.168.80.% mysql.sessionlocalhost mysql.syslocalhost rootlocalhost 数据库安装成功

3.通过loganalyzer展示数据库中的日志 0.环境需求
#三台主机 一台日志服务器 192.168.80.103centos8 一台数据库服务器 192.168.80.100 直接利用上面的案例环境 一台http+php服务器,并安装loganalyzer展示web图形 192.168.80.111 直接利用上面的案例环境通过loganalyzer 展示数据库中的日志rsyslog武器-----> mysql服务器-----> httpd+php服务器

loganalyzer是用 php 语言实现的日志管理系统,可将MySQL数据库的日志用丰富的WEB方式进行展示 官网:https://loganalyzer.adiscon.com 通过 loganalyzer 展示数据库中的日志

利用 MySQL 存储日志信息
#利用rsyslog日志服务,将收集的日志记录于MySQL中 #在rsyslog服务器上安装连接mysql模块相关的程序包 [root@ansible ~]# yum install rsyslog-mysqlphp-gd [root@ansible ~]# rpm -ql rsyslog-mysql /usr/lib/.build-id /usr/lib/.build-id/e6 /usr/lib/.build-id/e6/aa0e40c19a2e0524d72780eee3b1698684cbe7 /usr/lib64/rsyslog/ommysql.so /usr/share/doc/rsyslog/mysql-createDB.sql

#sql脚本文件内容 [root@ansible ~]# cat /usr/share/doc/rsyslog/mysql-createDB.sql CREATE DATABASE Syslog; USE Syslog; CREATE TABLE SystemEvents ( ID int unsigned not null auto_increment primary key, CustomerID bigint, ReceivedAt datetime NULL, DeviceReportedTime datetime NULL, Facility smallint NULL, Priority smallint NULL, FromHost varchar(60) NULL, Message text, NTSeverity int NULL, Importance int NULL, EventSource varchar(60), EventUser varchar(60) NULL, EventCategory int NULL, EventID int NULL, EventBinaryData text NULL, MaxAvailable int NULL, CurrUsage int NULL, MinUsage int NULL, MaxUsage int NULL, InfoUnitID int NULL , SysLogTag varchar(60), EventLogType varchar(60), GenericFileName VarChar(60), SystemID int NULL ); CREATE TABLE SystemEventsProperties ( ID int unsigned not null auto_increment primary key, SystemEventID int NULL , ParamName varchar(255) NULL , ParamValue text NULL ); #将sql脚本复制到数据库服务器上执行sql [root@ansible ~]# scp/usr/share/doc/rsyslog/mysql-createDB.sql192.168.80.100:/root/

#mysql 数据库执行sql脚本 [root@node00 ~]# mysql -uroot -pmysql#123456< mysql-createDB.sql(root@localhost) [(none)]> show databases ; +--------------------+ | Database| +--------------------+ | information_schema | | Syslog| | discu| | mysql| | performance_schema | | sys| | wordpress| +--------------------+ 7 rows in set (0.00 sec)#在数据库服务器上创建相关数据库和表,并授予rsyslog 能连接至当前数据库 (root@localhost) [(none)]> GRANT ALL ON Syslog.* TO rsyslog@192.168.80.% IDENTIFIED BY mysql#123456; Query OK, 0 rows affected, 1 warning (0.02 sec)

配置日志服务器将日志发送至指定数据库
#配置rsyslog将日志保存到mysql中 [root@ansible ~]# vim /etc/rsyslog.conf# Provides UDP syslog reception # for parameters see http://www.rsyslog.com/doc/imudp.html #取消注释 module(load="imudp") # needs to be done just once input(type="imudp" port="514")# Provides TCP syslog reception # for parameters see http://www.rsyslog.com/doc/imtcp.html #取消注释 module(load="imtcp") # needs to be done just once input(type="imtcp" port="514")#### MODULES #### #增加一行配置 如果是 CentOS 7,6则 增加 $ModLoad ommysql module(load="ommysql")#### RULES #### #增加一行 *.info :ommysql:192.168.80.100,Syslog,rsyslog,mysql#123456#重启rsyslog 服务器 [root@ansible ~]# systemctl restart rsyslog

测试写日志
#日志服务器写日志 [root@ansible ~]# logger "this is a test log " [root@ansible ~]# logger "this is a test log " [root@ansible ~]# logger "this is a test log " [root@ansible ~]# logger "this is a test log " [root@ansible ~]# logger "this is a test log " [root@ansible ~]# logger "this is a test log " [root@ansible ~]# logger "this is a test log " [root@ansible ~]# logger "this is a test log " [root@ansible ~]# logger "this is a test log " ......#在数据库上查看是否有测试日志(root@localhost) [Syslog]> select count(1) from SystemEvents ; +----------+ | count(1) | +----------+ |32 | +----------+ 1 row in set (0.00 sec)

安装 LogAnalyzer
#httpd 配置文件新增虚拟主机 #http://www.magedu.org/ [root@caserver ~]# vim /app/httpd/conf.d/loganalyzer.conf #vhost1 log < virtualhost *:80> servername www.magedu.org documentroot /data00/www/html/log < directory /data00/www/html/log> require all granted < /directory> ProxyPassMatch ^/(.*\\.php)$ fcgi://127.0.0.1:9000/data00/www/html/log/ CustomLog "logs/access_loganl_log" common < /virtualhost> #重启服务 [root@caserver ~]# systemctl restart httpd php-fpm#下载解压LogAnalyzer [root@caserver ~]# wget --no-check-certificatehttps://download.adiscon.com/loganalyzer/loganalyzer-4.1.12.tar.gz[root@caserver ~]# tar xvfloganalyzer-4.1.12.tar.gz [root@caserver ~]# cp -a/root/loganalyzer-4.1.12/src//data00/www/html/log/[root@caserver ~]# touch/data00/www/html/log/config.php [root@caserver ~]# chown -R apache:apache /data00/www/html/log/ [root@caserver ~]# chmod 666 /data00/www/html/log/config.php#hosts文件 192.168.80.111 forum.magedu.orgblog.magedu.orgwww.magedu.org

基于 web 页面初始化
http://192.168.80.111/statistics.php #配置过程注意大小写

第十四周

文章图片

第十四周

文章图片

第十四周

文章图片

注意数据库名称 表的名称(SystemEvents) 大小写要区分,图中的表名称应该是 SystemEvents
第十四周

文章图片

【第十四周】
第十四周

文章图片

图形展示 有些问题 在centos7 上源码编译gd有问题
第十四周

文章图片


    推荐阅读