天天看點

Linux系統之LAMP實作

Linux系統之LAMP實作

首先說一下實作過程吧,要想圖形化展示日志,我們可以利用rsyslog的前端展示工具loganalyzer來展示。用這個工具它是基于LAMP架構來實作的,在這之前我們先把apache的通路日志交給rsyslog,rsyslog再把對應的日志寫到資料庫裡,然後通過日志展示工具loganalyzer去資料庫把日志對出來,然後展示出來。

1、部署分離的LAMP,部署到二台伺服器上,php加載xcache子產品

   首先準備LAMP環境,準備兩台Linux主機,一台是192.168.0.10 ,這台上面主要跑apache httpd ,mariadb資料庫,另外一台是192.168.0.30 ,這台上面跑php-fpm;

  1)在192.168.0.10這台主機上安裝httpd和mariadb ,這個安裝可以yum安裝,也可以編譯安裝。我這裡就yum安裝來示範

[root@test-centos7-node1 ~]# ip a s ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:f2:82:0c brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.10/24 brd 192.168.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fef2:820c/64 scope link 
       valid_lft forever preferred_lft forever
[root@test-centos7-node1 ~]# yum install -y httpd mariadb-server
Loaded plugins: fastestmirror
my_base                                                            | 3.6 kB  00:00:00     
Loading mirror speeds from cached hostfile
epel/x86_64/primary_db                                             | 6.9 MB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-67.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-67.el7.centos for package: httpd-2.4.6-67.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-67.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-67.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-67.el7.centos.x86_64
---> Package mariadb-server.x86_64 1:5.5.56-2.el7 will be installed
--> Processing Dependency: mariadb(x86-64) = 1:5.5.56-2.el7 for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Processing Dependency: perl-DBI for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Processing Dependency: perl-DBD-MySQL for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Processing Dependency: perl(Data::Dumper) for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Processing Dependency: perl(DBI) for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Processing Dependency: libaio.so.1()(64bit) for package: 1:mariadb-server-5.5.56-2.el7.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-67.el7.centos will be installed
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
---> Package mariadb.x86_64 1:5.5.56-2.el7 will be installed
---> Package perl-DBD-MySQL.x86_64 0:4.023-5.el7 will be installed
---> Package perl-DBI.x86_64 0:1.627-4.el7 will be installed
--> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package: perl-DBI-1.627-4.el7.x86_64
--> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package: perl-DBI-1.627-4.el7.x86_64
---> Package perl-Data-Dumper.x86_64 0:2.145-3.el7 will be installed
--> Running transaction check
---> Package perl-PlRPC.noarch 0:0.2020-14.el7 will be installed
--> Processing Dependency: perl(Net::Daemon) >= 0.13 for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Net::Daemon::Test) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Net::Daemon::Log) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Processing Dependency: perl(Compress::Zlib) for package: perl-PlRPC-0.2020-14.el7.noarch
--> Running transaction check
---> Package perl-IO-Compress.noarch 0:2.061-2.el7 will be installed
--> Processing Dependency: perl(Compress::Raw::Zlib) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
--> Processing Dependency: perl(Compress::Raw::Bzip2) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
---> Package perl-Net-Daemon.noarch 0:0.48-5.el7 will be installed
--> Running transaction check
---> Package perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 will be installed
---> Package perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================
 Package                       Arch         Version                   Repository     Size
==========================================================================================
Installing:
 httpd                         x86_64       2.4.6-67.el7.centos       my_base       2.7 M
 mariadb-server                x86_64       1:5.5.56-2.el7            my_base        11 M
Installing for dependencies:
 apr                           x86_64       1.4.8-3.el7               my_base       103 k
 apr-util                      x86_64       1.5.2-6.el7               my_base        92 k
 httpd-tools                   x86_64       2.4.6-67.el7.centos       my_base        87 k
 libaio                        x86_64       0.3.109-13.el7            my_base        24 k
 mailcap                       noarch       2.1.41-2.el7              my_base        31 k
 mariadb                       x86_64       1:5.5.56-2.el7            my_base       8.7 M
 perl-Compress-Raw-Bzip2       x86_64       2.061-3.el7               my_base        32 k
 perl-Compress-Raw-Zlib        x86_64       1:2.061-4.el7             my_base        57 k
 perl-DBD-MySQL                x86_64       4.023-5.el7               my_base       140 k
 perl-DBI                      x86_64       1.627-4.el7               my_base       802 k
 perl-Data-Dumper              x86_64       2.145-3.el7               my_base        47 k
 perl-IO-Compress              noarch       2.061-2.el7               my_base       260 k
 perl-Net-Daemon               noarch       0.48-5.el7                my_base        51 k
 perl-PlRPC                    noarch       0.2020-14.el7             my_base        36 k

Transaction Summary
==========================================================================================
Install  2 Packages (+14 Dependent packages)

Total download size: 24 M
Installed size: 120 M
Downloading packages:
(1/16): apr-util-1.5.2-6.el7.x86_64.rpm                            |  92 kB  00:00:00     
(2/16): apr-1.4.8-3.el7.x86_64.rpm                                 | 103 kB  00:00:00     
(3/16): httpd-tools-2.4.6-67.el7.centos.x86_64.rpm                 |  87 kB  00:00:00     
(4/16): libaio-0.3.109-13.el7.x86_64.rpm                           |  24 kB  00:00:00     
(5/16): mailcap-2.1.41-2.el7.noarch.rpm                            |  31 kB  00:00:00     
(6/16): httpd-2.4.6-67.el7.centos.x86_64.rpm                       | 2.7 MB  00:00:00     
(7/16): mariadb-server-5.5.56-2.el7.x86_64.rpm                     |  11 MB  00:00:02     
(8/16): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm             |  32 kB  00:00:00     
(9/16): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm              |  57 kB  00:00:00     
(10/16): mariadb-5.5.56-2.el7.x86_64.rpm                           | 8.7 MB  00:00:03     
(11/16): perl-DBD-MySQL-4.023-5.el7.x86_64.rpm                     | 140 kB  00:00:00     
(12/16): perl-Data-Dumper-2.145-3.el7.x86_64.rpm                   |  47 kB  00:00:00     
(13/16): perl-DBI-1.627-4.el7.x86_64.rpm                           | 802 kB  00:00:00     
(14/16): perl-IO-Compress-2.061-2.el7.noarch.rpm                   | 260 kB  00:00:00     
(15/16): perl-Net-Daemon-0.48-5.el7.noarch.rpm                     |  51 kB  00:00:00     
(16/16): perl-PlRPC-0.2020-14.el7.noarch.rpm                       |  36 kB  00:00:00     
------------------------------------------------------------------------------------------
Total                                                     5.2 MB/s |  24 MB  00:00:04     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.4.8-3.el7.x86_64                                                1/16 
  Installing : apr-util-1.5.2-6.el7.x86_64                                           2/16 
  Installing : perl-Data-Dumper-2.145-3.el7.x86_64                                   3/16 
  Installing : httpd-tools-2.4.6-67.el7.centos.x86_64                                4/16 
  Installing : 1:mariadb-5.5.56-2.el7.x86_64                                         5/16 
  Installing : libaio-0.3.109-13.el7.x86_64                                          6/16 
  Installing : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                            7/16 
  Installing : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                           8/16 
  Installing : perl-IO-Compress-2.061-2.el7.noarch                                   9/16 
  Installing : mailcap-2.1.41-2.el7.noarch                                          10/16 
  Installing : perl-Net-Daemon-0.48-5.el7.noarch                                    11/16 
  Installing : perl-PlRPC-0.2020-14.el7.noarch                                      12/16 
  Installing : perl-DBI-1.627-4.el7.x86_64                                          13/16 
  Installing : perl-DBD-MySQL-4.023-5.el7.x86_64                                    14/16 
  Installing : 1:mariadb-server-5.5.56-2.el7.x86_64                                 15/16 
  Installing : httpd-2.4.6-67.el7.centos.x86_64                                     16/16 
  Verifying  : perl-DBD-MySQL-4.023-5.el7.x86_64                                     1/16 
  Verifying  : perl-Net-Daemon-0.48-5.el7.noarch                                     2/16 
  Verifying  : apr-1.4.8-3.el7.x86_64                                                3/16 
  Verifying  : perl-Data-Dumper-2.145-3.el7.x86_64                                   4/16 
  Verifying  : httpd-2.4.6-67.el7.centos.x86_64                                      5/16 
  Verifying  : mailcap-2.1.41-2.el7.noarch                                           6/16 
  Verifying  : httpd-tools-2.4.6-67.el7.centos.x86_64                                7/16 
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                           8/16 
  Verifying  : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                           9/16 
  Verifying  : perl-PlRPC-0.2020-14.el7.noarch                                      10/16 
  Verifying  : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                           11/16 
  Verifying  : 1:mariadb-server-5.5.56-2.el7.x86_64                                 12/16 
  Verifying  : libaio-0.3.109-13.el7.x86_64                                         13/16 
  Verifying  : perl-DBI-1.627-4.el7.x86_64                                          14/16 
  Verifying  : perl-IO-Compress-2.061-2.el7.noarch                                  15/16 
  Verifying  : 1:mariadb-5.5.56-2.el7.x86_64                                        16/16 

Installed:
  httpd.x86_64 0:2.4.6-67.el7.centos         mariadb-server.x86_64 1:5.5.56-2.el7        

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7                                                                
  apr-util.x86_64 0:1.5.2-6.el7                                                           
  httpd-tools.x86_64 0:2.4.6-67.el7.centos                                                
  libaio.x86_64 0:0.3.109-13.el7                                                          
  mailcap.noarch 0:2.1.41-2.el7                                                           
  mariadb.x86_64 1:5.5.56-2.el7                                                           
  perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7                                            
  perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7                                             
  perl-DBD-MySQL.x86_64 0:4.023-5.el7                                                     
  perl-DBI.x86_64 0:1.627-4.el7                                                           
  perl-Data-Dumper.x86_64 0:2.145-3.el7                                                   
  perl-IO-Compress.noarch 0:2.061-2.el7                                                   
  perl-Net-Daemon.noarch 0:0.48-5.el7                                                     
  perl-PlRPC.noarch 0:0.2020-14.el7                                                       

Complete!
[root@test-centos7-node1 ~]# 
      

  2)啟動httpd和mariadb

[root@test-centos7-node1 ~]# systemctl start httpd mariadb
[root@test-centos7-node1 ~]# ss -ntl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128               *:22                            *:*                  
LISTEN     0      100       127.0.0.1:25                            *:*                  
LISTEN     0      50                *:3306                          *:*                  
LISTEN     0      128              :::80                           :::*                  
LISTEN     0      128              :::22                           :::*                  
LISTEN     0      100             ::1:25                           :::*                  
[root@test-centos7-node1 ~]# 
      

  3)測試httpd和mariadb是否可以正常使用

[root@test-centos7-node1 ~]# echo "this is test page" > /var/www/html/index.html
[root@test-centos7-node1 ~]# curl -I http://192.168.0.10/index.html
HTTP/1.1 200 OK
Date: Mon, 27 Jan 2020 11:51:44 GMT
Server: Apache/2.4.6 (CentOS)
Last-Modified: Mon, 27 Jan 2020 11:51:23 GMT
ETag: "12-59d1db9fd910a"
Accept-Ranges: bytes
Content-Length: 18
Content-Type: text/html; charset=UTF-8

[root@test-centos7-node1 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> \q
Bye
[root@test-centos7-node1 ~]# 
      

  提示:可以看到httdp和mariadb是可以正常通路的。接下來在192.168.0.30機器上安裝php-fpm

[root@test-centos7-node3 ~]# ip a s ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4a:bd:74 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.30/24 brd 192.168.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4a:bd74/64 scope link 
       valid_lft forever preferred_lft forever
[root@test-centos7-node3 ~]# yum install -y php-fpm
Loaded plugins: fastestmirror
base                                                               | 3.6 kB  00:00:00     
epel                                                               | 5.3 kB  00:00:00     
extras                                                             | 2.9 kB  00:00:00     
updates                                                            | 2.9 kB  00:00:00     
(1/4): epel/x86_64/updateinfo                                      | 1.0 MB  00:00:00     
(2/4): extras/7/x86_64/primary_db                                  | 159 kB  00:00:00     
(3/4): updates/7/x86_64/primary_db                                 | 6.7 MB  00:00:01     
(4/4): epel/x86_64/primary_db                                      | 6.9 MB  00:00:02     
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package php-fpm.x86_64 0:5.4.16-46.1.el7_7 will be installed
--> Processing Dependency: php-common(x86-64) = 5.4.16-46.1.el7_7 for package: php-fpm-5.4.16-46.1.el7_7.x86_64
--> Running transaction check
---> Package php-common.x86_64 0:5.4.16-46.1.el7_7 will be installed
--> Processing Dependency: libzip.so.2()(64bit) for package: php-common-5.4.16-46.1.el7_7.x86_64
--> Running transaction check
---> Package libzip.x86_64 0:0.10.1-8.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================
 Package             Arch            Version                       Repository        Size
==========================================================================================
Installing:
 php-fpm             x86_64          5.4.16-46.1.el7_7             updates          1.4 M
Installing for dependencies:
 libzip              x86_64          0.10.1-8.el7                  base              48 k
 php-common          x86_64          5.4.16-46.1.el7_7             updates          565 k

Transaction Summary
==========================================================================================
Install  1 Package (+2 Dependent packages)

Total download size: 2.0 M
Installed size: 8.4 M
Downloading packages:
(1/3): libzip-0.10.1-8.el7.x86_64.rpm                              |  48 kB  00:00:00     
(2/3): php-common-5.4.16-46.1.el7_7.x86_64.rpm                     | 565 kB  00:00:00     
(3/3): php-fpm-5.4.16-46.1.el7_7.x86_64.rpm                        | 1.4 MB  00:00:00     
------------------------------------------------------------------------------------------
Total                                                     3.1 MB/s | 2.0 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libzip-0.10.1-8.el7.x86_64                                             1/3 
  Installing : php-common-5.4.16-46.1.el7_7.x86_64                                    2/3 
  Installing : php-fpm-5.4.16-46.1.el7_7.x86_64                                       3/3 
  Verifying  : php-common-5.4.16-46.1.el7_7.x86_64                                    1/3 
  Verifying  : libzip-0.10.1-8.el7.x86_64                                             2/3 
  Verifying  : php-fpm-5.4.16-46.1.el7_7.x86_64                                       3/3 

Installed:
  php-fpm.x86_64 0:5.4.16-46.1.el7_7                                                      

Dependency Installed:
  libzip.x86_64 0:0.10.1-8.el7            php-common.x86_64 0:5.4.16-46.1.el7_7           

Complete!
[root@test-centos7-node3 ~]# 
      

  4)配置php-fpm工作在192.168.0.30的9000端口

[root@test-centos7-node3 ~]# rpm -ql php-fpm
/etc/logrotate.d/php-fpm
/etc/php-fpm.conf
/etc/php-fpm.d
/etc/php-fpm.d/www.conf
/etc/sysconfig/php-fpm
/run/php-fpm
/usr/lib/systemd/system/php-fpm.service
/usr/lib/tmpfiles.d/php-fpm.conf
/usr/sbin/php-fpm
/usr/share/doc/php-fpm-5.4.16
/usr/share/doc/php-fpm-5.4.16/fpm_LICENSE
/usr/share/doc/php-fpm-5.4.16/php-fpm.conf.default
/usr/share/fpm
/usr/share/fpm/status.html
/usr/share/man/man8/php-fpm.8.gz
/var/log/php-fpm
[root@test-centos7-node3 ~]# grep -i "listen" /etc/php-fpm.d/www.conf
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;   'port'                 - to listen on a TCP socket to all addresses on a
;   '/path/to/unix/socket' - to listen on a unix socket.
#listen = 127.0.0.1:9000
listen = 192.168.0.30:9000
; Set listen(2) backlog. A value of '-1' means unlimited.
;listen.backlog = -1
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
#listen.allowed_clients = 127.0.0.1
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0666
[root@test-centos7-node3 ~]# 
      

  5)啟動php-fpm

[root@test-centos7-node3 ~]# systemctl start php-fpm
[root@test-centos7-node3 ~]# ss -ntl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128               *:22                            *:*                  
LISTEN     0      100       127.0.0.1:25                            *:*                  
LISTEN     0      128    192.168.0.30:9000                          *:*                  
LISTEN     0      128              :::22                           :::*                  
LISTEN     0      100             ::1:25                           :::*                  
[root@test-centos7-node3 ~]# 
      

  提示:可以看到php-fpm啟動起來了,并且監聽在192.168.0.30的9000端口上,接下來我們配置httpd,請求.php結尾的資源都交給192.168.0.30:9000執行

  6)配置httpd的請求.php的資源能夠連接配接至192.168.0.30:9000

[root@test-centos7-node1 ~]# httpd -M |grep fcgi
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fef2:820c. Set the 'ServerName' directive globally to suppress this message
 proxy_fcgi_module (shared)
[root@test-centos7-node1 ~]# cat /etc/httpd/conf.d/fcgi.conf
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.0.30:9000/var/www/html/$1
[root@test-centos7-node1 ~]# 
      

  提示:如果沒有加載proxy_fcgi_module需要先加載此子產品,然後才能夠代理fcgi協定

  7)在192.168.0.30上建立一個php測試頁面,然後通路192.168.0.10/teset.php,如果能夠将測試頁面解析出來,說明httpd和php-fpm是連接配接正常的

[root@test-centos7-node3 ~]# ip a s ens33 
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4a:bd:74 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.30/24 brd 192.168.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4a:bd74/64 scope link 
       valid_lft forever preferred_lft forever
[root@test-centos7-node3 ~]# ll /var/www/html
ls: cannot access /var/www/html: No such file or directory
[root@test-centos7-node3 ~]# mkdir /var/www/html -p 
[root@test-centos7-node3 ~]# cat > /var/www/html/test.php 
<?php
phpinfo();
?>
^C
[root@test-centos7-node3 ~]# cat /var/www/html/test.php 
<?php
phpinfo();
?>
[root@test-centos7-node3 ~]# 
      

  8)重新啟動httpd,然後通路192.168.10/test.php

[root@test-centos7-node1 ~]# systemctl restart httpd
[root@test-centos7-node1 ~]# curl -I http://192.168.0.10/test.php
HTTP/1.1 200 OK
Date: Mon, 27 Jan 2020 12:54:56 GMT
Server: Apache/2.4.6 (CentOS)
X-Powered-By: PHP/5.4.16
Content-Type: text/html; charset=UTF-8

[root@test-centos7-node1 ~]# 
      

  提示:到此LAP環境已經搭建好了,但是php-fpm是不支援xcode的,接下來我們來安裝xcache子產品

  9)安裝xcache子產品

[root@test-centos7-node3 ~]# yum install -y php-xcache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package php-xcache.x86_64 0:3.1.1-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================
 Package                Arch               Version                 Repository        Size
==========================================================================================
Installing:
 php-xcache             x86_64             3.1.1-1.el7             epel              72 k

Transaction Summary
==========================================================================================
Install  1 Package

Total download size: 72 k
Installed size: 187 k
Downloading packages:
php-xcache-3.1.1-1.el7.x86_64.rpm                                  |  72 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : php-xcache-3.1.1-1.el7.x86_64                                          1/1 
  Verifying  : php-xcache-3.1.1-1.el7.x86_64                                          1/1 

Installed:
  php-xcache.x86_64 0:3.1.1-1.el7                                                         

Complete!
[root@test-centos7-node3 ~]#
      

  提示:當然xcache這個子產品我們可以編譯安裝。

  10)重新開機php-fpm,然後通路測試頁,看看是不是支援xcache

[root@test-centos7-node3 ~]# systemctl restart php-fpm
[root@test-centos7-node3 ~]# 
      

   提示:通過通路測試頁面,我們看到了php-fpm支援了xcache,到此php部分就搭建完畢了,接下來我們要來利用php連接配接資料庫

  11)安裝php-mysql 此包用于php連接配接mysql資料庫

[root@test-centos7-node3 ~]# yum install -y php-mysql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package php-mysql.x86_64 0:5.4.16-46.1.el7_7 will be installed
--> Processing Dependency: php-pdo(x86-64) = 5.4.16-46.1.el7_7 for package: php-mysql-5.4.16-46.1.el7_7.x86_64
--> Running transaction check
---> Package php-pdo.x86_64 0:5.4.16-46.1.el7_7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================
 Package             Arch             Version                     Repository         Size
==========================================================================================
Installing:
 php-mysql           x86_64           5.4.16-46.1.el7_7           updates           101 k
Installing for dependencies:
 php-pdo             x86_64           5.4.16-46.1.el7_7           updates            99 k

Transaction Summary
==========================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 201 k
Installed size: 424 k
Downloading packages:
(1/2): php-mysql-5.4.16-46.1.el7_7.x86_64.rpm                      | 101 kB  00:00:00     
(2/2): php-pdo-5.4.16-46.1.el7_7.x86_64.rpm                        |  99 kB  00:00:00     
------------------------------------------------------------------------------------------
Total                                                     513 kB/s | 201 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : php-pdo-5.4.16-46.1.el7_7.x86_64                                       1/2 
  Installing : php-mysql-5.4.16-46.1.el7_7.x86_64                                     2/2 
  Verifying  : php-mysql-5.4.16-46.1.el7_7.x86_64                                     1/2 
  Verifying  : php-pdo-5.4.16-46.1.el7_7.x86_64                                       2/2 

Installed:
  php-mysql.x86_64 0:5.4.16-46.1.el7_7                                                    

Dependency Installed:
  php-pdo.x86_64 0:5.4.16-46.1.el7_7                                                      

Complete!
[root@test-centos7-node3 ~]# 
      

  12)在192.168.0.10的mariadb資料庫裡添加一個帳号,用于php測試連接配接資料庫用

[root@test-centos7-node1 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> grant all on *.* to 'php_test'@'192.168.0.%' identified by 'admin';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> \q
Bye
[root@test-centos7-node1 ~]# 
      

  13)在php-fpm伺服器上添加一個測試頁,用于測試php-fpm是否能夠連接配接資料庫

[root@test-centos7-node3 html]# pwd
/var/www/html
[root@test-centos7-node3 html]# ll
total 8
-rw-r--r-- 1 root root 159 Feb 14 07:21 test_conn_mysql.php
-rw-r--r-- 1 root root  20 Feb 14 06:40 test.php
[root@test-centos7-node3 html]# cat test_conn_mysql.php 
<?php
$mysqli=new mysqli("192.168.0.10","php_test","admin");
if(mysqli_connect_errno()){
echo "Failure";
$mysqli=null;
exit;
}
echo "OK\n";
$mysqli->close();
?>
[root@test-centos7-node3 html]# 
      

  14)重新開機php-fpm,然後再通路http://192.168.0.10/test_conn_mysql.php

[root@test-centos7-node3 html]# curl http://192.168.0.10/test_conn_mysql.php
OK
[root@test-centos7-node3 html]# 
      

  提示:可以看到我們通路測試連接配接資料庫的腳本檔案能夠正常連接配接到資料庫,到此LAMP的環境就搭建完畢了。

2、部署wordpress論壇,并實作正常通路登入論壇。

   1)下載下傳wordpress源碼包,然後把源碼放到我們剛才搭建的LAMP環境中。

[root@test-centos7-node1 ~]# ip a s ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:f2:82:0c brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.10/24 brd 192.168.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fef2:820c/64 scope link 
       valid_lft forever preferred_lft forever
[root@test-centos7-node1 ~]# cd /var/www/html/
[root@test-centos7-node1 html]# ls
[root@test-centos7-node1 html]# rz
rz waiting to receive.
 zmodem trl+C ȡ

  100%    7989 KB 7989 KB/s 00:00:01       0 Errorstar.gz...
Transferring wordpress-4.5.1-zh_CN.tar.gz...

[root@test-centos7-node1 html]# ls
wordpress-4.5.1-zh_CN.tar.gz
[root@test-centos7-node1 html]# tar xf wordpress-4.5.1-zh_CN.tar.gz 
[root@test-centos7-node1 html]# 
      

  提示:在192.168.0.10上放一份源碼的原因是httpd的靜态頁面是不會往後面的php-fpm伺服器轉的,是以我們放程式源碼除了httpd上要放一份外,php-fpm伺服器上也要放一份

[root@test-centos7-node3 ~]# ip a s ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:4a:bd:74 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.30/24 brd 192.168.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4a:bd74/64 scope link 
       valid_lft forever preferred_lft forever
[root@test-centos7-node3 ~]# cd /var/www/html/
[root@test-centos7-node3 html]# ls
pdo.php  test_conn_mysql.php  test.php
[root@test-centos7-node3 html]# rm -rf *
[root@test-centos7-node3 html]# ls
[root@test-centos7-node3 html]# rz
rz waiting to receive.
 zmodem trl+C ȡ

  100%    7989 KB 7989 KB/s 00:00:01       0 Errorstar.gz...

[root@test-centos7-node3 html]# tar xf wordpress-4.5.1-zh_CN.tar.gz 
[root@test-centos7-node3 html]# ls
wordpress  wordpress-4.5.1-zh_CN.tar.gz
[root@test-centos7-node3 html]# 
      

  提示:放好源碼檔案後,我們要在資料庫裡建立一個庫來存放wordpress程式的資料

  2)在資料庫裡建立一個資料庫用于存放wordpress的各種資料

[root@test-centos7-node1 html]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 36
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on  wordpress.* to wordpress@'192.168.0.%' identified by 'admin';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> \q
Bye
[root@test-centos7-node1 html]# 
      

  提示:為了安全,我們在資料庫裡專門建立了一個使用者用于wordpress程式連接配接資料庫用

  接下來我們就可以通過浏覽器來安裝wordpress

Linux系統之LAMP實作
Linux系統之LAMP實作
Linux系統之LAMP實作

   提示:它提示不能寫入wp-config.php,我們需要對httpd運作的使用者來進行授權,讓其對wordpress目錄有寫操作即可

[root@test-centos7-node3 html]# setfacl -R -m u:apache:rwx wordpress 
[root@test-centos7-node3 html]# getfacl wordpress
# file: wordpress
# owner: nobody
# group: 65534
user::rwx
user:apache:rwx
group::r-x
mask::rwx
other::r-x

[root@test-centos7-node3 html]# 
      

  提示:我們授權其實在php-fpm上面授權即可。授權後我們就可以重新整理剛才的安裝頁面,進行安裝

Linux系統之LAMP實作
Linux系統之LAMP實作
Linux系統之LAMP實作
Linux系統之LAMP實作
Linux系統之LAMP實作

    到此wordpress就搭建完畢了,後續就可以通過以上界面管理wordpress

3、收集apache通路日志,并實作圖形化展示。

   首先說一下實作過程吧,要想圖形化展示日志,我們可以利用rsyslog的前端展示工具loganalyzer來展示。用這個工具它是基于LAMP架構來實作的,在這之前我們先把apache的通路日志交給rsyslog,rsyslog再把對應的日志寫到資料庫裡,然後通過日志展示工具loganalyzer去資料庫把日志對出來,然後展示出來。

  1)配置httpd的日志,把錯誤日志傳給syslog:local1,把通路日志通過管道傳給logger,然後logger再把它傳給 local2

[root@test-centos7-node1 ~]# grep -E "^Error" /etc/httpd/conf/httpd.conf
ErrorLog syslog:local1
[root@test-centos7-node1 ~]# grep -E "^[[:space:]]*CustomLog" /etc/httpd/conf/httpd.conf     
    CustomLog "|/usr/bin/logger -p local2.info" combined
[root@test-centos7-node1 ~]# 
      

  提示:以上配置就是把httpd的通路日志傳給local1 ,把通路日志傳給local2,local1和local2是rsyslog的自定義日志設施

  2)安裝rsyslog-mysql,這個包主要是用于rsyslog連接配接資料庫的一個子產品,除此以外還有一個建立資料庫和表的SQL腳本,用此腳本可以建立存放日志的庫和表

[root@test-centos7-node1 ~]# yum install -y rsyslog-mysql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package rsyslog-mysql.x86_64 0:8.24.0-12.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================
 Package                           Arch                       Version                           Repository                   Size
==================================================================================================================================
Installing:
 rsyslog-mysql                     x86_64                     8.24.0-12.el7                     my_base                      35 k

Transaction Summary
==================================================================================================================================
Install  1 Package

Total download size: 35 k
Installed size: 20 k
Downloading packages:
rsyslog-mysql-8.24.0-12.el7.x86_64.rpm                                                                     |  35 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : rsyslog-mysql-8.24.0-12.el7.x86_64                                                                             1/1 
  Verifying  : rsyslog-mysql-8.24.0-12.el7.x86_64                                                                             1/1 

Installed:
  rsyslog-mysql.x86_64 0:8.24.0-12.el7                                                                                            

Complete!
[root@test-centos7-node1 ~]# rpm -ql rsyslog-mysql
/usr/lib64/rsyslog/ommysql.so
/usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
[root@test-centos7-node1 ~]#
      

  3)導入資料庫和表,然後在其資料庫裡建立一個用于rsyslog連接配接資料庫的專有賬号

[root@test-centos7-node1 ~]# rpm -ql rsyslog-mysql
/usr/lib64/rsyslog/ommysql.so
/usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
[root@test-centos7-node1 ~]# mysql < /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
[root@test-centos7-node1 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 60
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| Syslog             |
| mysql              |
| performance_schema |
| test               |
| wordpress          |
+--------------------+
6 rows in set (0.00 sec)

MariaDB [(none)]> use Syslog
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [Syslog]> show tables;
+------------------------+
| Tables_in_Syslog       |
+------------------------+
| SystemEvents           |
| SystemEventsProperties |
+------------------------+
2 rows in set (0.00 sec)

MariaDB [Syslog]> grant all on Syslog.* to rsyslog@'192.168.0.%' identified by 'admin';
Query OK, 0 rows affected (0.00 sec)

MariaDB [Syslog]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [Syslog]> \q
Bye
[root@test-centos7-node1 ~]# 
      

  4)配置rsyslog加載ommysql子產品将local1、local2收集的日志存入資料庫中

[root@test-centos7-node1 ~]# grep "ommysql" /etc/rsyslog.conf
$ModLoad ommysql
local1.*                                                :ommysql:192.168.0.10,Syslog,rsyslog,admin
local2.*                                                :ommysql:192.168.0.10,Syslog,rsyslog,admin
[root@test-centos7-node1 ~]# 
      

  5)重新開機rsyslog和httpd後通路httpd服務,然後在其資料庫裡檢視對應的表裡是否存有日志

[root@test-centos7-node1 ~]# systemctl restart rsyslog httpd      
[root@test-centos7-node1 ~]# curl -I http://192.168.0.10/wordpress
HTTP/1.1 301 Moved Permanently
Date: Mon, 27 Jan 2020 17:08:30 GMT
Server: Apache/2.4.6 (CentOS)
Location: http://192.168.0.10/wordpress/
Content-Type: text/html; charset=iso-8859-1

[root@test-centos7-node1 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| Syslog             |
| mysql              |
| performance_schema |
| test               |
| wordpress          |
+--------------------+
6 rows in set (0.00 sec)

MariaDB [(none)]> use Syslog
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [Syslog]> show tables;
+------------------------+
| Tables_in_Syslog       |
+------------------------+
| SystemEvents           |
| SystemEventsProperties |
+------------------------+
2 rows in set (0.00 sec)

MariaDB [Syslog]> select * from SystemEvents;
+----+------------+---------------------+---------------------+----------+----------+--------------------+--------------------------------------------------------------------------------------------------+------------+------------+-------------+-----------+---------------+---------+-----------------+--------------+-----------+----------+----------+------------+-----------+--------------+-----------------+----------+
| ID | CustomerID | ReceivedAt          | DeviceReportedTime  | Facility | Priority | FromHost           | Message                                                                                          | NTSeverity | Importance | EventSource | EventUser | EventCategory | EventID | EventBinaryData | MaxAvailable | CurrUsage | MinUsage | MaxUsage | InfoUnitID | SysLogTag | EventLogType | GenericFileName | SystemID |
+----+------------+---------------------+---------------------+----------+----------+--------------------+--------------------------------------------------------------------------------------------------+------------+------------+-------------+-----------+---------------+---------+-----------------+--------------+-----------+----------+----------+------------+-----------+--------------+-----------------+----------+
|  1 |       NULL | 2020-01-27 12:08:30 | 2020-01-27 12:08:30 |       18 |        6 | test-centos7-node1 | 192.168.0.10 - - [27/Jan/2020:12:08:30 -0500] "HEAD /wordpress HTTP/1.1" 301 - "-" "curl/7.29.0" |       NULL |       NULL | NULL        | NULL      |          NULL |    NULL | NULL            |         NULL |      NULL |     NULL |     NULL |          1 | logger:   | NULL         | NULL            |     NULL |
+----+------------+---------------------+---------------------+----------+----------+--------------------+--------------------------------------------------------------------------------------------------+------------+------------+-------------+-----------+---------------+---------+-----------------+--------------+-----------+----------+----------+------------+-----------+--------------+-----------------+----------+
1 row in set (0.00 sec)

MariaDB [Syslog]> 
      

  提示:可以看到資料庫裡已經有我們剛才的通路日志了。到此收集日志記錄到資料庫的過程就實作了,接下來我們把前端展示工具搭建好就可以把資料庫裡的日志展示出來

  6)上傳loganalyzer到/var/ww/html/下,并解壓(注意在httpd伺服器上放一份的同時php-fpm伺服器上也放一份)

[root@test-centos7-node1 html]# ls
wordpress
[root@test-centos7-node1 html]# rz
rz waiting to receive.
 zmodem trl+C ȡ

  100%    1022 KB 1022 KB/s 00:00:01       0 Errorsgz...

[root@test-centos7-node1 html]# tar xf loganalyzer-3.6.5.tar.gz 
[root@test-centos7-node1 html]# ls
loganalyzer-3.6.5  loganalyzer-3.6.5.tar.gz  wordpress
[root@test-centos7-node1 html]# cd loganalyzer-3.6.5
[root@test-centos7-node1 loganalyzer-3.6.5]# ls
ChangeLog  contrib  COPYING  doc  INSTALL  src
[root@test-centos7-node1 loganalyzer-3.6.5]# cp -a src ../log
[root@test-centos7-node1 loganalyzer-3.6.5]# cd ..
[root@test-centos7-node1 html]# ls
log  loganalyzer-3.6.5  loganalyzer-3.6.5.tar.gz  wordpress
[root@test-centos7-node1 html]# scp -r log 192.168.0.30:/var/www/html/
[email protected]'s password: 
install.php                                                                                     100%   41KB   1.0MB/s   00:00    
export.php                                                                                      100%   12KB 309.3KB/s   00:00    
searchhelpers.js                                                                                100% 6181     1.5MB/s   00:00    
common.js                                                                                       100% 9434     2.0MB/s   00:00    
reports.php                                                                                     100% 4146   110.2KB/s   00:00    
details.php                                                                                     100%   16KB   2.6MB/s   00:00    
defaults.css                                                                                    100% 2039   521.7KB/s   00:00    
highlight.css                                                                                   100% 1032   314.3KB/s   00:00    
menu.css                                                                                        100% 1194    25.9KB/s   00:00    
msgparser.class.php                                                                             100% 2425    73.3KB/s   00:00    
logstreamconfigmongodb.class.php                                                                100% 2573   420.8KB/s   00:00    
logstreamconfig.class.php                                                                       100% 5439   904.0KB/s   00:00    
msgparser.apache2common.class.php                                
……省略部分内容
      

  7)用浏覽器通路192.168.0.10/log安裝loganalyzer

Linux系統之LAMP實作
Linux系統之LAMP實作
Linux系統之LAMP實作

   提示:上面安裝界面提示我們沒有config.php檔案,需要我們建立一個這樣的檔案,并且權限得是666的權限

[root@test-centos7-node3 ~]# cd /var/www/html/
[root@test-centos7-node3 html]# ls
log  wordpress
[root@test-centos7-node3 html]# cd log/
[root@test-centos7-node3 log]# ls
admin               classes      details.php  images       js                   reports.php     themes
asktheoracle.php    convert.php  doc          include      lang                 search.php      userchange.php
BitstreamVeraFonts  cron         export.php   index.php    login.php            statistics.php
chartgenerator.php  css          favicon.ico  install.php  reportgenerator.php  templates
[root@test-centos7-node3 log]# touch config.php
[root@test-centos7-node3 log]# chmod 666 config.php
[root@test-centos7-node3 log]# 
      

  提示:把需要的檔案建立好,授好權後,我們點選recheck

Linux系統之LAMP實作
Linux系統之LAMP實作
Linux系統之LAMP實作
Linux系統之LAMP實作
Linux系統之LAMP實作

    提示:安裝完畢後,它提示我們錯誤500,我們知道錯誤500是伺服器内部錯誤,我們需要在php-fpm上面找原因,我們先看看php-fpm的錯誤日志吧

[root@test-centos7-node3 log]# cd /var/log/php-fpm/
[root@test-centos7-node3 php-fpm]# ls
error.log  www-error.log
[root@test-centos7-node3 php-fpm]# tail www-error.log 
[14-Feb-2020 16:00:06 UTC] PHP Notice:  Undefined index: ViewStringCharacterLimit in /var/www/html/log/install.php on line 800
[14-Feb-2020 16:00:06 UTC] PHP Notice:  Undefined index: ViewEntriesPerPage in /var/www/html/log/install.php on line 801
[14-Feb-2020 16:00:06 UTC] PHP Notice:  Undefined index: ViewEnableDetailPopups in /var/www/html/log/install.php on line 802
[14-Feb-2020 16:00:06 UTC] PHP Notice:  Undefined index: EnableIPAddressResolve in /var/www/html/log/install.php on line 803
[14-Feb-2020 16:00:06 UTC] PHP Notice:  Undefined index: UserDBEnabled in /var/www/html/log/install.php on line 904
[14-Feb-2020 16:00:06 UTC] PHP Warning:  Unknown: open(/var/lib/php/session/sess_b7f7ckbngimv44nhs20dpl7807, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
[14-Feb-2020 16:00:06 UTC] PHP Warning:  Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0
[14-Feb-2020 16:00:48 UTC] PHP Parse error:  syntax error, unexpected ';' in /var/www/html/log/config.php on line 86
[14-Feb-2020 16:00:48 UTC] PHP Warning:  Unknown: open(/var/lib/php/session/sess_b7f7ckbngimv44nhs20dpl7807, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
[14-Feb-2020 16:00:48 UTC] PHP Warning:  Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0
[root@test-centos7-node3 php-fpm]# 
      

  說明:php-fpm錯誤日志提示我們說/var/www/html/log/config.php的第86行文法錯誤

Linux系統之LAMP實作

    提示:前三個值是我們設定安裝loganalyzer的第三步,它這裡沒有寫進來,我們需要手動填一下即可

Linux系統之LAMP實作

   提示:修改好後,我們在用浏覽器通路下192.168.0.10/log看看問題解決沒有

Linux系統之LAMP實作

   提示:還是告訴我們錯誤500,我們再來看看php-fpm的錯誤日志,看看它提示我們那裡錯了

Linux系統之LAMP實作

   提示:它又告訴我們99行有錯誤,我們去看看呢

Linux系統之LAMP實作

   提示:這個錯誤和上面一樣,沒有給值,我們可以從後面的解釋看看,這個表示什麼;它說如果啟用,将自動解析IP位址内聯消息,并将結果添加到IP後面的括号{}中;那說明這選項要麼啟動,要麼關閉,那我們就填一個1啟用嘛

Linux系統之LAMP實作

   提示:我們改完配置檔案後,儲存在用浏覽器通路192.168.0.10/log看看現在是否可以通路了

Linux系統之LAMP實作

   提示:可以看到是可以通路了,我們看到我們通路httpd的日志都有記錄,并顯示在我們搭建的loganalyzer上面

  我們點選statistics可能沒有圖示展示,這是因為我們的伺服器上沒有安裝php-gd這個包,安裝好了,重新開機php-fpm後,在重新整理就有了

Linux系統之LAMP實作
[root@test-centos7-node3 log]# yum install php-gd -y
[root@test-centos7-node3 log]# systemctl restart php-fpm      
Linux系統之LAMP實作

  提示:我們才搭建好資料量很少,是以看到畫的圖也不是很好。我們可以把其他主機的日志也接入到資料庫中,當資料量比較大時,我們看統計圖就可以看到那個主機的日志占比等等資訊。如下

Linux系統之LAMP實作

    到此我們就把httpd的通路日志用rsyslog給收集到資料庫中,然後通過loganalyzer 給圖形化展示出來了。 

作者:Linux-1874

出處:https://www.cnblogs.com/qiuhom-1874/

本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接,否則保留追究法律責任的權利.

繼續閱讀