动静分离是什么

概念

动静分离,通过中间件将动态请求和静态请求进行分离;可以减少不必要的请求消耗,同时能减少请求的延时。
通过中间件将动态请求和静态请求分离,逻辑图如下:

动静分离从目前实现角度来讲大致分为两种。

第一种:纯粹把静态文件独立成单独的域名,放在独立的服务器上(主流推崇的方案);
第二种:动态跟静态文件混合在一起发布,通过 nginx 来分开。

为了加快网站的解析速度,我们可以把动态页面和静态页面交给不同的服务器来解析,来加快解析速度,提高请求的访问效率,降低原来单个服务器的压力。

主机名 IP 服务
nginx 192.168.230.132 nginx
agent 192.168.153.131 nginx
localhost 192.168.153.139 httpd

实例

准备工作
需要在lnmp架构下部署
#部署lnmp
#解压缩包及关闭防火墙
[root@localhost local]# ls
bin    include  libexec                         php-8.0.10.tar.xz  src
etc    lib      mysql-5.7.34-el7-x86_64.tar.gz  sbin
games  lib64    nginx-1.20.1.tar.gz             share
[root@localhost local]# tar xf nginx-1.20.1.tar.gz
[root@localhost local]# tar xf mysql-5.7.34-el7-x86_64.tar.gz
[root@localhost local]# tar xf php-8.0.10.tar.xz
[root@localhost local]# ls /usr/local/
bin      libexec                         php-8.0.10.tar.xz
etc      mysql-5.7.34-el7-x86_64         sbin
games    mysql-5.7.34-el7-x86_64.tar.gz  share
include  nginx-1.20.1                    src
lib      nginx-1.20.1.tar.gz
lib64    php-8.0.10
[root@localhost local]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost local]# vi /etc/selinux/config
[root@localhost local]# setenforce 0#nginx安装
#创建系统用户nginx
[root@localhost local]# useradd -r -M -s /sbin/nologin nginx
#安装依赖环境
[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ vim make
[root@localhost ~]# yum -y groups mark install 'Development Tools'
#创建日志存放目录
[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx/[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx/
[root@localhost ~]# cd /usr/local/nginx-1.20.1
[root@localhost nginx-1.20.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log[root@localhost nginx-1.20.1]# make && make install#配置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost ~]# . /etc/profile.d/nginx.sh
[root@localhost ~]# nginx#mysql安装
#创建MySQL用户及安装依赖包
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs
#创建软连接
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
bin      libexec                         php-8.0.10.tar.xz
etc      mysql-5.7.34-el7-x86_64         sbin
games    mysql-5.7.34-el7-x86_64.tar.gz  share
include  nginx-1.20.1                    src
lib      nginx-1.20.1.tar.gz
lib64    php-8.0.10
[root@localhost local]# ln -sv mysql-5.7.34-el7-x86_64 mysql
'mysql' -> 'mysql-5.7.34-el7-x86_64'
[root@localhost local]# ll
总用量 724288
drwxr-xr-x.  2 root root         6 5月  18 2020 bin
drwxr-xr-x.  2 root root         6 5月  18 2020 etc
drwxr-xr-x.  2 root root         6 5月  18 2020 games
drwxr-xr-x.  2 root root         6 5月  18 2020 include
drwxr-xr-x.  2 root root         6 5月  18 2020 lib
drwxr-xr-x.  3 root root        17 9月  30 12:29 lib64
drwxr-xr-x.  2 root root         6 5月  18 2020 libexec
lrwxrwxrwx.  1 root root        23 10月 26 07:21 mysql -> mysql-5.7.34-el7-x86_64#修改目录/usr/local/mysql的属主属组
[root@localhost local]# ll -d /usr/local/mysql
lrwxrwxrwx. 1 mysql mysql 23 10月 26 07:21 /usr/local/mysql -> mysql-5.7.34-el7-x86_64
#添加环境变量
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# . /etc/profile.d/mysql.sh
[root@localhost local]# cat /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost local]# echo $PATH
/usr/local/mysql/bin:/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
#创建数据存放目录
[root@localhost local]# mkdir /opt/data
[root@localhost local]# chown -R mysql.mysql /opt/data/
[root@localhost local]# ll -d /opt/data/
drwxr-xr-x. 2 mysql mysql 6 10月 26 07:24 /opt/data/
#初始化数据存放目录
[root@localhost ~]# cd /usr/local/mysql/bin
[root@localhost bin]# mysqld --initialize --user=mysql --datadir=/opt/data/
2021-10-26T11:26:27.165801Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-10-26T11:26:27.502560Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-10-26T11:26:27.543492Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-10-26T11:26:27.548773Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 8f42ef9f-364f-11ec-aa46-000c297af016.
2021-10-26T11:26:27.549855Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-10-26T11:26:27.997930Z 0 [Warning] CA certificate ca.pem is self signed.
2021-10-26T11:26:28.760242Z 1 [Note] A temporary password is generated for root@localhost: y*kZ*g3Fkx*m
#配置mysql及生成配置文件
[root@localhost bin]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
'/usr/local/include/mysql' -> '/usr/local/mysql/include/'
[root@localhost bin]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost bin]# ldconfig
#生成配置文件
[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve#配置服务启动脚本
[root@localhost ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld#开启mysql
[root@localhost ~]# ss -anlt
State    Recv-Q   Send-Q     Local Address:Port     Peer Address:Port   Process
LISTEN   0        128              0.0.0.0:22            0.0.0.0:*
LISTEN   0        128                 [::]:22               [::]:*
[root@localhost ~]# service mysqld start
Starting MySQL SUCCESS!
[root@localhost ~]# ss -anlt
State    Recv-Q   Send-Q     Local Address:Port     Peer Address:Port   Process
LISTEN   0        128              0.0.0.0:22            0.0.0.0:*
LISTEN   0        128                 [::]:22               [::]:*
LISTEN   0        80                     *:3306                *:*              #登录后设置密码
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.34Copyright (c) 2000, 2021, Oracle and/or its affiliates.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> set password = password('1');
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> quit
Bye#PHP安装过程
#下载依赖包
[root@localhost ~]# yum -y install sqlite-devel libzip-devel libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel
[root@localhost ~]# yum -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm#编译安装
[root@localhost]# cd /usr/local/php-8.0.10/
[root@localhost php-8.0.10]#  ./configure --prefix=/usr/local/php8  \--with-config-file-path=/etc \--enable-fpm \--disable-debug \--disable-rpath \--enable-shared \--enable-soap \--with-openssl \--enable-bcmath \--with-iconv \--with-bz2 \--enable-calendar \--with-curl \--enable-exif  \--enable-ftp \--enable-gd \--with-jpeg \--with-zlib-dir \--with-freetype \--with-gettext \--enable-mbstring \--enable-pdo \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \--with-readline \--enable-shmop \--enable-simplexml \--enable-sockets \--with-zip \--enable-mysqlnd-compression-support \--with-pear \--enable-pcntl \--enable-posixconfig.status: creating main/php_config.h
config.status: executing default commands+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+Thank you for using PHP.
#出现上面页面方为成功
[root@localhost php-8.0.10]# make && make install#安装成功后进行配置
[root@localhost php-8.0.10]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php.sh
[root@localhost php-8.0.10]# source /etc/profile.d/php.sh
[root@localhost php-8.0.10]# which php
/usr/local/php8/bin/php
[root@localhost php-8.0.10]# php -v
PHP 8.0.10 (cli) (built: Oct 26 2021 03:20:37) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.10, Copyright (c) Zend Technologies
#配置php-fpm
[root@localhost php-8.0.10]# cp -f /usr/local/php-8.0.10/php.ini-production /etc/php.ini
[root@localhost php-8.0.10]# cp /usr/local/php-8.0.10/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm -f
[root@localhost php-8.0.10]# chmod +x /etc/init.d/php-fpm
[root@localhost php-8.0.10]# cp -f /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
[root@localhost php-8.0.10]# cp -f /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf
#启动php
[root@localhost php-8.0.10]# service php-fpm start
Starting php-fpm  done
[root@localhost php-8.0.10]# ss -anlt
State    Recv-Q   Send-Q     Local Address:Port     Peer Address:Port   Process
LISTEN   0        128              0.0.0.0:22            0.0.0.0:*
LISTEN   0        128            127.0.0.1:9000          0.0.0.0:*
LISTEN   0        128                 [::]:22               [::]:*
LISTEN   0        80                     *:3306                *:*              #nginx配置过程[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf#access_log  logs/host.access.log  main;location / {root   html;index  index.php index.html index.htm;    # ##添加index.php}·····此处省略··········此处省略·····# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php$ {root           html;fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;include        fastcgi_params;}[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# echo "<?php phpinfo(); ?>" >> index.php
[root@localhost html]# cat index.php
<?php phpinfo(); ?>[root@localhost ~]# vim /usr/local/php8/etc/php-fpm.d/www.conf; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = nginx   ##改为nginx用户
group = nginx   ##改为nginx组#重启所有服务后进行测试
[root@localhost ~]# nginx -s stop
[root@localhost ~]# nginx
[root@localhost ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@localhost ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done
[root@localhost ~]# ss -anlt
State    Recv-Q   Send-Q     Local Address:Port     Peer Address:Port   Process
LISTEN   0        128              0.0.0.0:80            0.0.0.0:*
LISTEN   0        128              0.0.0.0:22            0.0.0.0:*
LISTEN   0        128            127.0.0.1:9000          0.0.0.0:*
LISTEN   0        128                 [::]:22               [::]:*
LISTEN   0        80                     *:3306                *:*                #每台主机开启服务,并关闭防火墙
[root@agent ~]# vi /etc/selinux/config
[root@agent ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@agent ~]# setenforce 0#nginx和agent主机安装nginx(步骤一致,所以我就写了一遍)
[root@agent ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
[root@agent ~]# yum -y groups mark install 'Development Tools'
#创建用户
[root@agent ~]# useradd -r -M -s /sbin/nologin nginx
[root@agent ~]# chown -R nginx.nginx /var/log/nginx
[root@agent local]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
[root@agent src]# ls
debug  kernels  nginx-1.12.0.tar.gz
[root@agent src]# tar xf nginx-1.12.0.tar.gz
[root@agent src]# cd nginx-1.12.0
[root@agent nginx-1.12.0]# ./configure \--prefix=/usr/local/nginx \--user=nginx \--group=nginx \--with-debug \--with-http_ssl_module \--with-http_realip_module \--with-http_image_filter_module \--with-http_gunzip_module \--with-http_gzip_static_module \--with-http_stub_status_module \--http-log-path=/var/log/nginx/access.log \--error-log-path=/var/log/nginx/error.log
[root@agent nginx-1.12.0]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
[root@agent nginx-1.12.0]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@agent nginx-1.12.0]# . /etc/profile.d/nginx.sh
[root@agent nginx-1.12.0]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@agent nginx-1.12.0]# nginx -v
nginx version: nginx/1.12.0
[root@agent nginx-1.12.0]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
[root@agent nginx-1.12.0]# nginx
[root@agent nginx-1.12.0]# ps -ef | grep nginx
root       75578       1  0 20:48 ?        00:00:00 nginx: master process nginx
nginx      75579   75578  0 20:48 ?        00:00:00 nginx: worker process
root       75619   38505  0 20:48 pts/0    00:00:00 grep --color=auto nginx
[root@agent nginx-1.12.0]# ss -anlt
State  Recv-Q Send-Q  Local Address:Port   Peer Address:Port Process
LISTEN 0      128           0.0.0.0:22          0.0.0.0:*
LISTEN 0      128           0.0.0.0:80          0.0.0.0:*
LISTEN 0      128              [::]:22             [::]:*            #安装httpd
[root@localhost src ~]# wget http://dlcdn.apache.org/httpd/httpd-2.4.49.tar.gz
--2021-09-24 11:50:58--  http://dlcdn.apache.org/httpd/httpd-2.4.49.tar.gz
正在解析主机 dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
正在连接 dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:9421895 (9.0M) [application/x-gzip]
正在保存至: “httpd-2.4.49.tar.gz”httpd-2.4.49.tar.gz  100%[=====================>]   8.99M  2.83MB/s  用时 3.2s    2021-09-24 11:51:01 (2.83 MB/s) - 已保存 “httpd-2.4.49.tar.gz” [9421895/9421895])[root@localhost src ~]# wget http://dlcdn.apache.org/apr/apr-1.7.0.tar.gz
--2021-09-24 11:51:21--  http://dlcdn.apache.org/apr/apr-1.7.0.tar.gz
正在解析主机 dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
正在连接 dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1093896 (1.0M) [application/x-gzip]
正在保存至: “apr-1.7.0.tar.gz”apr-1.7.0.tar.gz     100%[=====================>]   1.04M  2.03MB/s  用时 0.5s    2021-09-24 11:51:22 (2.03 MB/s) - 已保存 “apr-1.7.0.tar.gz” [1093896/1093896])[root@localhost src ~]# wget http://dlcdn.apache.org/apr/apr-util-1.6.1.tar.gz
--2021-09-24 11:51:31--  http://dlcdn.apache.org/apr/apr-util-1.6.1.tar.gz
正在解析主机 dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
正在连接 dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:554301 (541K) [application/x-gzip]
正在保存至: “apr-util-1.6.1.tar.gz”apr-util-1.6.1.tar.g 100%[=====================>] 541.31K  1.64MB/s  用时 0.3s    2021-09-24 11:51:32 (1.64 MB/s) - 已保存 “apr-util-1.6.1.tar.gz” [554301/554301])[root@localhost src ~]# tar xf apr-1.7.0.tar.gz
[root@localhost src ~]# tar xf apr-util-1.6.1.tar.gz
[root@localhost src ~]# tar xf httpd-2.4.49.tar.gz
[root@localhost src ~]# ls
公共  文档  anaconda-ks.cfg   apr-util-1.6.1.tar.gz  lamp
模板  下载  apr-1.7.0         httpd-2.4.49
视频  音乐  apr-1.7.0.tar.gz  httpd-2.4.49.tar.gz
图片  桌面  apr-util-1.6.1    initial-setup-ks.cfg#安装依赖包
[root@localhost src ~]# yum -y groups mark install 'Development Tools'
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:02:24 前,执行于 2021年09月24日 星期五 12时00分27秒。
依赖关系解决。
===================================================================================软件包             架构              版本                仓库                大小
===================================================================================
安装组:Development Tools                                                                事务概要
===================================================================================完毕![root@localhost src ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:03:18 前,执行于 2021年09月24日 星期五 12时00分27秒。
依赖关系解决。
===================================================================================软件包                   架构        版本                    仓库            大小
===================================================================================
安装:expat-devel              x86_64      2.2.5-3.el8             BaseOS          55 kgcc                      x86_64      8.3.1-5.el8             Appstream       23 Mgcc-c++                  x86_64      8.3.1-5.el8             Appstream       12 Mlibtool                  x86_64      2.4.6-25.el8            Appstream      709 kmake                     x86_64      1:4.2.1-10.el8          BaseOS         498 kopenssl-devel            x86_64      1:1.1.1c-15.el8         BaseOS         2.3 Mpcre-devel               x86_64      8.42-4.el8              BaseOS         551 k
安装依赖关系:
···[root@localhost src ~]# cd apr-1.7.0/
[root@localhost apr-1.7.0]# vim configurecfgfile=${ofile}Ttrap "$RM \"$cfgfile\"; exit 1" 1 2 15# $RM "$cfgfile"    #注释掉#编译安装
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
Configuring APR library
Platform: x86_64-pc-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.7.0
checking for chosen layout... apr
checking for gcc... gcc
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 gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed[root@localhost apr-1.7.0]# make && make install
···
/usr/bin/install -c -m 755 /root/apr-1.7.0/build/mkdir.sh /usr/local/apr/build-1
for f in make_exports.awk make_var_export.awk; do \/usr/bin/install -c -m 644 /root/apr-1.7.0/build/${f} /usr/local/apr/build-1; \
done
/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config
#进行编译
[root@localhost ~]# cd /usr/src/apr-util-1.6.1/
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking for working mkdir -p... yes
APR-util Version: 1.6.1
checking for chosen layout... apr-util
checking for gcc... gcc[root@localhost apr-util-1.6.1]# make && make install
···- have your system administrator add LIBDIR to '/etc/ld.so.conf'See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config[root@localhost apr-util-1.6.1]# cd /usr/src/httpd-2.4.49/
[root@localhost httpd-2.4.49]# ./configure --prefix=/usr/local/apache \
> --enable-so \
> --enable-ssl \
> --enable-cgi \
> --enable-rewrite \
> --with-zlib \
> --with-pcre \
>  --with-apr=/usr/local/apr \
> --with-apr-util=/usr/local/apr-util/ \
> --enable-modules=most \
> --enable-mpms-shared=all \
> --with-mpm=prefork
checking for chosen layout... Apache
checking for working mkdir -p... yes
···
configure: summary of build options:Server Version: 2.4.49Install prefix: /usr/local/apacheC compiler:     gccCFLAGS:          -g -O2 -pthread  CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  LDFLAGS:           LIBS:             C preprocessor: gcc -E[root@localhost httpd-2.4.49]# make && make install
···
Installing build system files
mkdir /usr/local/apache/build
Installing man pages and online manual
mkdir /usr/local/apache/man
mkdir /usr/local/apache/man/man1
mkdir /usr/local/apache/man/man8
mkdir /usr/local/apache/manual
make[1]: 离开目录“/usr/src/httpd-2.4.49”[root@localhost httpd-2.4.49]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man#去掉注释
[root@localhost httpd-2.4.49]# vim /usr/local/apache/conf/httpd.conf ServerName www.example.com:80#启动apache查看是否开启
[root@localhost httpd-2.4.49]# apachectl start
[root@localhost httpd-2.4.49]# ss -anlt
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port
LISTEN    0         32             192.168.122.1:53                0.0.0.0:*
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*
LISTEN    0         5                  127.0.0.1:631               0.0.0.0:*
LISTEN    0         128                  0.0.0.0:111               0.0.0.0:*
LISTEN    0         128                     [::]:22                   [::]:*
LISTEN    0         5                      [::1]:631                  [::]:*
LISTEN    0         128                     [::]:111                  [::]:*
LISTEN    0         128                        *:80                      *:*   [root@localhost ~]# vim /usr/lib/systemd/system/httpd.service
[root@localhost ~]# cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=Httpd server daemon
Documentation=man:httpd(8)
After=network.target[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP $MAINPID[Install]
WantedBy=multi-user.target[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl status httpd.service
● httpd.service - Httpd server daemonLoaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset:>Active: inactive (dead)Docs: man:httpd(8)9月 24 12:32:30 localhost.localdomain systemd[1]: /usr/lib/systemd/system/httpd.se>
9月 24 12:32:30 localhost.localdomain systemd[1]: /usr/lib/systemd/system/httpd.se>
9月 24 12:32:30 localhost.localdomain systemd[1]: /usr/lib/systemd/system/httpd.se>
9月 24 12:32:30 localhost.localdomain systemd[1]: /usr/lib/systemd/system/httpd.se>
9月 24 12:32:30 localhost.localdomain systemd[1]: /usr/lib/systemd/system/httpd.se>
9月 24 12:33:33 localhost.localdomain systemd[1]: /usr/lib/systemd/system/httpd.se>
lines 1-11/11 (END)
[root@localhost ~]# apachectl stop
[root@localhost ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl status httpd.service
● httpd.service - Httpd server daemonLoaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: >Active: active (running) since Fri 2021-09-24 12:36:03 CST; 8s agoDocs: man:httpd(8)Process: 151521 ExecStart=/usr/local/apache/bin/apachectl start (code=exited, st>Main PID: 151524 (httpd)Tasks: 6 (limit: 4704)Memory: 8.5MCGroup: /system.slice/httpd.service├─151524 /usr/local/apache/bin/httpd -k start├─151525 /usr/local/apache/bin/httpd -k start├─151526 /usr/local/apache/bin/httpd -k start├─151527 /usr/local/apache/bin/httpd -k start├─151528 /usr/local/apache/bin/httpd -k start└─151529 /usr/local/apache/bin/httpd -k start开启服务
[root@httpd ~]# systemctl start httpd
[root@httpd ~]# ss -anlt
State  Recv-Q Send-Q  Local Address:Port   Peer Address:Port Process
LISTEN 0      128           0.0.0.0:22          0.0.0.0:*
LISTEN 0      128                 *:80                *:*
LISTEN 0      128              [::]:22             [::]:*            [root@lnmp ~]# nginx
[root@lnmp ~]# systemctl start php-fpm.service
[root@lnmp ~]# systemctl start mysqld.service
[root@lnmp ~]# ss -anlt
State  Recv-Q Send-Q  Local Address:Port   Peer Address:Port Process
LISTEN 0      128         127.0.0.1:9000        0.0.0.0:*
LISTEN 0      128           0.0.0.0:80          0.0.0.0:*
LISTEN 0      128           0.0.0.0:22          0.0.0.0:*
LISTEN 0      80                  *:3306              *:*
LISTEN 0      128              [::]:22             [::]:*            [root@agent ~]# nginx
[root@agent ~]# ss -anlt
State  Recv-Q Send-Q  Local Address:Port   Peer Address:Port Process
LISTEN 0      128           0.0.0.0:22          0.0.0.0:*
LISTEN 0      128           0.0.0.0:80          0.0.0.0:*
LISTEN 0      128              [::]:22             [::]:*            #修改agent主机配置文件
[root@agent ~]# vim /usr/local/nginx/conf/nginx.conf
......#gzip  on;upstream static {                   server 192.168.230.139;}upstream dynamic {             server 192.168.230.132;       }server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {proxy_pass http://test;       #访问静态资源会自动跳转到进行访问}#error_page  404              /404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80location ~ \.php$ {                            #取消注释proxy_pass   http://dynamic;               #访问动态资源会自动跳转到进行访问}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000......
[root@agent ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@agent ~]# nginx -s reload

使用agent主机IP地址访问测试
访问静态资源

nginx—动静分离相关推荐

  1. Nginx系列二:(Nginx Rewrite 规则、Nginx 防盗链、Nginx 动静分离、Nginx+keepalived 实现高可用)...

    一.Nginx Rewrite 规则 1. Nginx rewrite规则 Rewrite规则含义就是某个URL重写成特定的URL(类似于Redirect),从某种意义上说为了美观或者对搜索引擎友好, ...

  2. Nginx动静分离实现负载均衡

    转载自   Nginx动静分离实现负载均衡 前期准备 使用Debian环境.安装Nginx(默认安装),一个web项目,安装tomcat(默认安装)等. Nginx.conf配置 1 # 定义Ngin ...

  3. nginx动静分离配置_Nginx 动静分离与负载均衡的实现

    一.前提 企业中,随着用户的增长,数据量也几乎成几何增长,数据越来越大,随之也就出现了各种应用的瓶颈问题. 问题出现了,我们就得想办法解决,一般网站环境,均会使用LAMP或者LNMP,而我们对于网站环 ...

  4. keepalive高可用nginx(nginx动静分离)的实现

    HA Cluster的配置前提: 1.各节点时间要同步:2.确保iptables及selinux不会成为障碍:3.(可选)各节点之间可通过主机名互相通信:节点的名称设定与hosts文件中解析的主机名都 ...

  5. 【nginx】nginx 动静分离

    1.概述 Nginx动静分离简单来说就是把动态跟静态请求分开,不能理解成只是单纯的把动态页面和静态页面物理分离.严格意义上说应该是动态请求跟静态请求分开,可以理解成使用Nginx,处理静态页面,Tom ...

  6. nginx动静分离配置_Nginx动静分离配置实例

    点击▲关注 "长安大司马"   给公众号标星置顶 更多精彩 第一时间直达 父亲节快乐 HAPPY FATHER'S DAY 1 .什么是动静分离 Nginx 动静分离简单来说就是把 ...

  7. Nginx 动静分离 -02

    Nginx 动静分离 ---- --------切记 10.10.0.7 一.单台机器动静分离 [root@web01 ~]# cat /etc/nginx/conf.d/linux12.wp.com ...

  8. nginx动静分离和资源隔离的网站搭建

    | 作业 nginx动静分离和资源隔离的网站搭建 一.动静分离的网站 0.准备环境 主机 IP 主机角色 条件 web01 192.168.15.7 Android页面 关闭防火墙和selinux w ...

  9. Nginx动静分离配置

    Nginx动静分离 一.动静分离介绍 动静分离,通过中间件将动态请求和静态请求进行分离 通过中间件将动态请求和静态请求分离,可以减少不必要的请求消耗,同时能减少请求的延时. 通过中间件将动态请求和静态 ...

  10. 谷粒商城项目篇8_分布式高级篇_商城首页、性能压测、优化(Nginx动静分离)

    目录 商城首页 整合thymeleaf springmvc的WebMvcAutoConfiguration 首页三级分类渲染 Nginx代理 Nginx代理会丢掉host信息 压力测试 性能检测 性能 ...

最新文章

  1. PHP SPL使用方法和他的威力
  2. 当javaScript从入门到提高前需要注意的细节:变量部分
  3. 二进制搜索算法_二进制搜索的一个扭曲故事
  4. java response 状态码_response(向客户端写入数据、对相应进行设置(状态码、响应头))...
  5. 另存为里面没有jpg_CAD图不会转JPG?教你两个方法,从此CAD格式转换不再烦恼
  6. 小白设计模式:责任链模式
  7. requesbodys.java_这个requestBody的正确swagger-annotation是什么?
  8. C++11 range-based for loop
  9. 利润表模板excel_Excel教程:作为财务,这些excel技巧你还不会吗?
  10. matlab单回路控制系统设计,实验二单回路控制系统的建模与仿真 .doc
  11. cron在线生成表达式
  12. jason表情包在线生成源码
  13. 大学计算机应用教程马秀麟,大学计算机基础电子教案.docx
  14. macos 下 vmware fusion 安装 vmware tools
  15. win10装机之天涯若比邻长时间卡死
  16. 企业信用等级重不重要?看看各地招标文件就知道了。
  17. PHP编写poc,代码实战/萌新如何编写sql注入的poc
  18. QIIME 2教程. 05粪菌移植分析练习Fecal microbiota transplant(2021.2)
  19. Ubuntu挂载iso文件和配置apt本地源
  20. CSGO手套武器箱直接卖还是开了再卖?

热门文章

  1. 11 wifi6速率_WiFi 6是什么?现在是更换WiFi 6路由器的时候吗?
  2. 虚拟机安装kali linux
  3. 关闭compactos_windows 10 CompactOS最节省空间的安装系统
  4. 巨大数的运算 (前篇 ——对于整数) # 万进制 # —————— 开开开山怪
  5. GPON(计算机网络相关)
  6. 开源护眼工具LightBulb2.3.3汉化说明
  7. BUUCTF [0CTF 2016] piapiapia
  8. 股票学习-量柱和k线-第二天
  9. 交换字符使得字符串相同
  10. 一个简单的sql查询脚本