1懦底、部署分離的LAMP,部署到二臺(tái)服務(wù)器上笼裳,php加載xcache模塊
基礎(chǔ)知識(shí)
什么是LAMP守呜?
即linux操作系統(tǒng)下的apache(httpd)+MySQL或者mariadb并且可以運(yùn)行php眠寿,per,python等代碼躬翁,我們這里的LAMP指的是linux+apache(httpd)+(Mysql)Mariadb+php;
httpd與php的結(jié)合方式
一種方式是:php以模塊的形式集成在apache當(dāng)中,讓apache具有了處理php程序的能力盯拱;其只需要安裝php包即可盒发;
yum install httpd php-mysql php
#生產(chǎn)場(chǎng)景不常用,但是可以實(shí)現(xiàn)快速部署
一種方式是:php與apache直接以fastcgi協(xié)議進(jìn)行通信,apache狡逢,php宁舰,是二個(gè)不同的軟件來(lái)運(yùn)行,并監(jiān)聽(tīng)在不同的端口之上奢浑;其需要安裝php-fpm包蛮艰;這種結(jié)合方式其效率更高,也是生產(chǎn)場(chǎng)景中使用的結(jié)合方式雀彼;
實(shí)現(xiàn)LAMP的方式
快速部署:yum安裝的方式壤蚜,簡(jiǎn)單快速
編譯部署:運(yùn)行新的php程序代碼需要比較新的環(huán)境,就需要編譯部署
LAMP的分離方式
常用的分離方式:apache--->fascgi--->php做為一臺(tái)服務(wù)器徊哑,數(shù)據(jù)庫(kù)單獨(dú)一臺(tái)服務(wù)器部署
當(dāng)然也可以apache袜刷,php,數(shù)據(jù)庫(kù)都單獨(dú)一臺(tái)服務(wù)器部署莺丑,這里不常用
關(guān)于Xcache?
php的加速器:基于PHP的特殊擴(kuò)展機(jī)制如opcode緩存擴(kuò)展也可以將opcode緩存于php的共享內(nèi)存中著蟹,從而可以讓同一段代碼的后續(xù)重復(fù)執(zhí)行時(shí)跳過(guò)編譯階段以提高性能。這些加速器并非真正提高了opcode的運(yùn)行速度梢莽,而僅是通過(guò)分析opcode后并將它們重新排列以達(dá)到快速執(zhí)行的目的萧豆;
XCache就是其中一中php的緩存加速器,XCache快速而且穩(wěn)定的PHP opcode緩存昏名,經(jīng)過(guò)嚴(yán)格測(cè)試且被大量用于生產(chǎn)環(huán)境炕横。項(xiàng)目地址:http://xcache.lighttpd.net/,收錄EPEL源 ;其官網(wǎng)的XCache3.2只能支持php5.X葡粒,也沒(méi)有新的更新了份殿,而新的PHP7.X其本身自帶加速模塊,XCache3.2加速器已經(jīng)成為歷史膜钓。
所以下面的部署,以yum安裝方式來(lái)部署LAMP卿嘲,并且演示Xcache的加速效果颂斜;
部署過(guò)程
1. 主機(jī)規(guī)劃
主機(jī)IP | 主機(jī)用途 |
---|---|
192.168.37.7 | web服務(wù)器(apache-->fastcgi-->php) |
192.168.37.17 | 數(shù)據(jù)庫(kù)服務(wù)器(mariadb)主機(jī)規(guī)劃 |
2. web服務(wù)器的安裝配置過(guò)程
#yum安裝所需包組
#php-mysql也是模塊,用來(lái)連接數(shù)據(jù)庫(kù)
[root@37-7-test1 ~]# yum install httpd php-mysql php-fpm -y
Installing:
httpd x86_64 2.4.6-93.el7.centos base 2.7 M
php-fpm x86_64 5.4.16-48.el7 base 1.4 M
php-mysql x86_64 5.4.16-48.el7 base 102 k
Installing for dependencies:
httpd-tools x86_64 2.4.6-93.el7.centos base 92 k
libzip x86_64 0.10.1-8.el7 base 48 k
mailcap noarch 2.1.41-2.el7 base 31 k
php-common x86_64 5.4.16-48.el7 base 565 k
php-pdo x86_64 5.4.16-48.el7 base 99 k
Updating for dependencies:
openssl x86_64 1:1.0.2k-19.el7 base 493 k
openssl-libs x86_64 1:1.0.2k-19.el7 base 1.2 M
Installed:
httpd.x86_64 0:2.4.6-93.el7.centos php-fpm.x86_64 0:5.4.16-48.el7
php-mysql.x86_64 0:5.4.16-48.el7
Dependency Installed:
httpd-tools.x86_64 0:2.4.6-93.el7.centos libzip.x86_64 0:0.10.1-8.el7
mailcap.noarch 0:2.1.41-2.el7 php-common.x86_64 0:5.4.16-48.el7
php-pdo.x86_64 0:5.4.16-48.el7
Dependency Updated:
openssl.x86_64 1:1.0.2k-19.el7 openssl-libs.x86_64 1:1.0.2k-19.el7
Complete!
-----------------------------------------------------
-----------------------------------------------------
#配置httpd的配置文件遇到php結(jié)尾的文件拾枣,交由php處理
#這種httpd和php-fpm在同一臺(tái)機(jī)器上沃疮,也可以使用套接字文件進(jìn)行通信,就不會(huì)開(kāi)啟9000端口
#如果將httpd和php-fpm分別部署在不同機(jī)器上梅肤,就只能基于這種套接字的通信方式
#通信方式1和通信方式2可以任選一個(gè)司蔬,這里選通信方式2,因?yàn)槠涠荚谝慌_(tái)服務(wù)器上
#此種方式效率高
-----------------------------------------------------
#通信方式1 socket的配置
[root@37-7-test1 ~]# vim /etc/httpd/conf.d/fcgi.conf
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1
------------------------------------------------------------------
#通信方式2 UDS方式即套接字文件
#通信雙方在本地打開(kāi)一個(gè)文件姨蝴,進(jìn)行通信
vim /etc/httpd/conf.d/uds.conf
ProxyRequests off
ProxyPassMatch "^/(.*\.php)$" "unix:/var/run/php.sock|fcgi://localhost/var/www/html/$1"
#還需修改監(jiān)聽(tīng)端口變成監(jiān)聽(tīng)文件
[root@37-7-test1 conf.d]# vim /etc/php-fpm.d/www.conf
; Start a new pool named 'www'.
[www]
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses on a
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
;listen = 127.0.0.1:9000
#主要修改此將監(jiān)聽(tīng)在端口上改成一個(gè)文件
listen = /var/run/php.sock
-----------------------------------------------------
-----------------------------------------------------
#創(chuàng)建一個(gè)php測(cè)試網(wǎng)頁(yè)調(diào)用phpinfo()
[root@37-7-test1 ~]# cd /var/www/html/
[root@37-7-test1 html]# ls
[root@37-7-test1 html]# vim index.php
<?php
phpinfo()
?>
#開(kāi)啟httpd服務(wù)俊啼,和php-fpm服務(wù)
[root@37-7-test1 html]# systemctl start httpd
[root@37-7-test1 html]# systemctl start php-fpm
[root@37-7-test1 html]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:51966 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::34352 :::*
LISTEN 0 128 :::22 :::*
[root@37-7-test1 html]#
#測(cè)試php程序是否可以運(yùn)行
如上頁(yè)面打開(kāi)就說(shuō)明httpd與php的結(jié)合方式已經(jīng)可以了;下面部署數(shù)據(jù)庫(kù)服務(wù)器
3. 數(shù)據(jù)庫(kù)服務(wù)器的安裝與配置
[root@37-17-test2 ~]# yum install mariadb-server -y
Loaded plugins: fastestmirror, langpacks
base ..... Installed:
mariadb-server.x86_64 1:5.5.65-1.el7
Dependency Installed:
mariadb.x86_64 1:5.5.65-1.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-6.el7
perl-DBI.x86_64 0:1.627-4.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
Dependency Updated:
mariadb-libs.x86_64 1:5.5.65-1.el7
Complete!
#啟動(dòng)數(shù)據(jù)庫(kù)并創(chuàng)建測(cè)試數(shù)據(jù)庫(kù)
[root@37-17-test2 ~]# systemctl start mariadb
[root@37-17-test2 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
#創(chuàng)建測(cè)試數(shù)據(jù)庫(kù)
MariaDB [(none)]> create database testdb;
Query OK, 1 row affected (0.00 sec)
#授權(quán)用戶方便測(cè)試
MariaDB [(none)]> grant all privileges on testdb.* to testuser@'192.168.37.%' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)
在web服務(wù)器上編寫php測(cè)試代碼左医,連接192.168.37.17數(shù)據(jù)庫(kù)服務(wù)器授帕,查看所有環(huán)境是否準(zhǔn)備好;
[root@37-7-test1 html]# vim test.php
<?php
$mysqli=new mysqli("192.168.37.17", "testuser", "centos");
if(mysqli_connect_errno()){
echo "Failure";
$mysqli=null;
exit;
} echo "OK";
$mysqli->close();
?>
#測(cè)試瀏覽器顯示OK即可
4. 部署wordpress個(gè)人博客來(lái)測(cè)試php的性能
1. 數(shù)據(jù)庫(kù)創(chuàng)建
#創(chuàng)建wpdb數(shù)據(jù)庫(kù)浮梢,并授權(quán)用戶跛十,以便安裝wordpress
MariaDB [(none)]> create database wpdb;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> use wpdb;
Database changed
MariaDB [wpdb]> grant all on wpdb.* to wpuser@'192.168.37.%' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)
MariaDB [wpdb]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#測(cè)試與數(shù)據(jù)庫(kù)的連接
[root@master-mariadb html]# mysql -uwpuser -pcentos -h192.168.37.17
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, 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 |
| test |
| wpdb |
+--------------------+
3 rows in set (0.00 sec)
2. 安裝wordpress
[root@37-7-test1 data]# rz
rz waiting to receive.
zmodem trl+C ?
100% 10838 KB 10838 KB/s 00:00:01 0 Errorsar.gz...
[root@37-7-test1 data]# ls
#以5.0.3wordpress為例
wordpress-5.0.3-zh_CN.tar.gz xcache-3.2.0 xcache-3.2.0.tar.gz
#直接解壓至站點(diǎn)wordpress子目錄,yum安裝默認(rèn)站點(diǎn)目錄是/var/www/html/可以在配置文件中修改
#centos7修改站點(diǎn)目錄秕硝,還需要配合授權(quán)語(yǔ)句授權(quán)目錄權(quán)限
[root@37-7-test1 data]# tar xvf wordpress-5.0.3-zh_CN.tar.gz -C /var/www/html/
wordpress/
wordpress/wp-login.php
wordpress/wp-cron.php
wordpress/xmlrpc.php
wordpress/wp-load.php
wordpress/wp-admin/
wordpress/wp-admin/credits.php
wordpress/wp-admin/admin-functions.php
wordpress/wp-admin/options-reading.php
wordpress/wp-admin/edit-tags.php
wordpress/wp-admin/link-manager.php
wordpress/wp-admin/options-writing.php
wordpress/wp-admin/network.php
#修改wordpress的配置文件芥映,這里可以直接修改配置文件,也可以根據(jù)網(wǎng)頁(yè)提示信息一步一步安裝
[root@37-7-test1 wordpress]# cp wp-config-sample.php wp-config.php
[root@37-7-test1 wordpress]# vim wp-config.php
// ** MySQL 設(shè)置 - 具體信息來(lái)自您正在使用的主機(jī) ** //
/** WordPress數(shù)據(jù)庫(kù)的名稱 */
define('DB_NAME', 'wpdb');
/** MySQL數(shù)據(jù)庫(kù)用戶名 */
define('DB_USER', 'wpuser');
/** MySQL數(shù)據(jù)庫(kù)密碼 */
define('DB_PASSWORD', 'centos');
/** MySQL主機(jī) */
define('DB_HOST', '192.168.37.17');
3. 網(wǎng)頁(yè)初始化
配置好以后远豺,打開(kāi)瀏覽器輸入http://192.168.37.7/wordpress,進(jìn)行初始化即可屏轰,即填寫一個(gè)信息,并自動(dòng)生成數(shù)據(jù)庫(kù)當(dāng)中的表等內(nèi)容憋飞;
一個(gè)個(gè)人博客網(wǎng)站就搭建好了霎苗,有了它,我們來(lái)測(cè)試緩存加速器的作用榛做,使用ab工具來(lái)測(cè)試當(dāng)前網(wǎng)站的效率唁盏。
[root@37-27-test3 ~]# ab -c10 -n 100
Requests per second: 5.24 [#/sec] (mean)
#每秒鐘響應(yīng)5次請(qǐng)求
#可以多測(cè)幾次取平均值
Requests per second: 5.21 [#/sec] (mean)
Requests per second: 5.23 [#/sec] (mean)
5. 源碼安裝php-xcache
[root@37-27-test3 ~]# rpm -qi php
Name : php
Version : 5.4.16
#xcache可以對(duì)php5.X進(jìn)行加速,不支持更高版本
[root@37-7-test1 html]# rz
rz waiting to receive.
zmodem trl+C ?
100% 169 KB 169 KB/s 00:00:01 0 Errors
[root@37-7-test1 data]# ls
#官網(wǎng)已經(jīng)不存在了检眯,可以去github下載
xcache-3.2.0.tar.gz
[root@37-7-test1 data]# tar xvf xcache-3.2.0.tar.gz
#解壓
xcache-3.2.0/
xcache-3.2.0/AUTHORS
xcache-3.2.0/bin/
xcache-3.2.0/bin/phpdc.phpr
#使用phpize生成configure厘擂,需要安裝php-devel包
[root@37-7-test1 xcache-3.2.0]# yum install php-devel -y
....
Complete!
[root@37-7-test1 xcache-3.2.0]# phpize --clean && phpize
Cleaning..
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
#開(kāi)啟xcache
[root@37-7-test1 xcache-3.2.0]# ./configure --enable-xcache
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
[root@37-7-test1 xcache-3.2.0]# make && make install
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/lib64/php/modules/
#拷貝配置文件xcache.ini到php-fpm的啟動(dòng)配置端,從其php-fpm
[root@37-7-test1 xcache-3.2.0]# cp xcache.ini /etc/php.d/
[root@37-7-test1 xcache-3.2.0]# cd /etc/php.d/
[root@37-7-test1 php.d]# systemctl restart php-fpm
#測(cè)試速度
[root@37-27-test3 data]# ab -c10 -n 100
Requests per second: 12.74 [#/sec] (mean)
#每秒12個(gè)處理請(qǐng)求明顯提升
#如何關(guān)閉加速
#在/etc/php.d/xcache.ini里注釋掉;extension = xcache.so然后重啟服務(wù)
2锰瘸、部署論壇刽严,并實(shí)現(xiàn)正常訪問(wèn)登錄論壇。
論壇比較著名的php源碼程序避凝,就是discuz舞萄,可以去官網(wǎng)下載所需版本眨补;
1. 192.168.37.7的準(zhǔn)備
#下載utf8版本,上傳至服務(wù)器倒脓,并解壓撑螺,拷貝至站點(diǎn)相對(duì)應(yīng)子目錄
[root@37-7-test1 html]# rz
rz waiting to receive.
zmodem trl+C ?
100% 10666 KB 10666 KB/s 00:00:01 0 Errors...
[root@37-7-test1 html]# unzip Discuz_X3.3_SC_UTF8.zip -d discuz
Archive: Discuz_X3.3_SC_UTF8.zip
creating: discuz/readme/
inflating: discuz/readme/changelog.txt
inflating: discuz/readme/convert.txt
inflating: discuz/readme/license.txt
inflating: discuz/readme/readme.txt
[root@37-7-test1 html]# ls
discuz Discuz_X3.3_SC_UTF8.zip index.php test.php wordpress
[root@37-7-test1 html]# cd discuz/
[root@37-7-test1 discuz]# mv upload/ /var/www/html/forum
[root@37-7-test1 discuz]# ls /var/www/html/forum/
admin.php config data home.php misc.php search.php uc_client
api connect.php favicon.ico index.php plugin.php source uc_server
api.php cp.php forum.php install portal.php static userapp.php
archiver crossdomain.xml group.php member.php robots.txt template
[root@37-7-test1 discuz]# cd ..
[root@37-7-test1 html]# setfacl -Rm u:apache:rwx forum/
2. 192.168.37.27的準(zhǔn)備
#192.168.37.17創(chuàng)建所需數(shù)據(jù)庫(kù),授權(quán)用戶
[root@37-17-test2 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2184
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database forumdb;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on forumdb.* to forum@'192.168.37.%' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)
3. 初始化網(wǎng)頁(yè)的過(guò)程
瀏覽器地址欄輸入192.168.37.7/forum/進(jìn)入安裝向?qū)?/p>
到此一個(gè)論壇就搭建成功了
3崎弃、收集apache訪問(wèn)日志甘晤,并實(shí)現(xiàn)圖形化展示。
想要圖形化展示apache的訪問(wèn)日志饲做,可以通過(guò)loganalyzer來(lái)實(shí)現(xiàn)线婚,loganalyzer依賴LAMP,圖形化展示apache的訪問(wèn)日志的方法有二種:
- 直接讓訪問(wèn)日志交給loganalyzer并圖形化展示
- 將pache訪問(wèn)日志統(tǒng)一管理到一臺(tái)日志服務(wù)器上盆均,然后讓loganalyzer去日志服務(wù)器取相關(guān)數(shù)據(jù)塞弊,出圖
1. 直接讓訪問(wèn)日志交給loganalyzer并圖形化展示
A. 部署loganalyzer
#192.168.37.7下載loganlzer解壓到/var/www/html/目錄
#這里不需要連接數(shù)據(jù)庫(kù)直接,所以安裝包有httpd php或httpd php-fpm
#這里以httpd模塊的方式演示
[root@37-7-test1 ~]# yum install httpd php
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/5): epel/x86_64/group_gz | 95 kB 00:00:00
(2/5): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(3/5): epel/x86_64/primary_db
[root@37-7-test1 html]# rz
rz waiting to receive.
zmodem trl+C ?
100% 1022 KB 255 KB/s 00:00:04 0 Errorsgz...
[root@37-7-test1 html]# ls
discuz forum loganalyzer-3.6.4.tar.gz wordpress
Discuz_X3.3_SC_UTF8.zip index.php test.php
[root@37-7-test1 html]# tar xvf loganalyzer-3.6.4.tar.gz -C /var/www/html/
loganalyzer-3.6.4/
loganalyzer-3.6.4/ChangeLog
loganalyzer-3.6.4/INSTALL
loganalyzer-3.6.4/doc/
loganalyzer-3.6.4/doc/free_support.html
loganalyzer-3.6.4/doc/manual.html
loganalyzer-3.6.4/doc/professional_services.html
[root@37-7-test1 html]# cd loganalyzer-3.6.4/
[root@37-7-test1 loganalyzer-3.6.4]# ls
ChangeLog contrib COPYING doc INSTALL src
[root@37-7-test1 loganalyzer-3.6.4]# mv src/ ../logs
[root@37-7-test1 loganalyzer-3.6.4]# cd ..
[root@37-7-test1 html]# ls
discuz forum loganalyzer-3.6.4 logs wordpress
Discuz_X3.3_SC_UTF8.zip index.php loganalyzer-3.6.4.tar.gz test.php
[root@37-7-test1 html]# systemctl restart httpd
B. 網(wǎng)頁(yè)初始化安裝
#可以執(zhí)行其contrib/configure.sh腳本,也可以自己執(zhí)行
[root@37-7-test1 html]# cd logs/
[root@37-7-test1 logs]# touch config.php
[root@37-7-test1 logs]# chmod 666 config.php
[root@37-7-test1 logs]# setfacl -R -m u:apache:rwx /var/log/httpd/
圖形化展示
2.將apache訪問(wèn)日志保存至一臺(tái)日志服務(wù)器上缀踪,然后讓loganalyzer去日志服務(wù)器取相關(guān)數(shù)據(jù),出圖
主機(jī)規(guī)劃:
主機(jī)用途 | IP |
---|---|
apache服務(wù)器 | 192.168.37.7 |
mariadb數(shù)據(jù)庫(kù)服務(wù)器/日志服務(wù)器 | 192.168.37.17 |
loganalyzer服務(wù)器 | 192.168.37.27 |
說(shuō)明:
這里的apache服務(wù)器生成的日志由rsyslog轉(zhuǎn)發(fā)到mariadb數(shù)據(jù)庫(kù)服務(wù)器虹脯,也可以稱為專門的日志服務(wù)器驴娃;
loganalyzer需要lamp環(huán)境,然后連接數(shù)據(jù)庫(kù)服務(wù)器出圖循集;
1. apache服務(wù)器快速部署
#192.168.37.7安裝這里以fastcgi的方式運(yùn)行php
[root@37-7-test1 ~]# yum install httpd php-fpm php-mysql
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates
#配置fcgi.conf
[root@37-7-test1 conf.d]# pwd
/etc/httpd/conf.d
[root@37-7-test1 conf.d]# vim fcgi.conf
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1
#啟動(dòng)服務(wù)httpd和php-fpm
systemctl start httpd
systemctl start php-fpm
#編寫測(cè)試代碼
[root@37-7-test1 conf.d]# cd /var/www/html/
[root@37-7-test1 html]# ls
index.php
[root@37-7-test1 html]# vim index.php
<?php
phpinfo()
?>
進(jìn)入瀏覽器查看效果
2. 數(shù)據(jù)庫(kù)服務(wù)器連接配置
#apache服務(wù)器上安裝rsyslog-mysql模塊唇敞,可以連接數(shù)據(jù)庫(kù)
[root@37-7-test1 html]# yum install rsyslog-mysql
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Loading mirror speeds from cached hostfile
#上傳mysql-createDB.sql給192.168.37.17生成所需數(shù)據(jù)庫(kù)
[root@37-7-test1 html]# rpm -ql rsyslog-mysql
/usr/lib64/rsyslog/ommysql.so
/usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
You have new mail in /var/spool/mail/root
[root@37-7-test1 html]# scp /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql 192.168.37.17:/data
The authenticity of host '192.168.37.17 (192.168.37.17)' can't be established.
ECDSA key fingerprint is 82:01:ab:34:04:e9:98:28:c2:10:0b:79:9a:60:19:06.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.37.17' (ECDSA) to the list of known hosts.
root@192.168.37.17's password:
mysql-createDB.sql 100% 1046 1.0KB/s 00:00
[root@37-7-test1 html]#
#數(shù)據(jù)庫(kù)服務(wù)器安裝,啟動(dòng)咒彤,導(dǎo)入數(shù)據(jù)
[root@37-17-test2 ~]# yum install mariadb-server -y
[root@37-17-test2 ~]# systemctl start mariadb
[root@37-17-test2 ~]# mysql < /data/mysql-createDB.sql
#授權(quán)用戶權(quán)限
[root@37-17-test2 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
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]> grant all on Syslog.* to 'loguser'@'192.168.37.%' identified by 'centos';
Query OK, 0 rows affected (0.01 sec)
3. apache服務(wù)器配置日志服務(wù)將日志發(fā)送至數(shù)據(jù)庫(kù)服務(wù)器
#1. 訪問(wèn)日志改這里就可以了
[root@37-7-test1 html]# vim /etc/httpd/conf/httpd.conf
#access_log由管道交給syslog疆柔,facility為自定義的local4
CustomLog "|/usr/bin/logger -p local4.info" combined
#2. 配置rsyslog
[root@37-7-test1 html]# vim /etc/rsyslog.co
#啟用數(shù)據(jù)庫(kù)模塊,將local4所有內(nèi)容 記錄到遠(yuǎn)程數(shù)據(jù)庫(kù)服務(wù)器上
#打開(kāi)udp514端口
$ModLoad imudp
$UDPServerRun 514
$ModLoad ommysql
local4.* :ommysql:192.168.37.17,Syslog,loguser,centos
#重啟httpd服務(wù)和rsyslog服務(wù)镶柱,嘗試瀏覽器訪問(wèn)旷档,檢查數(shù)據(jù)庫(kù)中是否由日志產(chǎn)生
[root@37-7-test1 html]# systemctl restart rsyslog
[root@37-7-test1 html]# systemctl restart httpd
#192.168.37.17開(kāi)始沒(méi)有數(shù)據(jù),訪問(wèn)過(guò)后日志數(shù)據(jù)來(lái)了
MariaDB [Syslog]> select * from SystemEvents\G
Empty set (0.00 sec)
MariaDB [Syslog]> select * from SystemEvents\G
*************************** 1. row ***************************
ID: 1
CustomerID: NULL
ReceivedAt: 2020-09-04 12:00:26
DeviceReportedTime: 2020-09-04 12:00:26
Facility: 20
Priority: 6
FromHost: [localhost]
Message: 192.168.37.1 - - [04/Sep/2020:12:00:26 +0800] "GET / HTTP/1.1" 200 45485 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0"
NTSeverity: NULL
Importance: NULL
EventSource: NULL
EventUser: NULL
EventCategory: NULL
EventID: NULL
EventBinaryData: NULL
MaxAvailable: NULL
CurrUsage: NULL
MinUsage: NULL
MaxUsage: NULL
InfoUnitID: 1
SysLogTag: logger:
EventLogType: NULL
GenericFileName: NULL
SystemID: NULL
......
4. loganalyzer服務(wù)器的安裝配置
#首先快速部署lamp httpd
[root@37-27-test3 ~]# yum install httpd php php-mysql php-gd -y
#部署loganalyzer
[root@37-27-test3 ~]# rz
rz waiting to receive.
zmodem trl+C ?
100% 2802 KB 2802 KB/s 00:00:01 0 Errorsgz...
[root@37-27-test3 ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg loganalyzer-4.1.7.tar.gz
[root@37-27-test3 ~]# tar xvf loganalyzer-4.1.7.tar.gz -C /var/www/html
[root@37-27-test3 ~]# cd /var/www/html/
[root@37-27-test3 html]# cd loganalyzer-4.1.7/
[root@37-27-test3 loganalyzer-4.1.7]# ls
ChangeLog contrib COPYING doc INSTALL src
[root@37-27-test3 loganalyzer-4.1.7]# mv src/ ../logs
[root@37-27-test3 loganalyzer-4.1.7]# cd ..
[root@37-27-test3 html]# cd logs/
[root@37-27-test3 logs]# ls
admin convert.php favicon.ico js search.php
asktheoracle.php cron images lang statistics.php
BitstreamVeraFonts css include login.php templates
chartgenerator.php details.php index.php reportgenerator.php themes
classes export.php install.php reports.php userchange.php
[root@37-27-test3 logs]# touch config.php
[root@37-27-test3 logs]# chmod 666 config.php
#啟動(dòng)httpd服務(wù)即可
loganalyzer初始化過(guò)程
日志圖形展示
錯(cuò)誤匯總
#1. logAnalyzer報(bào)錯(cuò)如下
Could not find the configured table, maybe misspelled or the tablenames are case sensitive
#提示找不到表歇拆,修改鞋屈,解決方法修改配置tablename的名字一定要對(duì)應(yīng)正確的數(shù)據(jù)庫(kù)里的表名,區(qū)分大小寫
[root@37-27-test3 logs]# vim config.php
#將小寫的sysemevents改成SystemEvents后重啟服務(wù)
$CFG['Sources']['Source1']['DBTableName'] = 'SystemEvents';
[root@37-27-test3 logs]# systemctl restart httpd
#2. 不出圖
#安裝php-gd
yum install php-gd -y