LAMP的實(shí)戰(zhàn)應(yīng)用

1、部署分離的LAMP,部署到二臺(tái)服務(wù)器上,php加載xcache模塊

10.0.0.7  web
10.0.0.17 db

1.1 WEB端安裝httpd

[root@web ~]# yum -y install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
[root@web ~]# yum -y install php56-php php56-php-mysqlnd
[root@web ~]# systemctl enable --now httpd

1.2 DB端安裝數(shù)據(jù)庫(kù)并創(chuàng)建書(shū)庫(kù)和用戶(hù)

[root@db ~]# yum -y install mariadb-server
[root@db ~]# systemctl enable --now mariadb
[root@db ~]# mysql
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

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

1.3 WEB端部署wordpress并測(cè)試

[root@web ~]# wget https://cn.wordpress.org/latest-zh_CN.zip
[root@web ~]# unzip latest-zh_CN.zip^C
[root@web ~]# mv wordpress/ /var/www/html/
[root@web ~]# cd /var/www/html/
[root@web html]# chown -R apache.apache wordpress/
#通過(guò)別的主機(jī)進(jìn)行測(cè)試
[root@db ~]# ab -c 10 -n 100 http://10.0.0.7/wordpress/
...
Requests per second:    4.35 [#/sec] (mean)
...

1.4 編譯安裝xcache 并行速度測(cè)試

#安裝編譯xcache
[root@web ~]# yum -y install gcc php56-php-devel
#下載并解壓縮xcache-3.2.0.tar.bz2
[root@web ~]# tar zxf xcache-3.2.0.tar.gz 
[root@web ~]# cd xcache-3.2.0/

[root@web xcache-3.2.0]# /opt/remi/php56/root/usr/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226

[root@web xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/opt/remi/php56/root/usr/bin/php-config

[root@web xcache-3.2.0]# make && make install
....
Installing shared extensions:     /opt/remi/php56/root/usr/lib64/php/modules/
#通過(guò)訪問(wèn)測(cè)試
[root@db ~]# ab -c 10 -n 100 http://10.0.0.7/wordpress/
...
Requests per second:    14.74 [#/sec] (mean)
...

2、部署wordpress論壇,并實(shí)現(xiàn)正常訪問(wèn)登錄論壇。

[root@localhost ~]# yum -y install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
[root@localhost ~]# sed -i 's#enabled=0#enabled=1#g'  /etc/yum.repos.d/remi-php74.repo
[root@localhost ~]# yum -y install php56-php php56-php-mysqlnd mariadb-server
[root@localhost ~]# systemctl enable --now httpd mariadb
[root@localhost ~]# mysql
MariaDB [(none)]> create database wordpress;
MariaDB [(none)]> grant all on wordpress.* to wordpress@'localhost' identified by 'jhd2021@';

[root@localhost ~]# wget https://cn.wordpress.org/latest-zh_CN.zip\
[root@localhost ~]# unzip latest-zh_CN.zip 
[root@localhost ~]# mv wordpress/ /var/www/html/
[root@localhost ~]# chown -R apache.apache /var/www/html/

#瀏覽器訪問(wèn)
#http://10.0.0.7/wordpress

#安全加固
#用瀏覽器訪問(wèn)https://api.wordpress.org/secret-key/1.1/salt/,替代下面wp-config.php內(nèi)容
[root@centos8 ~]#vim /var/www/html/wp-config.php

3、收集apache訪問(wèn)日志,并實(shí)現(xiàn)圖形化展示。

3.1 修改Apache和rsyslog配置文件

#修改apache配置文件
[root@web ~]# vim /etc/httpd/conf/httpd.conf
....
CustomLog "logs/access_log" combined
CustomLog "/usr/bin/logger -p local6.info" combined

#修改rsyslog的配置文件
[root@web ~]# vim /etc/rsyslog.conf 
local6.*                           /var/log/apache_access_log

#重啟rsyslog和apache服務(wù)
[root@web ~]# systemctl restart rsyslog.service httpd.service 

3.2 在mysql server上授權(quán)rsyslog能連接至數(shù)據(jù)庫(kù)服務(wù)器

#在mysql server上授權(quán)rsyslog能連接至數(shù)據(jù)庫(kù)服務(wù)器
[root@db ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.68-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)]> grant all on Syslog.* to 'apache'@'%' identified by 'jhd2021@';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;

3.3 配置rsyslog

# 在rsyslog服務(wù)器上安裝mysql模塊相關(guān)的程序包
[root@web ~]# yum -y install rsyslog-mysql.x86_64 

# 為rsyslog創(chuàng)建數(shù)據(jù)庫(kù)及表
[root@web ~]# mysql -uapache -pjhd2021@ -h10.0.0.17 < /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
[root@web ~]# mysql -uapache -pjhd2021@ -h10.0.0.17 -e "show databases;"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| Syslog             |
| test               |
+--------------------+

#配置rsyslog將日志保存到mysql中
[root@web ~]# vim /etc/rsyslog.conf 
local6.* :ommysql:10.0.0.17,Syslog,apache,jhd2021@

#重啟rsyslogd服務(wù)
[root@web ~]# systemctl restart rsyslog.service

#在rsyslog服務(wù)器上安裝繪圖工具php-gd
[root@web ~]# yum -y  install php-gd 

#下載
[root@web ~]# wget -c https://download.adiscon.com/loganalyzer/loganalyzer-4.1.11.tar.gz
[root@web ~]# tar zxf loganalyzer-4.1.11.tar.gz 
[root@web ~]# mv loganalyzer-4.1.11 /var/www/html/
[root@web html]# mv loganalyzer-4.1.11 loganalyzer
[root@web html]# cd loganalyzer/
[root@web loganalyzer]# touch config.php
[root@web loganalyzer]# chmod 666 config.php
[root@web html]# setfacl -Rm u:apache:rwx loganalyzer
[root@web html]# systemctl restart httpd.service 

在瀏覽器輸入 http://10.0.0.7/loganalyzer/
1.png
2.png
3.png
4.png
5.png
6.png
7.png
8.png
9.png
10.png
11.png

3.4 安全加固

#安全加固
[root@web ~]# cd /var/www/html/loganalyzer
[root@web ~]# chmod 644 config.php
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1、部署分離的LAMP,部署到二臺(tái)服務(wù)器上,php加載xcache模塊 基礎(chǔ)知識(shí) 什么是LAMP? 即linux操...
    路口的閱讀 503評(píng)論 0 0
  • 部署分離的LAMP,部署到二臺(tái)服務(wù)器上,php加載xcache模塊 實(shí)驗(yàn)環(huán)境: 主機(jī)os軟件iphttp+php服...
    jamas閱讀 252評(píng)論 0 0
  • 一、部署分離的LAMP,部署到二臺(tái)服務(wù)器上,php加載xcache模塊 主機(jī):兩臺(tái)CentOS7系統(tǒng)主機(jī),一臺(tái)實(shí)現(xiàn)...
    毅_閱讀 409評(píng)論 0 0
  • 1.LAMP介紹 ? LAM(M)P:L: linuxA: apache (httpd)M: mysql, mar...
    尛尛大尹閱讀 1,240評(píng)論 0 1
  • 1、講述httpd工作原理以rpm包的方式安裝LAMP,配置基于域名的虛擬機(jī)主機(jī)并部署PhpMyAdmin、Wor...
    stephe_c閱讀 706評(píng)論 0 1

友情鏈接更多精彩內(nèi)容