综合练习---第十八周
作者:互联网
1、部署分离的LAMP,部署到二台服务器上,php加载xcache模块
环境搭建:
- apache服务器:httpd-2.4.46
- mysql服务器:mysql-5.7.31
- PHP服务器:php-7.3.26
搭建次序:httpd- - - >php 配置在一个服务器;mysql单独一个服务器
编译安装httpd
所需包文件:httpd-2.4.46.tar.gz、apr-1.7.0.tar.gz、apr-util-1.6.1.tar.gz
#安装相关包
[root@apache-php ~]#hostname apache-php
[root@apache-php src]#ll /usr/local/src
total 10760
-rw-r--r--. 1 root root 1093896 Jan 22 09:10 apr-1.7.0.tar.gz
-rw-r--r--. 1 root root 554301 Jan 22 09:09 apr-util-1.6.1.tar.gz
-rw-r--r--. 1 root root 9363314 Jan 21 16:49 httpd-2.4.46.tar.gz
[root@apache-php src]#yum install gcc pcre-devel openssl-devel expat-devel make -y
#编译安装httpd
[root@apache-php src]#tar xvf apr-1.7.0.tar.gz
[root@apache-php src]#tar xf apr-util-1.6.1.tar.gz
[root@apache-php src]#tar xf httpd-2.4.46.tar.gz
[root@apache-php src]#mv apr-1.7.0 httpd-2.4.46/srclib/apr
#将apr 和apr-util源码与httpd 源码合并,一起编译安装
[root@apache-php src]#mv apr-util-1.6.1 httpd-2.4.46/srclib/apr-util
[root@apache-php src]#mv apr-util-1.6.1 httpd-2.4.46/srclib/apr-util
[root@apache-php httpd-2.4.46]#./configure \
--prefix=/apps/httpd24 \
--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
[root@apache-php httpd-2.4.46]#make && make install
#准备PATH变量
[root@apache-php httpd-2.4.46]#echo 'PATH=/apps/httpd24/bin:$PATH' > /etc/profile.d/lamp.sh
[root@apache-php httpd-2.4.46]# . /etc/profile.d/lamp.sh
#创建和配置用户和组
[root@apache-php httpd-2.4.46]#useradd -s /sbin/nologin -r -u 88 apache
[root@apache-php httpd-2.4.46]#vim /apps/httpd24/conf/httpd.conf
User apache
Group apache
#编写服务器脚本
[root@apache-php httpd-2.4.46]#vim /usr/lib/systemd/system/httpd.servicevim /usr/lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=forking
#EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/apps/httpd24/bin/apachectl start
#ExecStart=/apps/httpd24/bin/httpd $OPTIONS -k start
ExecReload=/apps/httpd24/bin/apachectl graceful
#ExecReload=/apps/httpd24/bin/httpd $OPTIONS -k graceful
ExecStop=/apps/httpd24/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#重新加载服务配置,并启动
[root@apache-php httpd-2.4.46]#systemctl daemon-reload
[root@apache-php httpd-2.4.46]#systemctl enable --now httpd
[root@apache-php httpd-2.4.46]#systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sun 2021-02-21 11:22:49 CST; 10s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 38647 ExecStart=/apps/httpd24/bin/apachectl start (code=exited, status=203/EXEC)
Feb 21 11:22:49 apache-php systemd[1]: Starting The Apache HTTP Server...
Feb 21 11:22:49 apache-php systemd[1]: httpd.service: Control process exited, code=exited status=203
Feb 21 11:22:49 apache-php systemd[1]: httpd.service: Failed with result 'exit-code'.
Feb 21 11:22:49 apache-php systemd[1]: Failed to start The Apache HTTP Server.
[root@apache-php httpd-2.4.46]#systemctl stop firewalld
[root@apache-php httpd-2.4.46]#setenforce 0
[root@apache-php httpd-2.4.46]#systemctl enable --now httpd
[root@apache-php httpd-2.4.46]#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-02-21 11:23:51 CST; 11s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 38717 ExecStart=/apps/httpd24/bin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 38720 (httpd)
Tasks: 82 (limit: 5882)
Memory: 14.0M
CGroup: /system.slice/httpd.service
├─38720 /apps/httpd24/bin/httpd -k start
├─38721 /apps/httpd24/bin/httpd -k start
├─38722 /apps/httpd24/bin/httpd -k start
└─38723 /apps/httpd24/bin/httpd -k start
Feb 21 11:23:48 apache-php systemd[1]: Starting The Apache HTTP Server...
Feb 21 11:23:51 apache-php apachectl[38717]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fee0:bbba%eth0. Set the>
Feb 21 11:23:51 apache-php systemd[1]: Started The Apache HTTP Server.
编译安装php
所需包文件:php-7.3.26.tar.xz
#安装相关包
[root@apache-php src]#yum -y install gcc libxml2-devel bzip2-devel libmcrypt-devel
#编译安装php 7.3
[root@apache-php src]#tar xf php-7.3.26.tar.xz
[root@apache-php src]#cd php-7.3.26
[root@apache-php php-7.3.26]#./configure --prefix=/apps/php73 \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo
[root@apache-php php-7.3.26]#make && make install
#准备PATH变量
[root@apache-php php-7.3.26]#echo 'PATH=/apps/php73/bin:/apps/httpd24/bin:$PATH' > /etc/profile.d/lamp.sh
. /etc/profile.d/lamp.sh
#准备php配置文件和启动文件
[root@apache-php php-7.3.26]#cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
[root@apache-php php-7.3.26]#cd /apps/php73/etc/
[root@apache-php etc]#cp php-fpm.conf.default php-fpm.conf
[root@apache-php etc]#cp php-fpm.d/www.conf.default php-fpm.d/www.conf
#修改进程所有者
[root@apache-php etc]#vim /apps/php74/etc/php-fpm.d/www.conf
user apache
group apache
#启动服务
[root@apache-php php-7.3.26]#systemctl daemon-reload
[root@apache-php php-7.3.26]#systemctl enable --now php-fpm
编译安装xcache
[root@apache-php src]#tar xf xcache-3.2.0.tar.gz
[root@apache-php src]#cd xcache-3.2.0
[root@apache-php xcache-3.2.0]#vim INSTALL
[root@apache-php xcache-3.2.0]#phpize --clean && phpize
Cleaning..
Configuring for:
PHP Api Version: 20180731
Zend Module Api No: 20180731
Zend Extension Api No: 320180731
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
[root@apache-php xcache-3.2.0]#yum provides autoconf
Last metadata expiration check: 1:57:18 ago on Sun 21 Feb 2021 11:14:51 AM CST.
autoconf-2.69-27.el8.noarch : A GNU tool for automatically configuring source code
Repo : AppStream
Matched from:
Provide : autoconf = 2.69-27.el8
[root@apache-php xcache-3.2.0]#yum install autoconf -y
[root@apache-php xcache-3.2.0]#phpize --clean && phpize
Cleaning..
Configuring for:
PHP Api Version: 20180731
Zend Module Api No: 20180731
Zend Extension Api No: 320180731
[root@apache-php xcache-3.2.0]#./configure --enable-xcache --with-php-config=/apps/php73/bin/php-config
[root@apache-php xcache-3.2.0]#make
make: *** [Makefile:216: processor.out.c] Error 1 #经查,php版本太高,xcache不支持。
安装php5.6
[root@apache-php src]#yum install bzip2 -y
[root@apache-php src]#tar xf php-5.6.37.tar.bz2
[root@apache-php src]#cd php-5.6.37
[root@centos8 php-5.6.37]#./configure --prefix=/apps/php56 --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-mbstring --enable-xml --enable-sockets --enable-fpm --enable-maintainer-zts --disable-fileinfo
[root@centos8 php-5.6.37]#make
make: *** [Makefile:618: ext/openssl/openssl.lo] Error 1
网上查了一下发现是openssl版本太高了,php5.6不支持。从官网下载了openssl-1.0.2u尝试一下
[root@apache-php src]#tar xf openssl-1.0.2u.tar.gz
[root@apache-php src]#cd openssl-1.0.2u
#看了一下INSTALL说明,可以直接编译安装
[root@apache-php src]#./config
[root@apache-php src]#make && make install
安装路径在/usr/local/ssl/下
继续编译安装php5.6
[root@apache-php src]#cd php-5.6.37
[root@centos8 php-5.6.37]#./configure --prefix=/apps/php56 \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl=/usr/local/ssl/ \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo
[root@centos8 php-5.6.37]#.make
[root@apache-php php-5.6.37]#make install
Installing shared extensions: /apps/php56/lib/php/extensions/no-debug-zts-20131226/
Installing PHP CLI binary: /apps/php56/bin/
Installing PHP CLI man page: /apps/php56/php/man/man1/
Installing PHP FPM binary: /apps/php56/sbin/
Installing PHP FPM config: /apps/php56/etc/
Installing PHP FPM man page: /apps/php56/php/man/man8/
Installing PHP FPM status page: /apps/php56/php/php/fpm/
Installing PHP CGI binary: /apps/php56/bin/
Installing PHP CGI man page: /apps/php56/php/man/man1/
Installing build environment: /apps/php56/lib/php/build/
Installing header files: /apps/php56/include/php/
Installing helper programs: /apps/php56/bin/
program: phpize
program: php-config
Installing man pages: /apps/php56/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /apps/php56/lib/php/
[PEAR] Archive_Tar - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.2
[PEAR] PEAR - installed: 1.10.5
Wrote PEAR system config file at: /apps/php56/etc/pear.conf
You may want to add: /apps/php56/lib/php to your php.ini include_path
/usr/local/src/php-5.6.37/build/shtool install -c ext/phar/phar.phar /apps/php56/bin
ln -s -f phar.phar /apps/php56/bin/phar
Installing PDO headers: /apps/php56/include/php/ext/pdo/
[root@apache-php etc]#cp php-fpm.conf.default php-fpm.conf
#发现没有编写好的启动脚本,改改之前php7.3的
[root@apache-php php56]#cat /usr/lib/systemd/system/php-fpm.service
# It's not recommended to modify this file in-place, because it
# will be overwritten during upgrades. If you want to customize,
# the best way is to use the "systemctl edit" command.
[Unit]
Description=The PHP FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=/apps/php56/var/run/php-fpm.pid
ExecStart=/apps/php56/sbin/php-fpm --nodaemonize --fpm-config /apps/php56/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@apache-php php56]#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-02-21 19:14:10 CST; 2s ago
Main PID: 224228 (php-fpm)
Tasks: 3 (limit: 5882)
Memory: 4.3M
CGroup: /system.slice/php-fpm.service
├─224228 php-fpm: master process (/apps/php56/etc/php-fpm.conf)
├─224229 php-fpm: pool www
└─224230 php-fpm: pool www
Feb 21 19:14:10 apache-php systemd[1]: Started The PHP FastCGI Process Manager.
[root@apache-php xcache-3.2.0]#echo 'PATH=/apps/php56/bin:/apps/httpd24/bin:$PATH' > /etc/profile.d/lamp.sh
[root@apache-php xcache-3.2.0]#. /etc/profile.d/lamp.s
继续编译安装xcache
[root@apache-php xcache-3.2.0]#phpize --clean && phpize
Cleaning..
Configuring for:
PHP Api Version: 20180731
Zend Module Api No: 20180731
Zend Extension Api No: 320180731
[root@apache-php xcache-3.2.0]#./configure --enable-xcache --with-php-config=/apps/php56/bin/php-config
[root@apache-php xcache-3.2.0]#cp xcache.ini /apps/php56/etc/php.ini
二进制安装mysql服务器
[root@mysql ~]#hostname mysql
[root@mysql src]#yum -y -q install libaio numactl-libs ncurses-compat-libs perl
[root@mysql src]#tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local
[root@mysql src]#ln -s /usr/local/mysql-5.7.31-linux-glibc2.12-x86_64 /usr/local/mysql
[root@mysql local]#chown -R root.root /usr/local/mysql/
[root@mysql mysql]#useradd -s /sbin/nologin -r mysql
[root@mysql mysql]#echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh
[root@mysql mysql]#. /etc/profile.d/mysql.sh
[root@mysql mysql]#cat > /etc/my.cnf <<-EOF
> [mysqld]
> server-id=1
> log-bin
> datadir=/data/mysql
> socket=/data/mysql/mysql.sock
> log-error=/data/mysql/mysql.log
> pid-file=/data/mysql/mysql.pid
> [client]
> socket=/data/mysql/mysql.sock
> EOF
[root@mysql mysql]#mysqld --initialize --user=mysql --datadir=/data/mysql
[root@mysql mysql]#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@mysql mysql]#chkconfig --add mysqld
[root@mysql mysql]#chkconfig mysqld on
[root@mysql mysql]#service mysqld start
Starting MySQL. SUCCESS!
2、部署wordpress论坛,并实现正常访问登录论坛。
下载并安装wordpress
[root@apache-php src]#tar xf wordpress-4.7.4-zh_CN.tar.gz
[root@apache-php src]#mkdir /www/html/
[root@apache-php src]#mv wordpress /www/html/
#查看apache的proxy为空
[root@apache-php src]#httpd -M | grep proxy
#在/apps/httpd24/conf/httpd.conf主配置文件上打开proxy和proxy_fcgi模块
[root@apache-php src]#vim /apps/httpd24/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
Include conf.d/*.conf #加一句这个,就不再主配置目录增加网站了,便于修改
[root@apache-php src]#cat /apps/httpd24/conf.d/vhosts.conf
<virtualhost *:80>
documentroot /www/html/wordpress
servername www.yunmix.top
<directory /www/html/wordpress>
require all granted
</directory>
<ifmodule dir_module>
directoryindex index.php index.html index.htm
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/www/html/wordpress/$1
</ifmodule>
</virtualhost>
#这一步很重要,不然apache不能访问这个目录了
[root@apache-php html]#chown -R apache.apache wordpress/
数据库创建wordpress需要使用的库和账号权限
[root@mysql mysql]#mysql -uroot -pmagedu
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.31-log MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database wordpress;
mysql> grant all on wordpress.* to wordpress@'10.0.0.%' identified by 'magedu';
Query OK, 0 rows affected, 1 warning (0.00 sec)
展示:
3、收集apache访问日志,并实现图形化展示。"
在rsyslog服务器上安装连接mysql模块相关的程序包
[root@apache-php html]#yum install rsyslog-mysql
将sql脚本复制到数据库服库上并授权数据库账号
[root@apache-php html]#scp /usr/share/doc/rsyslog/mysql-createDB.sql 10.0.0.18:/data
The authenticity of host '10.0.0.18 (10.0.0.18)' can't be established.
ECDSA key fingerprint is SHA256:tSk0VxPd38Hnl4J0G7SMLXLOWG3JoLdNtIudnIP+bjY.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.0.0.18' (ECDSA) to the list of known hosts.
root@10.0.0.18's password:
mysql-createDB.sql
[root@mysql mysql]#mysql -uroot -pmagedu < /data/mysql-createDB.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@mysql mysql]#mysql -uroot -pmagedu
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 30
Server version: 5.7.31-log MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| Syslog |
| mysql |
| performance_schema |
| sys |
| wordpress |
+--------------------+
6 rows in set (0.01 sec)
mysql> GRANT ALL ON Syslog.* TO 'rsyslog'@'10.0.0.%' IDENTIFIED BY 'magedu';
Query OK, 0 rows affected, 1 warning (0.00 sec)
修改/apps/httpd24/conf/httpd.conf使日志重定向
[root@apache-php src]#vim /apps/httpd24/conf/httpd.conf
CustomLog "| /usr/bin/logger -p local6.info" combined #将日志定向到本地local6
[root@apache-php html]#systemctl restart httpd
修改 rsyslog的配置文件
[root@apache-php html]#vim /etc/rsyslog.conf
#### MODULES #### #找到此处,在其下添加模块centos8
module(load="ommysql")
#### RULES #### #找到此处,在其下添加数据库连接信息
##facility.priority :ommysql:DBHOST,DBNAME,DBUSER, PASSWORD
local6.* :ommysql:10.0.0.18,Syslog,rsyslog,magedu #数据库名,账号,密码
[root@apache-php html]#systemctl restart rsyslog
安装LogAnalyzer
[root@apache-php src]#tar xf loganalyzer-4.1.11.tar.gz
[root@apache-php src]#mv loganalyzer-4.1.11/src/ /www/html/log
[root@apache-php src]#touch /www/html/log/config.php
[root@apache-php src]#chmod 666 /www/html/log/config.php
配置虚拟主机
[root@apache-php src]#cat /apps/httpd24/conf.d/vhosts.conf
<virtualhost *:80>
documentroot /www/html/wordpress
servername www.yunmix.top
<directory /www/html/wordpress>
require all granted
</directory>
<ifmodule dir_module>
directoryindex index.php index.html index.htm
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/www/html/wordpress/$1
</ifmodule>
</virtualhost>
<virtualhost *:80>
documentroot /www/html/log
servername log.yunmix.top
<directory /www/html/log>
require all granted
</directory>
<ifmodule dir_module>
directoryindex index.php index.html index.htm
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/www/html/log/$1
</ifmodule>
</virtualhost>
显示饼状图需安装php-gd
[root@apache-php html]#yum install php-gd -y
[root@apache-php html]#systemctl restart php-fpm
图片好像刷新不出来…
标签:httpd,第十八,--,练习,---,mysql,apache,php,root 来源: https://blog.csdn.net/weixin_50904580/article/details/113914815