当前位置: 首页 > news >正文

Linux入门DAY21

Linux入门DAY21

WEB服务器

Nginx

配置基本认证

用户名和密码使用plain text发送,所以最好配置SSL/TLS

#安装工具
[root@server ~ 09:23:49]# yum -y install httpd-tools
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
base                                                            | 3.6 kB  00:00:00     
epel                                                            | 4.3 kB  00:00:00     
extras                                                          | 2.9 kB  00:00:00     
updates                                                         | 2.9 kB  00:00:00     
软件包 httpd-tools-2.4.6-99.el7.centos.1.x86_64 已安装并且是最新版本
无须任何处理
[root@server ~ 09:24:13]# vim /etc/nginx/conf.d/ssl.conf #注意括号嵌套引用
server {.....location /auth-basic/ {auth_basic            "Basic Auth";auth_basic_user_file  "/etc/nginx/.htpasswd";}
}#这里多写一个括号报错
[root@server ~ 09:25:25]# systemctl restart nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
[root@server ~ 09:25:38]# vim /etc/nginx/conf.d/ssl.conf 
[root@server ~ 09:25:57]# vim /etc/nginx/conf.d/ssl.conf 
[root@server ~ 09:26:00]# systemctl restart nginx#添加用户
[root@server ~ 09:26:02]# htpasswd -c /etc/nginx/.htpasswd phoenix
New password: 
Re-type new password: 
Adding password for user phoenix#准备测试页
[root@server ~ 09:26:16]# mkdir /usr/share/nginx/html/auth-basic
[root@server ~ 09:26:23]# vim /usr/share/nginx/html/auth-basic/index.html<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: phoenixer;">
Test Page for Basic Authentication
</div>
</body>
</html>[root@server ~ 09:26:46]# systemctl restart nginx
[root@server ~ 09:28:07]# yum install -y nginx
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
软件包 1:nginx-1.20.1-10.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@server ~ 09:33:07]# systemctl restart nginx
[root@server ~ 09:33:11]# systemctl start nginx
[root@server ~ 09:33:17]# systemctl start nginx --now
[root@server ~ 09:33:21]# systemctl start nginx#windows hosts文件 10.1.8.10 www.phoenix.cloud
#测试网页 https://www.phoenix.cloud/auth-basic

支持动态脚本

使用PHP

#安装php
[root@server ~ 10:14:42]# yum install -y php php-fpm
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
正在解决依赖关系
There are unfinished transactions remaining. You might consider running yum-complete-transaction, or "yum-complete-transaction --cleanup-only" and "yum history redo last", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help).
--> 正在检查事务
---> 软件包 php.x86_64.0.5.4.16-48.el7 将被 安装
--> 正在处理依赖关系 php-common(x86-64) = 5.4.16-48.el7,它被软件包 php-5.4.16-48.el7.x86_64 需要
--> 正在处理依赖关系 php-cli(x86-64) = 5.4.16-48.el7,它被软件包 php-5.4.16-48.el7.x86_64 需要
--> 正在处理依赖关系 httpd-mmn = 20120211x8664,它被软件包 php-5.4.16-48.el7.x86_64 需要
--> 正在处理依赖关系 httpd,它被软件包 php-5.4.16-48.el7.x86_64 需要
---> 软件包 php-fpm.x86_64.0.5.4.16-48.el7 将被 安装
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-99.el7.centos.1 将被 安装
---> 软件包 php-cli.x86_64.0.5.4.16-48.el7 将被 安装
---> 软件包 php-common.x86_64.0.5.4.16-48.el7 将被 安装
--> 正在处理依赖关系 libzip.so.2()(64bit),它被软件包 php-common-5.4.16-48.el7.x86_64 需要
--> 正在检查事务
---> 软件包 libzip.x86_64.0.0.10.1-8.el7 将被 安装
--> 解决依赖关系完成依赖关系解决=======================================================================================Package            架构           版本                          源               大小
=======================================================================================
正在安装:php                x86_64         5.4.16-48.el7                 base            1.4 Mphp-fpm            x86_64         5.4.16-48.el7                 base            1.4 M
为依赖而安装:httpd              x86_64         2.4.6-99.el7.centos.1         updates         2.7 Mlibzip             x86_64         0.10.1-8.el7                  base             48 kphp-cli            x86_64         5.4.16-48.el7                 base            2.7 Mphp-common         x86_64         5.4.16-48.el7                 base            565 k事务概要
=======================================================================================
安装  2 软件包 (+4 依赖软件包)总下载量:8.8 M
安装大小:31 M
Downloading packages:
(1/6): libzip-0.10.1-8.el7.x86_64.rpm                           |  48 kB  00:00:00     
(2/6): httpd-2.4.6-99.el7.centos.1.x86_64.rpm                   | 2.7 MB  00:00:00     
(3/6): php-5.4.16-48.el7.x86_64.rpm                             | 1.4 MB  00:00:00     
(4/6): php-cli-5.4.16-48.el7.x86_64.rpm                         | 2.7 MB  00:00:00     
(5/6): php-fpm-5.4.16-48.el7.x86_64.rpm                         | 1.4 MB  00:00:00     
(6/6): php-common-5.4.16-48.el7.x86_64.rpm                      | 565 kB  00:00:00     
---------------------------------------------------------------------------------------
总计                                                      8.1 MB/s | 8.8 MB  00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction正在安装    : libzip-0.10.1-8.el7.x86_64                                         1/6 正在安装    : php-common-5.4.16-48.el7.x86_64                                    2/6 正在安装    : php-cli-5.4.16-48.el7.x86_64                                       3/6 正在安装    : httpd-2.4.6-99.el7.centos.1.x86_64                                 4/6 正在安装    : php-5.4.16-48.el7.x86_64                                           5/6 正在安装    : php-fpm-5.4.16-48.el7.x86_64                                       6/6 验证中      : php-fpm-5.4.16-48.el7.x86_64                                       1/6 验证中      : php-cli-5.4.16-48.el7.x86_64                                       2/6 验证中      : httpd-2.4.6-99.el7.centos.1.x86_64                                 3/6 验证中      : libzip-0.10.1-8.el7.x86_64                                         4/6 验证中      : php-common-5.4.16-48.el7.x86_64                                    5/6 验证中      : php-5.4.16-48.el7.x86_64                                           6/6 已安装:php.x86_64 0:5.4.16-48.el7               php-fpm.x86_64 0:5.4.16-48.el7              作为依赖被安装:httpd.x86_64 0:2.4.6-99.el7.centos.1        libzip.x86_64 0:0.10.1-8.el7            php-cli.x86_64 0:5.4.16-48.el7              php-common.x86_64 0:5.4.16-48.el7       完毕!#安装扩展包
[root@server ~ 10:14:54]# yum install -y php-gd php-common php-pear php-mbstring php-mcrypt
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
软件包 php-common-5.4.16-48.el7.x86_64 已安装并且是最新版本
正在解决依赖关系
There are unfinished transactions remaining. You might consider running yum-complete-transaction, or "yum-complete-transaction --cleanup-only" and "yum history redo last", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help).
--> 正在检查事务
---> 软件包 php-gd.x86_64.0.5.4.16-48.el7 将被 安装
--> 正在处理依赖关系 libt1.so.5()(64bit),它被软件包 php-gd-5.4.16-48.el7.x86_64 需要
---> 软件包 php-mbstring.x86_64.0.5.4.16-48.el7 将被 安装
---> 软件包 php-mcrypt.x86_64.0.5.4.16-9.el7 将被 安装
--> 正在处理依赖关系 libmcrypt.so.4()(64bit),它被软件包 php-mcrypt-5.4.16-9.el7.x86_64 需要
---> 软件包 php-pear.noarch.1.1.9.4-23.el7_9 将被 安装
--> 正在处理依赖关系 php-xml,它被软件包 1:php-pear-1.9.4-23.el7_9.noarch 需要
--> 正在处理依赖关系 php-posix,它被软件包 1:php-pear-1.9.4-23.el7_9.noarch 需要
--> 正在检查事务
---> 软件包 libmcrypt.x86_64.0.2.5.8-13.el7 将被 安装
---> 软件包 php-process.x86_64.0.5.4.16-48.el7 将被 安装
---> 软件包 php-xml.x86_64.0.5.4.16-48.el7 将被 安装
---> 软件包 t1lib.x86_64.0.5.1.2-14.el7 将被 安装
--> 解决依赖关系完成依赖关系解决=======================================================================================Package              架构           版本                        源               大小
=======================================================================================
正在安装:php-gd               x86_64         5.4.16-48.el7               base            128 kphp-mbstring         x86_64         5.4.16-48.el7               base            506 kphp-mcrypt           x86_64         5.4.16-9.el7                epel             20 kphp-pear             noarch         1:1.9.4-23.el7_9            updates         361 k
为依赖而安装:libmcrypt            x86_64         2.5.8-13.el7                epel             99 kphp-process          x86_64         5.4.16-48.el7               base             56 kphp-xml              x86_64         5.4.16-48.el7               base            126 kt1lib                x86_64         5.1.2-14.el7                base            166 k事务概要
=======================================================================================
安装  4 软件包 (+4 依赖软件包)总下载量:1.4 M
安装大小:4.9 M
Downloading packages:
(1/8): libmcrypt-2.5.8-13.el7.x86_64.rpm                        |  99 kB  00:00:00     
(2/8): php-mcrypt-5.4.16-9.el7.x86_64.rpm                       |  20 kB  00:00:00     
(3/8): php-gd-5.4.16-48.el7.x86_64.rpm                          | 128 kB  00:00:00     
(4/8): php-process-5.4.16-48.el7.x86_64.rpm                     |  56 kB  00:00:00     
(5/8): php-xml-5.4.16-48.el7.x86_64.rpm                         | 126 kB  00:00:00     
(6/8): php-mbstring-5.4.16-48.el7.x86_64.rpm                    | 506 kB  00:00:00     
(7/8): t1lib-5.1.2-14.el7.x86_64.rpm                            | 166 kB  00:00:00     
(8/8): php-pear-1.9.4-23.el7_9.noarch.rpm                       | 361 kB  00:00:00     
---------------------------------------------------------------------------------------
总计                                                      2.9 MB/s | 1.4 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction正在安装    : libmcrypt-2.5.8-13.el7.x86_64                                      1/8 正在安装    : php-process-5.4.16-48.el7.x86_64                                   2/8 正在安装    : t1lib-5.1.2-14.el7.x86_64                                          3/8 正在安装    : php-xml-5.4.16-48.el7.x86_64                                       4/8 正在安装    : 1:php-pear-1.9.4-23.el7_9.noarch                                   5/8 正在安装    : php-gd-5.4.16-48.el7.x86_64                                        6/8 正在安装    : php-mcrypt-5.4.16-9.el7.x86_64                                     7/8 正在安装    : php-mbstring-5.4.16-48.el7.x86_64                                  8/8 验证中      : php-xml-5.4.16-48.el7.x86_64                                       1/8 验证中      : php-mcrypt-5.4.16-9.el7.x86_64                                     2/8 验证中      : t1lib-5.1.2-14.el7.x86_64                                          3/8 验证中      : php-process-5.4.16-48.el7.x86_64                                   4/8 验证中      : php-mbstring-5.4.16-48.el7.x86_64                                  5/8 验证中      : php-gd-5.4.16-48.el7.x86_64                                        6/8 验证中      : 1:php-pear-1.9.4-23.el7_9.noarch                                   7/8 验证中      : libmcrypt-2.5.8-13.el7.x86_64                                      8/8 已安装:php-gd.x86_64 0:5.4.16-48.el7            php-mbstring.x86_64 0:5.4.16-48.el7        php-mcrypt.x86_64 0:5.4.16-9.el7         php-pear.noarch 1:1.9.4-23.el7_9           作为依赖被安装:libmcrypt.x86_64 0:2.5.8-13.el7          php-process.x86_64 0:5.4.16-48.el7         php-xml.x86_64 0:5.4.16-48.el7           t1lib.x86_64 0:5.1.2-14.el7                完毕!#查看php版本
[root@server ~ 10:15:03]# php -v
PHP 5.4.16 (cli) (built: Apr  1 2020 04:07:17) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies#测试php
[root@server ~ 10:15:04]# echo "<?php echo 'PHP Test Page'.\"\n\"; ?>" > php_test.php 
[root@server ~ 10:15:08]# php php_test.php 
PHP Test Page#准备测试页
[root@server ~ 10:15:11]# echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php # 修改配置文件
[root@www ~]# vim /etc/nginx/nginx.conf
# add into the [server] section
include /etc/nginx/conf.d/*.conf;server {listen       80;listen       [::]:80;server_name  www.phoenix.cloud;root         /usr/share/nginx/html;server {.....location ~ \.php$ {try_files $uri =404;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}[root@server ~ 10:15:15]# systemctl restart nginx.service
[root@server ~ 10:15:43]# systemctl start nginx --now
[root@server ~ 10:15:53]# php php_test.php 
PHP Test Page
[root@server ~ 10:27:32]# vim /etc/nginx/nginx.conf
[root@server ~ 10:29:15]#  php php_test.php
PHP Test Page
[root@server ~ 10:29:28]# echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php 
[root@server ~ 10:29:31]# 
[root@server ~ 10:29:31]# systemctl restart php-fpm.service 
[root@server ~ 10:30:04]# systemctl restart nginx.service
[root@server ~ 10:30:14]# systemctl restart php-fpm.service ^C
[root@server ~ 10:34:05]# ls /etc/nginx/conf.d/
ssl.conf  vhost-port8081.conf  vhost-port8082.conf  vhost-web1.conf  vhost-web2.conf
[root@server ~ 10:34:32]# rm /etc/nginx/conf.d/vhost-port*
rm:是否删除普通文件 "/etc/nginx/conf.d/vhost-port8081.conf"?y
rm:是否删除普通文件 "/etc/nginx/conf.d/vhost-port8082.conf"?y
[root@server ~ 10:34:57]# systemctl restart nginx.service
[root@server ~ 10:35:01]# vi vhost-web1.conf
[root@server ~ 10:35:24]# vi /etc/nginx/conf.d/vhost-web1.conf
[root@server ~ 10:35:58]# vi /etc/nginx/conf.d/vhost-web1.conf
[root@server ~ 10:36:06]# systemctl restart php-fpm
[root@server ~ 10:37:09]# systemctl restart nginx
[root@server ~ 10:37:34]# systemctl start php-fpm --now[root@server ~ 10:39:54]# systemctl start nginx --now
[root@server ~ 10:40:10]# systemctl start php-fpm --now[root@server ~ 10:43:14]# systemctl restart nginx.service #测试
[root@client ~ 10:42:44]# curl www.phoenix.cloud/info.php

Tomcat

Tomcat 服务器是一个免费的开放源代码的 Web 应用服务器,属于轻量级应用服务器,在中小型系统和用户并发访问不多的场合下使用,是开发和调试JSP 程序的首选。因为Tomcat技术先进、性能稳定而且免费,因而深受Java爱好者的喜爱并得到了部分软件开发商的认可,成为目前比较流行的Web应用服务器

Tomcat部署

#安装tomcat 自动解决java jdk依赖
[root@server ~ 10:59:02]#  yum install -y tomcat
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
正在解决依赖关系
There are unfinished transactions remaining. You might consider running yum-complete-transaction, or "yum-complete-transaction --cleanup-only" and "yum history redo last", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help).
--> 正在检查事务
---> 软件包 tomcat.noarch.0.7.0.76-16.el7_9 将被 安装
--> 正在处理依赖关系 tomcat-lib = 7.0.76-16.el7_9,它被软件包 tomcat-7.0.76-16.el7_9.noarch 需要
--> 正在处理依赖关系 apache-commons-pool,它被软件包 tomcat-7.0.76-16.el7_9.noarch 需要
--> 正在处理依赖关系 apache-commons-logging,它被软件包 tomcat-7.0.76-16.el7_9.noarch 需要
--> 正在处理依赖关系 apache-commons-dbcp,它被软件包 tomcat-7.0.76-16.el7_9.noarch 需要
--> 正在处理依赖关系 apache-commons-daemon,它被软件包 tomcat-7.0.76-16.el7_9.noarch 需要
--> 正在处理依赖关系 apache-commons-collections,它被软件包 tomcat-7.0.76-16.el7_9.noarch 需要
--> 正在检查事务
---> 软件包 apache-commons-collections.noarch.0.3.2.1-22.el7_2 将被 安装
---> 软件包 apache-commons-daemon.x86_64.0.1.0.13-7.el7 将被 安装
---> 软件包 apache-commons-dbcp.noarch.0.1.4-17.el7 将被 安装
--> 正在处理依赖关系 mvn(org.apache.geronimo.specs:geronimo-jta_1.1_spec),它被软件包 apache-commons-dbcp-1.4-17.el7.noarch 需要
---> 软件包 apache-commons-logging.noarch.0.1.1.2-7.el7 将被 安装
--> 正在处理依赖关系 mvn(logkit:logkit),它被软件包 apache-commons-logging-1.1.2-7.el7.noarch 需要
--> 正在处理依赖关系 mvn(log4j:log4j),它被软件包 apache-commons-logging-1.1.2-7.el7.noarch 需要
--> 正在处理依赖关系 mvn(avalon-framework:avalon-framework-api),它被软件包 apache-commons-logging-1.1.2-7.el7.noarch 需要
---> 软件包 apache-commons-pool.noarch.0.1.6-9.el7 将被 安装
---> 软件包 tomcat-lib.noarch.0.7.0.76-16.el7_9 将被 安装
--> 正在处理依赖关系 tomcat-servlet-3.0-api = 7.0.76-16.el7_9,它被软件包 tomcat-lib-7.0.76-16.el7_9.noarch 需要
--> 正在处理依赖关系 tomcat-jsp-2.2-api = 7.0.76-16.el7_9,它被软件包 tomcat-lib-7.0.76-16.el7_9.noarch 需要
--> 正在处理依赖关系 tomcat-el-2.2-api = 7.0.76-16.el7_9,它被软件包 tomcat-lib-7.0.76-16.el7_9.noarch 需要
--> 正在处理依赖关系 ecj >= 1:4.2.1,它被软件包 tomcat-lib-7.0.76-16.el7_9.noarch 需要
--> 正在检查事务
---> 软件包 avalon-framework.noarch.0.4.3-10.el7 将被 安装
--> 正在处理依赖关系 xalan-j2,它被软件包 avalon-framework-4.3-10.el7.noarch 需要
---> 软件包 avalon-logkit.noarch.0.2.1-14.el7 将被 安装
--> 正在处理依赖关系 jms,它被软件包 avalon-logkit-2.1-14.el7.noarch 需要
---> 软件包 ecj.x86_64.1.4.5.2-3.el7 将被 安装
---> 软件包 geronimo-jta.noarch.0.1.1.1-17.el7 将被 安装
---> 软件包 log4j.noarch.0.1.2.17-18.el7_4 将被 安装
--> 正在处理依赖关系 mvn(javax.mail:mail),它被软件包 log4j-1.2.17-18.el7_4.noarch 需要
---> 软件包 tomcat-el-2.2-api.noarch.0.7.0.76-16.el7_9 将被 安装
---> 软件包 tomcat-jsp-2.2-api.noarch.0.7.0.76-16.el7_9 将被 安装
---> 软件包 tomcat-servlet-3.0-api.noarch.0.7.0.76-16.el7_9 将被 安装
--> 正在检查事务
---> 软件包 geronimo-jms.noarch.0.1.1.1-19.el7 将被 安装
---> 软件包 javamail.noarch.0.1.4.6-8.el7 将被 安装
---> 软件包 xalan-j2.noarch.0.2.7.1-23.el7 将被 安装
--> 正在处理依赖关系 xerces-j2,它被软件包 xalan-j2-2.7.1-23.el7.noarch 需要
--> 正在处理依赖关系 osgi(org.apache.xerces),它被软件包 xalan-j2-2.7.1-23.el7.noarch 需要
--> 正在检查事务
---> 软件包 xerces-j2.noarch.0.2.11.0-17.el7_0 将被 安装
--> 正在处理依赖关系 xml-commons-resolver >= 1.2,它被软件包 xerces-j2-2.11.0-17.el7_0.noarch 需要
--> 正在处理依赖关系 xml-commons-apis >= 1.4.01,它被软件包 xerces-j2-2.11.0-17.el7_0.noarch 需要
--> 正在处理依赖关系 osgi(org.apache.xml.resolver),它被软件包 xerces-j2-2.11.0-17.el7_0.noarch 需要
--> 正在处理依赖关系 osgi(javax.xml),它被软件包 xerces-j2-2.11.0-17.el7_0.noarch 需要
--> 正在检查事务
---> 软件包 xml-commons-apis.noarch.0.1.4.01-16.el7 将被 安装
---> 软件包 xml-commons-resolver.noarch.0.1.2-15.el7 将被 安装
--> 解决依赖关系完成依赖关系解决=======================================================================================Package                         架构        版本                   源            大小
=======================================================================================
正在安装:tomcat                          noarch      7.0.76-16.el7_9        updates       93 k
为依赖而安装:apache-commons-collections      noarch      3.2.1-22.el7_2         base         509 kapache-commons-daemon           x86_64      1.0.13-7.el7           base          54 kapache-commons-dbcp             noarch      1.4-17.el7             base         167 kapache-commons-logging          noarch      1.1.2-7.el7            base          78 kapache-commons-pool             noarch      1.6-9.el7              base         113 kavalon-framework                noarch      4.3-10.el7             base          88 kavalon-logkit                   noarch      2.1-14.el7             base          87 kecj                             x86_64      1:4.5.2-3.el7          base         1.9 Mgeronimo-jms                    noarch      1.1.1-19.el7           base          31 kgeronimo-jta                    noarch      1.1.1-17.el7           base          20 kjavamail                        noarch      1.4.6-8.el7            base         758 klog4j                           noarch      1.2.17-18.el7_4        updates      445 ktomcat-el-2.2-api               noarch      7.0.76-16.el7_9        updates       83 ktomcat-jsp-2.2-api              noarch      7.0.76-16.el7_9        updates       96 ktomcat-lib                      noarch      7.0.76-16.el7_9        updates      3.9 Mtomcat-servlet-3.0-api          noarch      7.0.76-16.el7_9        updates      214 kxalan-j2                        noarch      2.7.1-23.el7           base         1.9 Mxerces-j2                       noarch      2.11.0-17.el7_0        base         1.1 Mxml-commons-apis                noarch      1.4.01-16.el7          base         227 kxml-commons-resolver            noarch      1.2-15.el7             base         108 k事务概要
=======================================================================================
安装  1 软件包 (+20 依赖软件包)总下载量:12 M
安装大小:15 M
Downloading packages:
(1/21): apache-commons-daemon-1.0.13-7.el7.x86_64.rpm           |  54 kB  00:00:00     
(2/21): apache-commons-dbcp-1.4-17.el7.noarch.rpm               | 167 kB  00:00:00     
(3/21): apache-commons-collections-3.2.1-22.el7_2.noarch.rpm    | 509 kB  00:00:00     
(4/21): apache-commons-logging-1.1.2-7.el7.noarch.rpm           |  78 kB  00:00:00     
(5/21): apache-commons-pool-1.6-9.el7.noarch.rpm                | 113 kB  00:00:00     
(6/21): avalon-framework-4.3-10.el7.noarch.rpm                  |  88 kB  00:00:00     
(7/21): avalon-logkit-2.1-14.el7.noarch.rpm                     |  87 kB  00:00:00     
(8/21): geronimo-jms-1.1.1-19.el7.noarch.rpm                    |  31 kB  00:00:00     
(9/21): geronimo-jta-1.1.1-17.el7.noarch.rpm                    |  20 kB  00:00:00     
(10/21): ecj-4.5.2-3.el7.x86_64.rpm                             | 1.9 MB  00:00:00     
(11/21): javamail-1.4.6-8.el7.noarch.rpm                        | 758 kB  00:00:00     
(12/21): tomcat-7.0.76-16.el7_9.noarch.rpm                      |  93 kB  00:00:00     
(13/21): tomcat-el-2.2-api-7.0.76-16.el7_9.noarch.rpm           |  83 kB  00:00:00     
(14/21): tomcat-jsp-2.2-api-7.0.76-16.el7_9.noarch.rpm          |  96 kB  00:00:00     
(15/21): log4j-1.2.17-18.el7_4.noarch.rpm                       | 445 kB  00:00:00     
(16/21): tomcat-servlet-3.0-api-7.0.76-16.el7_9.noarch.rpm      | 214 kB  00:00:00     
(17/21): xerces-j2-2.11.0-17.el7_0.noarch.rpm                   | 1.1 MB  00:00:00     
(18/21): xml-commons-apis-1.4.01-16.el7.noarch.rpm              | 227 kB  00:00:00     
(19/21): xml-commons-resolver-1.2-15.el7.noarch.rpm             | 108 kB  00:00:00     
(20/21): tomcat-lib-7.0.76-16.el7_9.noarch.rpm                  | 3.9 MB  00:00:01     
(21/21): xalan-j2-2.7.1-23.el7.noarch.rpm                       | 1.9 MB  00:00:01     
---------------------------------------------------------------------------------------
总计                                                      3.3 MB/s |  12 MB  00:03     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction正在安装    : tomcat-servlet-3.0-api-7.0.76-16.el7_9.noarch                     1/21 正在安装    : apache-commons-pool-1.6-9.el7.noarch                              2/21 正在安装    : geronimo-jms-1.1.1-19.el7.noarch                                  3/21 正在安装    : apache-commons-collections-3.2.1-22.el7_2.noarch                  4/21 正在安装    : xml-commons-apis-1.4.01-16.el7.noarch                             5/21 正在安装    : xml-commons-resolver-1.2-15.el7.noarch                            6/21 正在安装    : xalan-j2-2.7.1-23.el7.noarch                                      7/21 正在安装    : xerces-j2-2.11.0-17.el7_0.noarch                                  8/21 正在安装    : tomcat-jsp-2.2-api-7.0.76-16.el7_9.noarch                         9/21 正在安装    : geronimo-jta-1.1.1-17.el7.noarch                                 10/21 正在安装    : apache-commons-dbcp-1.4-17.el7.noarch                            11/21 正在安装    : apache-commons-daemon-1.0.13-7.el7.x86_64                        12/21 正在安装    : 1:ecj-4.5.2-3.el7.x86_64                                         13/21 正在安装    : tomcat-el-2.2-api-7.0.76-16.el7_9.noarch                         14/21 正在安装    : tomcat-lib-7.0.76-16.el7_9.noarch                                15/21 正在安装    : javamail-1.4.6-8.el7.noarch                                      16/21 正在安装    : log4j-1.2.17-18.el7_4.noarch                                     17/21 正在安装    : apache-commons-logging-1.1.2-7.el7.noarch                        18/21 正在安装    : avalon-logkit-2.1-14.el7.noarch                                  19/21 正在安装    : avalon-framework-4.3-10.el7.noarch                               20/21 正在安装    : tomcat-7.0.76-16.el7_9.noarch                                    21/21 验证中      : xml-commons-apis-1.4.01-16.el7.noarch                             1/21 验证中      : tomcat-jsp-2.2-api-7.0.76-16.el7_9.noarch                         2/21 验证中      : apache-commons-logging-1.1.2-7.el7.noarch                         3/21 验证中      : tomcat-7.0.76-16.el7_9.noarch                                     4/21 验证中      : xalan-j2-2.7.1-23.el7.noarch                                      5/21 验证中      : tomcat-lib-7.0.76-16.el7_9.noarch                                 6/21 验证中      : javamail-1.4.6-8.el7.noarch                                       7/21 验证中      : avalon-logkit-2.1-14.el7.noarch                                   8/21 验证中      : avalon-framework-4.3-10.el7.noarch                                9/21 验证中      : tomcat-el-2.2-api-7.0.76-16.el7_9.noarch                         10/21 验证中      : apache-commons-pool-1.6-9.el7.noarch                             11/21 验证中      : tomcat-servlet-3.0-api-7.0.76-16.el7_9.noarch                    12/21 验证中      : 1:ecj-4.5.2-3.el7.x86_64                                         13/21 验证中      : apache-commons-dbcp-1.4-17.el7.noarch                            14/21 验证中      : apache-commons-daemon-1.0.13-7.el7.x86_64                        15/21 验证中      : log4j-1.2.17-18.el7_4.noarch                                     16/21 验证中      : geronimo-jta-1.1.1-17.el7.noarch                                 17/21 验证中      : apache-commons-collections-3.2.1-22.el7_2.noarch                 18/21 验证中      : geronimo-jms-1.1.1-19.el7.noarch                                 19/21 验证中      : xerces-j2-2.11.0-17.el7_0.noarch                                 20/21 验证中      : xml-commons-resolver-1.2-15.el7.noarch                           21/21 已安装:tomcat.noarch 0:7.0.76-16.el7_9                                                      作为依赖被安装:apache-commons-collections.noarch 0:3.2.1-22.el7_2                                   apache-commons-daemon.x86_64 0:1.0.13-7.el7                                          apache-commons-dbcp.noarch 0:1.4-17.el7                                              apache-commons-logging.noarch 0:1.1.2-7.el7                                          apache-commons-pool.noarch 0:1.6-9.el7                                               avalon-framework.noarch 0:4.3-10.el7                                                 avalon-logkit.noarch 0:2.1-14.el7                                                    ecj.x86_64 1:4.5.2-3.el7                                                             geronimo-jms.noarch 0:1.1.1-19.el7                                                   geronimo-jta.noarch 0:1.1.1-17.el7                                                   javamail.noarch 0:1.4.6-8.el7                                                        log4j.noarch 0:1.2.17-18.el7_4                                                       tomcat-el-2.2-api.noarch 0:7.0.76-16.el7_9                                           tomcat-jsp-2.2-api.noarch 0:7.0.76-16.el7_9                                          tomcat-lib.noarch 0:7.0.76-16.el7_9                                                  tomcat-servlet-3.0-api.noarch 0:7.0.76-16.el7_9                                      xalan-j2.noarch 0:2.7.1-23.el7                                                       xerces-j2.noarch 0:2.11.0-17.el7_0                                                   xml-commons-apis.noarch 0:1.4.01-16.el7                                              xml-commons-resolver.noarch 0:1.2-15.el7                                             完毕!#启服
[root@server ~ 11:13:52]# systemctl enable --now tomcat.service
Created symlink from /etc/systemd/system/multi-user.target.wants/tomcat.service to /usr/lib/systemd/system/tomcat.service.#准备测试页面
[root@server ~ 11:13:53]# cd /var/lib/tomcat/webapps/
[root@server webapps 11:14:00]#  mkdir test
[root@server webapps 11:14:03]# vim test/index.jsp<html><head><title>第一个 JSP 程序</title></head><body><%out.println("Hello World!");%></body>
</html>#测试
[root@client ~ 11:13:09]# curl www.phoenix.cloud:8080/test/index.jsp
<html><head><title>第一个 JSP 程序</title></head><body>Hello World!<body>
</html>

server流量分流

#server 作为tomcat 服务器
#client 作为nginx反向代理
[root@server ~ 11:18:19]# yum install -y nginx
[root@server ~ 11:30:14]# vim /etc/nginx/nginx.confhttp {......upstream tomcat {server www.phoenix.cloud:8080;}......server {......proxy_redirect      off;proxy_set_header    X-Real-IP $remote_addr;proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header    Host $http_host;location /tomcat/ {proxy_pass http://tomcat/;}}
}     [root@server ~ 11:31:20]systemctl restart nginx.service [root@server ~ 11:31:23]# echo hello world > /usr/share/nginx/html/index.html
[root@server ~ 11:31:23]# mkdir /usr/share/nginx/html/web1[root@server ~ 11:31:35]# echo hello WEB1 > /usr/share/nginx/html/web1/index.html#测试
[root@client ~ 11:59:03]# curl www.phoenix.cloud
hello world
[root@client ~ 11:59:22]# curl www.phoenix.cloud/web1/
hello WEB1

项目实战LAMP/LNMP

部署Mysql

#安装mariadb
[root@server ~ 14:01:34]# yum install -y mariadb-server
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
正在解决依赖关系
There are unfinished transactions remaining. You might consider running yum-complete-transaction, or "yum-complete-transaction --cleanup-only" and "yum history redo last", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help).
--> 正在检查事务
---> 软件包 mariadb-server.x86_64.1.5.5.68-1.el7 将被 安装
--> 正在处理依赖关系 perl-DBI,它被软件包 1:mariadb-server-5.5.68-1.el7.x86_64 需要
--> 正在处理依赖关系 perl-DBD-MySQL,它被软件包 1:mariadb-server-5.5.68-1.el7.x86_64 需要
--> 正在处理依赖关系 perl(Data::Dumper),它被软件包 1:mariadb-server-5.5.68-1.el7.x86_64 需要
--> 正在处理依赖关系 perl(DBI),它被软件包 1:mariadb-server-5.5.68-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 perl-DBD-MySQL.x86_64.0.4.023-6.el7 将被 安装
---> 软件包 perl-DBI.x86_64.0.1.627-4.el7 将被 安装
--> 正在处理依赖关系 perl(RPC::PlServer) >= 0.2001,它被软件包 perl-DBI-1.627-4.el7.x86_64 需要
--> 正在处理依赖关系 perl(RPC::PlClient) >= 0.2000,它被软件包 perl-DBI-1.627-4.el7.x86_64 需要
---> 软件包 perl-Data-Dumper.x86_64.0.2.145-3.el7 将被 安装
--> 正在检查事务
---> 软件包 perl-PlRPC.noarch.0.0.2020-14.el7 将被 安装
--> 正在处理依赖关系 perl(Net::Daemon) >= 0.13,它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在处理依赖关系 perl(Net::Daemon::Test),它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在处理依赖关系 perl(Net::Daemon::Log),它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在处理依赖关系 perl(Compress::Zlib),它被软件包 perl-PlRPC-0.2020-14.el7.noarch 需要
--> 正在检查事务
---> 软件包 perl-IO-Compress.noarch.0.2.061-2.el7 将被 安装
--> 正在处理依赖关系 perl(Compress::Raw::Zlib) >= 2.061,它被软件包 perl-IO-Compress-2.061-2.el7.noarch 需要
--> 正在处理依赖关系 perl(Compress::Raw::Bzip2) >= 2.061,它被软件包 perl-IO-Compress-2.061-2.el7.noarch 需要
---> 软件包 perl-Net-Daemon.noarch.0.0.48-5.el7 将被 安装
--> 正在检查事务
---> 软件包 perl-Compress-Raw-Bzip2.x86_64.0.2.061-3.el7 将被 安装
---> 软件包 perl-Compress-Raw-Zlib.x86_64.1.2.061-4.el7 将被 安装
--> 解决依赖关系完成依赖关系解决======================================================================================================================Package                                架构                  版本                          源                   大小
======================================================================================================================
正在安装:mariadb-server                         x86_64                1:5.5.68-1.el7                base                 11 M
为依赖而安装:perl-Compress-Raw-Bzip2                x86_64                2.061-3.el7                   base                 32 kperl-Compress-Raw-Zlib                 x86_64                1:2.061-4.el7                 base                 57 kperl-DBD-MySQL                         x86_64                4.023-6.el7                   base                140 kperl-DBI                               x86_64                1.627-4.el7                   base                802 kperl-Data-Dumper                       x86_64                2.145-3.el7                   base                 47 kperl-IO-Compress                       noarch                2.061-2.el7                   base                260 kperl-Net-Daemon                        noarch                0.48-5.el7                    base                 51 kperl-PlRPC                             noarch                0.2020-14.el7                 base                 36 k事务概要
======================================================================================================================
安装  1 软件包 (+8 依赖软件包)总下载量:13 M
安装大小:62 M
Downloading packages:
(1/9): mariadb-server-5.5.68-1.el7.x86_64.rpm                                                  |  11 MB  00:00:02     
(2/9): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm                                           |  57 kB  00:00:00     
(3/9): perl-DBD-MySQL-4.023-6.el7.x86_64.rpm                                                   | 140 kB  00:00:00     
(4/9): perl-DBI-1.627-4.el7.x86_64.rpm                                                         | 802 kB  00:00:00     
(5/9): perl-Data-Dumper-2.145-3.el7.x86_64.rpm                                                 |  47 kB  00:00:00     
(6/9): perl-IO-Compress-2.061-2.el7.noarch.rpm                                                 | 260 kB  00:00:00     
(7/9): perl-Net-Daemon-0.48-5.el7.noarch.rpm                                                   |  51 kB  00:00:00     
(8/9): perl-PlRPC-0.2020-14.el7.noarch.rpm                                                     |  36 kB  00:00:00     
(9/9): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm                                          |  32 kB  00:00:05     
----------------------------------------------------------------------------------------------------------------------
总计                                                                                  2.2 MB/s |  13 MB  00:00:05     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction正在安装    : perl-Data-Dumper-2.145-3.el7.x86_64                                                               1/9 正在安装    : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                                                        2/9 正在安装    : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                                                       3/9 正在安装    : perl-IO-Compress-2.061-2.el7.noarch                                                               4/9 正在安装    : perl-Net-Daemon-0.48-5.el7.noarch                                                                 5/9 正在安装    : perl-PlRPC-0.2020-14.el7.noarch                                                                   6/9 正在安装    : perl-DBI-1.627-4.el7.x86_64                                                                       7/9 正在安装    : perl-DBD-MySQL-4.023-6.el7.x86_64                                                                 8/9 正在安装    : 1:mariadb-server-5.5.68-1.el7.x86_64                                                              9/9 验证中      : perl-Net-Daemon-0.48-5.el7.noarch                                                                 1/9 验证中      : perl-Data-Dumper-2.145-3.el7.x86_64                                                               2/9 验证中      : 1:mariadb-server-5.5.68-1.el7.x86_64                                                              3/9 验证中      : perl-DBD-MySQL-4.023-6.el7.x86_64                                                                 4/9 验证中      : perl-IO-Compress-2.061-2.el7.noarch                                                               5/9 验证中      : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                                                       6/9 验证中      : perl-DBI-1.627-4.el7.x86_64                                                                       7/9 验证中      : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                                                        8/9 验证中      : perl-PlRPC-0.2020-14.el7.noarch                                                                   9/9 已安装:mariadb-server.x86_64 1:5.5.68-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-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                        完毕!#启服
[root@server ~ 14:02:00]# systemctl enable mariadb --now
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.#安全初始化
[root@server ~ 14:02:28]# mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.Enter current password for root (enter for none): 
OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.Set root password? [Y/n] n... skipping.By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.Remove anonymous users? [Y/n] y... Success!Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] y... Success!By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.Remove test database and access to it? [Y/n] y- Dropping test database...... Success!- Removing privileges on test database...... Success!Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.Reload privilege tables now? [Y/n] y... Success!Cleaning up...All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.Thanks for using MariaDB!#mysql
[root@server ~ 14:03:30]# mysql -uroot 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.68-MariaDB MariaDB ServerCopyright (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 wordpress;
Query OK, 1 row affected (0.00 sec)#用户
MariaDB [(none)]> create user wordpress@'%' identified by '';
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> grant all privileges on wordpress.* to wordpress@'%';
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> quit
Bye

部署Nginx

[root@server ~ 14:11:19]# yum install -y nginx
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
软件包 1:nginx-1.20.1-10.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@server ~ 14:11:33]# systemctl enable nginx.service --now
[root@server ~ 14:11:53]# echo 'Hello World !' > /usr/share/nginx/html/index.html
[root@server ~ 14:12:28]# systemctl enable nginx --now

部署PHP服务

[root@server ~ 14:12:33]# yum install -y php php-mysqlnd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
软件包 php-5.4.16-48.el7.x86_64 已安装并且是最新版本
正在解决依赖关系
There are unfinished transactions remaining. You might consider running yum-complete-transaction, or "yum-complete-transaction --cleanup-only" and "yum history redo last", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help).
--> 正在检查事务
---> 软件包 php-mysqlnd.x86_64.0.5.4.16-48.el7 将被 安装
--> 正在处理依赖关系 php-pdo(x86-64) = 5.4.16-48.el7,它被软件包 php-mysqlnd-5.4.16-48.el7.x86_64 需要
--> 正在检查事务
---> 软件包 php-pdo.x86_64.0.5.4.16-48.el7 将被 安装
--> 解决依赖关系完成依赖关系解决======================================================================================================================Package                       架构                     版本                             源                      大小
======================================================================================================================
正在安装:php-mysqlnd                   x86_64                   5.4.16-48.el7                    base                   174 k
为依赖而安装:php-pdo                       x86_64                   5.4.16-48.el7                    base                    99 k事务概要
======================================================================================================================
安装  1 软件包 (+1 依赖软件包)总下载量:274 k
安装大小:654 k
Downloading packages:
(1/2): php-mysqlnd-5.4.16-48.el7.x86_64.rpm                                                    | 174 kB  00:00:00     
(2/2): php-pdo-5.4.16-48.el7.x86_64.rpm                                                        |  99 kB  00:00:01     
----------------------------------------------------------------------------------------------------------------------
总计                                                                                  191 kB/s | 274 kB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction正在安装    : php-pdo-5.4.16-48.el7.x86_64                                                                      1/2 正在安装    : php-mysqlnd-5.4.16-48.el7.x86_64                                                                  2/2 验证中      : php-pdo-5.4.16-48.el7.x86_64                                                                      1/2 验证中      : php-mysqlnd-5.4.16-48.el7.x86_64                                                                  2/2 已安装:php-mysqlnd.x86_64 0:5.4.16-48.el7                                                                                  作为依赖被安装:php-pdo.x86_64 0:5.4.16-48.el7                                                                                      完毕![root@server ~ 14:25:20]# yum install php-fpm -y
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
正在解决依赖关系
There are unfinished transactions remaining. You might consider running yum-complete-transaction, or "yum-complete-transaction --cleanup-only" and "yum history redo last", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help).
--> 正在检查事务
---> 软件包 php-fpm.x86_64.0.5.4.16-48.el7 将被 安装
--> 解决依赖关系完成依赖关系解决======================================================================================================================Package                    架构                      版本                              源                       大小
======================================================================================================================
正在安装:php-fpm                    x86_64                    5.4.16-48.el7                     base                    1.4 M事务概要
======================================================================================================================
安装  1 软件包总下载量:1.4 M
安装大小:4.5 M
Downloading packages:
php-fpm-5.4.16-48.el7.x86_64.rpm                                                               | 1.4 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction正在安装    : php-fpm-5.4.16-48.el7.x86_64                                                                      1/1 验证中      : php-fpm-5.4.16-48.el7.x86_64                                                                      1/1 已安装:php-fpm.x86_64 0:5.4.16-48.el7                                                                                      完毕!#启服
[root@server ~ 14:13:04]# systemctl start php-fpm
[root@server ~ 14:13:34]# systemctl enable php-fpm.service --now
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.

准备测试文件

[root@server ~ 14:26:00]# cat > index.php <<EOF
> <?php
>   echo "<h1>Hello World !</h1>\n";
> ?>
> EOF
[root@server ~ 14:26:44]# cat > test-mysql.php <<'EOF'
> <?php
>   $link=mysqli_connect('10.1.8.10','wordpress','');
>   if($link)
>     echo "<h1>Connect Mysql Success !</h1>\n";
>   else
>     echo "<h1>Connect Mysql Failed !</h1>\n";
>   $link->close();
> ?>
> EOF
[root@server ~ 14:27:02]# cat > info.php <<EOF
> <?php
>   phpinfo()
> ?>
> EOF
[root@server ~ 14:27:17]# cp *.php /usr/share/nginx/html

测试程序

[root@server ~ 14:30:14]# php -f index.php
<h1>Hello World !</h1>
[root@server ~ 14:46:44]# php -f test-mysql.php
<h1>Connect Mysql Success !</h1>
10.1.8.21 www.phoenix.cloud www
10.1.8.22 php.phoenix.cloud php
10.1.8.23 db.phoenix.cloud db
10.1.8.24 nfs.phoenix.cloud nfs
scp /etc/hosts www:/etc/hosts
scp /etc/hosts php:/etc/hosts
scp /etc/hosts db:/etc/hosts

ALL-IN-ONE

以部署 wordpress 应用为例。

实验环境

主机名IP 地址角色
server.phoenix1337.cloud10.1.8.10all

以部署 wordpress 应用为例 在/etc/hosts文件中解析 www.phoenix.cloud 10.1.8.10

部署Mariadb服务

[root@server ~ 22:37:57]# yum install -y mariadb-server
[root@server ~ 22:40:44]# systemctl enable mariadb --now#数据库
[root@server ~ 22:42:40]# mysql
mysql> CREATE DATABASE wordpress;
mysql> CREATE USER wordpress@'%' identified by '';
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO 'wp'@'%';
mysql> FLUSH PRIVILEGES;
mysql> exit

部署Nginx服务

[root@server ~ 22:42:40]# yum install -y nginx
[root@server ~ 22:44:52]# echo 'Hello World !' > /usr/share/nginx/html/index.html
[root@server ~ 22:45:01]# systemctl enable nginx --now

部署PHP服务

[root@server ~ 22:45:18]# yum install -y php php-fpm php-mysqlnd
[root@server ~ 22:45:45]# systemctl enable php-fpm.service --now
[root@server ~ 22:45:57]# systemctl restart httpd#index.php
[root@server ~ 22:46:21]# cat > index.php <<EOF
<?phpecho "<h1>Hello World !</h1>\n";
?>
EOF#test-mysql.php
[root@server ~ 22:46:38]# cat > test-mysql.php <<'EOF'
<?php$link=mysqli_connect('10.1.8.20','wp','Laoma@123');if($link)echo "<h1>Connect Mysql Success !</h1>\n";elseecho "<h1>Connect Mysql Failed !</h1>\n";$link->close();
?>
EOF#info.php
[root@server ~ 22:47:20]# cat > info.php <<EOF
<?phpphpinfo()
?>
EOF#两者都要 缺省文件导致403
[root@server ~ 22:47:45]# cp *.php /var/www/html
[root@server ~ 22:47:39]#  cp *.php /usr/share/nginx/html#测试
[root@server ~ 22:48:38]# php -f index.php
<h1>Hello World !</h1>
[root@server ~ 22:48:41]# php -f test-mysql.php
<h1>Connect Mysql Success !</h1>#浏览器测试php页面

部署wordpress应用

#解压到nginx
[root@server ~ 22:48:45]# unzip -o wordpress-4.9.4-zh_CN.zip -d /usr/share/nginx/html
#-R 递归
[root@server ~ 22:49:39]# chown -R nginx:nginx /usr/share/nginx/html/wordpress#php-fpm 进程默认以 apache 用户身份运行,修改运行用户为 nginx,并重启服务
[root@server ~ 22:50:02]# vim /etc/php-fpm.d/www.conf
user=nginx
group=nginx
[root@server ~ 22:50:24]# systemctl restart php-fpm#访问www.phoenix.cloud/wordpress

Nginx对接 PHP 配置

#nginx
#/etc/nginx/default.d/php.conf[root@server ~ 22:53:25]# egrep -v '^ *#|^$' /etc/nginx/default.d/php.conf
index index.php index.html index.htm;
location ~ \.(php|phar)(/.*)?$ {fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$;fastcgi_intercept_errors on;fastcgi_index  index.php;include        fastcgi_params;# 到虚拟主机主目录下查找对应php文件fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;fastcgi_param  PATH_INFO $fastcgi_path_info;# 转发到后端 php-fpmfastcgi_pass   php-fpm;
}#分流
#/etc/nginx/conf.d/php-fpm.conf
[root@server ~ 22:54:20]# cat /etc/nginx/conf.d/php-fpm.conf
upstream php-fpm {server unix:/run/php-fpm/www.sock;
}

测试页

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

Standalone

以部署 wordpress 应用为例 特别指出centos7取消了mysql支持,mariadb可以完美替代

实验环境

主机名IP 地址角色
www.phoenix.cloud10.1.8.21nginx
php.phoenix.cloud10.1.8.22php
db.phoenix.cloud10.1.8.23mariadb
nfs.phoenix.cloud10.1.8.24nfs
[root@www ~ 22:57:58]# vi /etc/hosts10.1.8.21 www.phoenix.cloud www
10.1.8.22 php.phoenix.cloud php
10.1.8.23 db.phoenix.cloud db
10.1.8.24 nfs.phoenix.cloud nfs#scp到其他主机 方便操作
[root@www ~ 23:02:04]# scp /etc/hosts php:/etc/hosts
[root@www ~ 23:02:07]# scp /etc/hosts db:/etc/hosts
[root@www ~ 23:02:08]# scp /etc/hosts nfs:/etc/hosts

部署 NFS 服务器

#建议mkdir后chomd -R 777验证 
[root@nfs ~ 23:05:56]# yum install -y nfs-utils
[root@nfs ~ 23:06:23]# mkdir -m 777 /www
[root@nfs ~ 23:07:14]# echo '/www 10.1.8.0/24(rw)' > /etc/exports
[root@nfs ~ 23:07:22]# systemctl enable nfs-server.service --now#解压
[root@nfs ~ 23:07:33]# unzip -o wordpress-4.9.4-zh_CN.zip -d /www/#准备测试文件
#index.php
[root@nfs ~ 23:07:54]# echo 'Hello World !' > /www/index.html
[root@nfs ~ 23:08:01]# cat > /www/index.php <<EOF
<?phpecho "<h1>Hello World !</h1>\n";
?>
EOF#test-mysql.php
[root@nfs ~ 23:08:30]# cat > /www/test-mysql.php <<'EOF'
<?php$link=mysqli_connect('db.phoenix.cloud','wordpress','');if($link)echo "<h1>Connect Mysql Success !</h1>\n";elseecho "<h1>Connect Mysql Failed !</h1>\n";$link->close();
?>
EOF#info.php
[root@nfs ~ 23:11:10]#  cat > /www/info.php <<EOF
<?phpphpinfo();
?>
EOF

部署 Mariadb 服务器

[root@nfs ~ 23:11:33]# ssh db
Last login: Mon Aug 11 17:49:52 2025 from 10.1.8.21
[root@db ~ 23:11:36]# yum install -y mariadb-server
[root@db ~ 23:12:12]# systemctl enable mariadb --now#数据库
[root@db ~ 23:12:31]# mysql
mysql> CREATE DATABASE wordpress;
mysql> CREATE USER wordpress@'%' identified by '';
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'%';
mysql> FLUSH PRIVILEGES;
mysql> exit

部署 Nginx 服务

[root@nfs ~ 23:13:11]# ssh www
Last login: Mon Aug 11 22:57:58 2025 from 10.1.8.1
[root@www ~ 23:13:14]# yum install -y nginx
[root@www ~ 23:13:40]# systemctl enable nginx --now#安装nfs工具
[root@www ~ 23:13:49]# yum install -y nfs-utils#挂载存储
[root@www ~ 23:14:18]#  echo 'nfs.phoenix.cloud:/www /usr/share/nginx/html nfs defaults 0 0' >> /etc/fstab
[root@www ~ 23:14:39]# systemctl daemon-reload 
[root@www ~ 23:14:45]# mount /usr/share/nginx/html/
[root@www ~ 23:14:53]# df -h /usr/share/nginx/html/
文件系统                容量  已用  可用 已用% 挂载点
nfs.phoenix.cloud:/www   47G  1.7G   46G    4% /usr/share/nginx/html

部署 PHP 服务器

[root@www ~ 23:15:04]# ssh php
Last login: Mon Aug 11 17:47:32 2025 from 10.1.8.21
[root@php ~ 23:15:31]# yum install -y php php-fpm php-mysqlnd
[root@php ~ 23:15:46]# vim /etc/php-fpm.d/www.conf#使用;号注释掉原有listen行
#新增listen 监听所有ip的9000端口
listen = 9000
# 支持监听特定ip的9000端口,格式10.1.8.22:9000# 使用;号注释掉原有 listen.allowed_clients 行
# 允许所有客户端访问
;listen.allowed_clients = 127.0.0.1[root@php ~ 23:16:38]# systemctl enable php-fpm.service --now

PHP测试

#挂载
[root@www ~ 23:17:13]# echo 'nfs.phoenix.cloud:/www /www nfs defaults 0 0' >> /etc/fstab 
[root@www ~ 23:17:56]# systemctl daemon-reload
[root@www ~ 23:18:03]# mkdir /www
[root@www ~ 23:18:14]# mount /www
[root@www ~ 23:18:21]# df -h /www
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   47G  1.6G   46G    4% /www#测试
[root@www ~ 23:18:36]# php -f index.php
<h1>Hello World !</h1>
[root@www ~ 23:20:06]# php -f test-mysql.php
<h1>Connect Mysql Success !</h1>

Nginx 对接 PHP

#在vhost文件中配置
#静态资源管理
#PHP请求
#监听端口
#php server中添加wordpress重定向
[root@www ~ 23:20:18]# cat > /etc/nginx/conf.d/vhost-www.conf <<'EOF'
server {listen 80;server_name www.laoma.cloud;location / {root /usr/share/nginx/html;index index.html index.htm index.php;}location ~ \.php$ {fastcgi_pass php.laoma.cloud:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name;include fastcgi_params;}
}
EOF
[root@www ~ 23:22:53]# systemctl restart nginx

PHP测试

#挂载
[root@www ~ 23:17:13]# echo 'nfs.phoenix.cloud:/www /www nfs defaults 0 0' >> /etc/fstab 
[root@www ~ 23:17:56]# systemctl daemon-reload
[root@www ~ 23:18:03]# mkdir /www
[root@www ~ 23:18:14]# mount /www
[root@www ~ 23:18:21]# df -h /www
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   47G  1.6G   46G    4% /www#测试
[root@www ~ 23:18:36]# php -f index.php
<h1>Hello World !</h1>
[root@www ~ 23:20:06]# php -f test-mysql.php
<h1>Connect Mysql Success !</h1>

Nginx 对接 PHP

#在vhost文件中配置
#静态资源管理
#PHP请求
#监听端口
#php server中添加wordpress重定向
[root@www ~ 23:20:18]# cat > /etc/nginx/conf.d/vhost-www.conf <<'EOF'
server {listen 80;server_name www.laoma.cloud;location / {root /usr/share/nginx/html;index index.html index.htm index.php;}location ~ \.php$ {fastcgi_pass php.laoma.cloud:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name;include fastcgi_params;}
}
EOF
[root@www ~ 23:22:53]# systemctl restart nginx

测试页

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

http://www.xdnf.cn/news/1280143.html

相关文章:

  • 用 Python 绘制企业年度财务可视化报告 —— 从 Excel 到 9 种图表全覆盖
  • 读《精益数据分析》:媒体内容平台全链路梳理
  • 低延迟RTSP|RTMP视频链路在AI驱动无人机与机器人操控中的架构实践与性能优化
  • TRS(总收益互换)系统架构设计:多市场交易的技术实现分析
  • 每日五个pyecharts可视化图表-line:从入门到精通 (3)
  • 常用设计模式系列(十九)- 状态模式
  • 闸机控制系统从设计到实现全解析:第 5 篇:RabbitMQ 消息队列与闸机通信设计
  • HBase BlockCache:LRU Cache
  • Agent用户体验设计:人机交互的最佳实践
  • redis(2)-java客户端使用(IDEA基于springboot)
  • 【图像处理基石】UE输出渲染视频,有哪些画质相关的维度和标准可以参考?
  • FlinkSql(详细讲解二)
  • IDE认知革命:JetBrains AI Assistant插件深度调教手册(终极实战指南)
  • 服务器配置实战:从 “密码锁” 到 “分工协作” 的知识点详解
  • POI导入时相关的EXCEL校验
  • Spring Boot Excel数据导入数据库实现详解
  • 缓存的三大问题分析与解决
  • Flink + Hologres构建实时数仓
  • MSE ZooKeeper:Flink高可用架构的企业级选择
  • 容器之王--Docker的安全优化详解及演练
  • 在Mac 上生成GitLab 的SSH 密钥并将其添加到GitLab
  • Django Request 与 DRF Request 的区别
  • (Arxiv-2025)Phantom:通过跨模态对齐实现主体一致性视频生成
  • 什么情况下会导致日本服务器变慢?解决办法
  • 第2节 大模型分布式推理架构设计原则
  • AIStarter修复macOS 15兼容问题:跨平台AI项目管理新体验
  • MySQL权限管理和MySQL备份
  • 大模型落地实践:从技术重构到行业变革的双重突破
  • C/C++练习面试题
  • Selenium动态元素定位