Lamp架构搭建以及docker

Lamp架构搭建以及docker


文章目录

  • Lamp架构搭建以及docker
    • 1. web工作流程
    • 2. lamp平台构建
      • 2.1 安装httpd
      • 2.2 安装mysql
      • 2.3 安装php
      • 2.4 配置apache
        • 2.4.1 启用代理模块
        • 2.4.2 配置虚拟主机
      • 2.5 验证
  • docker容器技术基础入门
    • 容器(Container)
    • 传统虚拟化与容器的区别

1. web工作流程

通过上面的图说明一下web的工作流程:

  • 客户端通过http协议请求web服务器资源
  • web服务器收到请求后判断客户端请求的资源是静态资源或是动态资源
    • 若是静态资源则直接从本地文件系统取之返回给客户端。
    • 否则若为动态资源则通过FastCGI协议与php服务器联系,通过CGI程序的master进程调度worker进程来执行程序以获得客户端请求的动态资源,并将执行的结果通过FastCGI协议返回给httpd服务器,httpd服务器收到php的执行结果后将其封装为http响应报文响应给客户端。在执行程序获取动态资源时若需要获得数据库中的资源时,由Php服务器通过mysql协议与MySQL/MariaDB服务器交互,取之而后返回给httpd,httpd将从php服务器收到的执行结果封装成http响应报文响应给客户端。

2. lamp平台构建

环境说明:

系统平台 IP 需要安装的服务
centos7
redhat7
172.16.12.128 httpd-2.4
mysql-5.7
php
php-mysql

lamp平台软件安装次序:

httpd --> mysql --> php

注意:php要求httpd使用prefork MPM

2.1 安装httpd

//配置阿里云网络仓库

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Stream-AppStream.repo  CentOS-Stream-Debuginfo.repo  CentOS-Stream-HighAvailability.repo  CentOS-Stream-PowerTools.repo
CentOS-Stream-BaseOS.repo     CentOS-Stream-Extras.repo     CentOS-Stream-Media.repo             CentOS-Stream-RealTime.repo
[root@localhost yum.repos.d]# rm -rf *
[root@localhost yum.repos.d]# ls
[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0   7295      0 --:--:-- --:--:-- --:--:--  7295
[root@localhost yum.repos.d]# ls
CentOS-Base.repo
[root@localhost yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost yum.repos.d]# cd
[root@localhost ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
CentOS-8.5.2111 - Base - mirrors.aliyun.com                                                                                                             497 kB/s | 4.6 MB     00:09    
CentOS-8.5.2111 - Extras - mirrors.aliyun.com                                                                                                            27 kB/s |  10 kB     00:00    
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com                                                                                                        333 kB/s | 8.4 MB     00:25    
epel-release-latest-8.noarch.rpm                                                                                                                         57 kB/s |  24 kB     00:00    
Dependencies resolved.
......
Complete!
[root@localhost ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  epel-modular.repo  epel.repo  epel-testing-modular.repo  epel-testing.repo

//安装开发工具包

[root@localhost yum.repos.d]# cd
[root@localhost ~]# yum groups mark install 'Development Tools'
......
Complete!

//创建apache服务的用户和组

[root@localhost ~]# useradd -r -M -s /sbin/nologin  apache
[root@localhost ~]# id apache
uid=994(apache) gid=991(apache) groups=991(apache) 

//安装依赖包

[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
Last metadata expiration check: 0:07:03 ago on Tue 02 Aug 2022 04:34:46 PM CST.
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
......
Complete!

//下载和安装apr和apr-util以及httpd

[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://downloads.apache.org/apr/apr-1.6.5.tar.bz2

[root@localhost src]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.bz2

[root@localhost src]# wget https://downloads.apache.org/httpd/httpd-2.4.54.tar.bz2

[root@localhost src]# ls
apr-1.6.5.tar.bz2  apr-util-1.6.1.tar.bz2  debug  httpd-2.4.54.tar.bz2  kernels
[root@localhost src]# dnf install bzip2
......
Complete!
[root@localhost src]# tar xf apr-1.6.5.tar.bz2
[root@localhost src]# ls
apr-1.6.5  apr-1.6.5.tar.bz2  apr-util-1.6.1.tar.bz2  debug  httpd-2.4.54.tar.bz2  kernels
[root@localhost src]# cd apr-1.6.5
[root@localhost apr-1.6.5]# vim configure
    cfgfile="${ofile}T"
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    # $RM "$cfgfile"        //将此行加上注释,或者删除此行

[root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr
配置过程略...
[root@localhost apr-1.6.5]# make && make install
编译安装过程略...

[root@localhost apr-1.6.5]# cd ..
[root@localhost src]# tar xf apr-util-1.6.1.tar.bz2
[root@localhost src]# ls
apr-1.6.5  apr-1.6.5.tar.bz2  apr-util-1.6.1  apr-util-1.6.1.tar.bz2  debug  httpd-2.4.54.tar.bz2  kernels
[root@localhost src]# cd apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
配置过程略...
[root@localhost apr-util-1.6.1]# make && make install
编译安装过程略...
[root@localhost apr-util-1.6.1]# cd
[root@localhost ~]# ls /usr/local/
apr  apr-util  bin  etc  games  include  lib  lib64  libexec  sbin  share  src

//编译安装httpd

[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
apr-1.6.5  apr-1.6.5.tar.bz2  apr-util-1.6.1  apr-util-1.6.1.tar.bz2  debug  httpd-2.4.54.tar.bz2  kernels
[root@localhost src]# tar xf httpd-2.4.54.tar.bz2
[root@localhost src]# ls
apr-1.6.5  apr-1.6.5.tar.bz2  apr-util-1.6.1  apr-util-1.6.1.tar.bz2  debug  httpd-2.4.54  httpd-2.4.54.tar.bz2  kernels
[root@localhost src]# cd httpd-2.4.54
[root@localhost src]# ./configure --prefix=/usr/local/apache \
--sysconfdir=/etc/httpd24 \
--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

[root@localhost httpd-2.4.38]# make && make install
编译安装过程略...

//安装后配置

[root@localhost httpd-2.4.54]# cd /usr/local/
[root@localhost local]# ls
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  sbin  share  src
[root@localhost local]# cd apache
[root@localhost apache]# ls
bin  build  cgi-bin  error  htdocs  icons  include  logs  man  manual  modules
[root@localhost apache]# echo 'export PATH=$PATH:/usr/local/apache/bin' > /etc/profile.d/httpd.sh
[root@localhost apache]# source /etc/profile.d/httpd.sh
[root@localhost apache]# which apachectl
/usr/local/apache/bin/apachectl
[root@localhost apache]# ln -s /usr/local/apache/include/  /usr/include/httpd
[root@localhost apache]# 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 apache]# cd
[root@localhost ~]# httpd -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
Syntax OK
[root@localhost ~]# vim /etc/httpd24/httpd.conf
......
 #ServerName www.example.com:80         //将这行注释掉
[root@localhost ~]# httpd -t
Syntax OK

//启动apache

[root@localhost ~]# which apachectl
/usr/local/apache/bin/apachectl
[root@localhost ~]# cd /usr/lib/systemd/system/
[root@localhost system]# cp sshd.service httpd.service
[root@localhost system]# vim httpd.service
[Unit]
Description=httpd server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl  start
ExecStop=/usr/local/apache/bin/apachectl  stop
ExecReload=/bin/kill -HUP $MAINPID

[root@localhost system]# systemctl daemon-reload
[root@localhost system]# 
[root@localhost system]# cd
[root@localhost ~]# systemctl status httpd
● httpd.service - httpd server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# ss -antl
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@localhost ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim /etc/selinux/config
 # This file controls the state of SELinux on the system.
 # SELINUX= can take one of these three values:
 #     enforcing - SELinux security policy is enforced.
 #     permissive - SELinux prints warnings instead of enforcing.
 #     disabled - No SELinux policy is loaded.
 SELINUX=disabled
[root@localhost ~]# setenforce 0

Lamp架构搭建以及docker_第1张图片

2.2 安装mysql

//安装依赖包

[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake 
......
Complete!

//创建用户和组

[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
[root@localhost ~]# id mysql
uid=993(mysql) gid=990(mysql) groups=990(mysql)

//下载二进制格式的mysql软件包

[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
--2022-08-02 21:38:15--  https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
Resolving downloads.mysql.com (downloads.mysql.com)... 104.102.102.89, 2600:1406:1400:691::2e31, 2600:1406:1400:68d::2e31
Connecting to downloads.mysql.com (downloads.mysql.com)|104.102.102.89|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz [following]
--2022-08-02 21:38:16--  https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
Resolving cdn.mysql.com (cdn.mysql.com)... 23.2.84.230
Connecting to cdn.mysql.com (cdn.mysql.com)|23.2.84.230|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 674830866 (644M) [application/x-tar-gz]
Saving to: ‘mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz’

mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz    100%[=================================================================================================>] 643.57M  1.14MB/s    in 10m 28s 

2022-08-02 21:48:46 (1.02 MB/s) - ‘mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz’ saved [674830866/674830866]

//解压软件至/usr/local/

[root@localhost src]# ls
apr-1.6.5  apr-1.6.5.tar.bz2  apr-util-1.6.1  apr-util-1.6.1.tar.bz2  debug  httpd-2.4.54  httpd-2.4.54.tar.bz2  kernels  mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz  -C /usr/local/
[root@localhost src]# cd /usr/local/
[root@localhost local]# ls
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  mysql-5.7.38-linux-glibc2.12-x86_64  sbin  share  src
[root@localhost local]# ln -s mysql-5.7.38-linux-glibc2.12-x86_64 mysql
[root@localhost local]# chown -R mysql.mysql mysql*
[root@localhost local]# ll
total 0
drwxr-xr-x. 13 root  root  152 Aug  2 18:44 apache
drwxr-xr-x.  6 root  root   58 Aug  2 18:25 apr
drwxr-xr-x.  5 root  root   43 Aug  2 18:29 apr-util
drwxr-xr-x.  2 root  root    6 May 19  2020 bin
drwxr-xr-x.  2 root  root    6 May 19  2020 etc
drwxr-xr-x.  2 root  root    6 May 19  2020 games
drwxr-xr-x.  2 root  root    6 May 19  2020 include
drwxr-xr-x.  2 root  root    6 May 19  2020 lib
drwxr-xr-x.  3 root  root   17 Jun 27 15:02 lib64
drwxr-xr-x.  2 root  root    6 May 19  2020 libexec
lrwxrwxrwx.  1 mysql mysql  35 Aug  2 21:57 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x.  9 mysql mysql 129 Aug  2 21:52 mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x.  2 root  root    6 May 19  2020 sbin
drwxr-xr-x.  5 root  root   49 Jun 27 15:02 share
drwxr-xr-x.  2 root  root    6 May 19  2020 src

//添加环境变量

[root@localhost local]# ls
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  mysql  mysql-5.7.38-linux-glibc2.12-x86_64  sbin  share  src
[root@localhost local]# cd mysql
[root@localhost mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost mysql]# cd bin/
[root@localhost bin]# pwd
/usr/local/mysql/bin
[root@localhost bin]# echo 'export PATH=$PATH:/usr/local/mysql/bin' >  /etc/profile.d/mysql.sh
[root@localhost bin]# source /etc/profile.d/mysql.sh
[root@localhost bin]# which mysql
/usr/local/mysql/bin/mysql
[root@localhost bin]# cd ..
[root@localhost mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost mysql]# ln -s /usr/local/mysql/include/  /usr/include/mysql
[root@localhost mysql]# echo '/usr/local/mysql/lib/' > /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql]# ldconfig
[root@localhost mysql]# vim /etc/man_db.conf
......
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man
MANDATORY_MANPATH                       /usr/local/mysql/man   //添加此行

//建立数据存放目录

[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data/

//初始化数据库

[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/ 
2022-08-02T14:26:22.422615Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-08-02T14:26:22.946887Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-08-02T14:26:23.021036Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-08-02T14:26:23.085041Z 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: 159109a6-126f-11ed-a8d4-000c29343c77.
2022-08-02T14:26:23.087259Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-08-02T14:26:23.780512Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T14:26:23.780541Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-08-02T14:26:23.781745Z 0 [Warning] CA certificate ca.pem is self signed.
2022-08-02T14:26:23.823427Z 1 [Note] A temporary password is generated for root@localhost: ue5IueBar)t2
[root@localhost ~]# echo 'ue5IueBar)t2'  > pass
[root@localhost ~]# cat pass
ue5IueBar)t2

//请注意,这个命令的最后会生成一个临时密码,此处密码是ue5IueBar)t2
//再次注意,这个密码是随机的,你的不会跟我一样,一定要记住这个密码,因为一会登录时会用到

//生成配置文件

[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 ~]# ls
anaconda-ks.cfg   pass
[root@localhost ~]# cd /usr/local/mysql/support-files/
[root@localhost support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@localhost support-files]# file mysql.server
mysql.server: POSIX shell script, ASCII text executable
[root@localhost support-files]# cd
[root@localhost ~]# cp -a /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
[root@localhost ~]# vim /etc/init.d/mysqld
......
basedir=/usr/local/mysql/
datadir=/opt/data/

//启动mysql

[root@localhost ~]# cd /usr/lib/systemd/system
[root@localhost system]# cp sshd.service  mysql.service
[root@localhost system]# vim mysqld.service
[root@localhost system]# cat mysqld.service
[Unit]
Description=mysqld server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/etc/init.d/mysqld start
ExecStop=/etc/init.d/mysqld stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl stop firewalld
[root@localhost system]# setenforce 0
[root@localhost system]# systemctl start mysqld
[root@localhost system]# systemctl enable mysqld.service
Synchronizing state of mysqld.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@localhost system]# ss -antl
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         80                       *:3306                    *:*                  
LISTEN    0         128                      *:80                      *:*                  
LISTEN    0         128                   [::]:22                   [::]:*                  

//修改密码
//使用临时密码登录

[root@localhost system]# cd
[root@localhost ~]# dnf whatprovides libncurses.so.5
Last metadata expiration check: 6:50:45 ago on Tue 02 Aug 2022 04:34:46 PM CST.
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
Repo        : base
Matched from:
Provide    : libncurses.so.5

[root@localhost ~]# dnf install -y ncurses-compat-libs
......
Complete!
[root@localhost ~]# mysql -uroot -p'ue5IueBar)t2'
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 2
Server version: 5.7.38

Copyright (c) 2000, 2022, 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('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye
[root@localhost ~]# mysql -uroot -p123456
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 3
Server version: 5.7.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, 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> 

2.3 安装php

//安装依赖包

[root@localhost ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel libzip-devel openldap-devel  pcre-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel sqlite-devel php-mysqlnd

[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

//下载php

[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://www.php.net/distributions/php-7.4.30.tar.xz
--2022-08-02 23:49:41--  https://www.php.net/distributions/php-7.4.30.tar.xz
Resolving www.php.net (www.php.net)... 185.85.0.29, 2a02:cb40:200::1ad
Connecting to www.php.net (www.php.net)|185.85.0.29|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10419136 (9.9M) [application/octet-stream]
Saving to: ‘php-7.4.30.tar.xz’

2022-08-02 23:58:39 (12.9 KB/s) - ‘php-7.4.30.tar.xz’ saved [10419136/10419136]

//编译安装php

[root@localhost src]# ls
apr-1.6.5          apr-util-1.6.1.tar.bz2  httpd-2.4.54.tar.bz2                        php-7.4.30.tar.xz
apr-1.6.5.tar.bz2  debug                   kernels
apr-util-1.6.1     httpd-2.4.54            mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# tar xf php-7.4.30.tar.xz
[root@localhost src]# cd php-7.4.30
[root@localhost php-7.4.30]# ./configure --prefix=/usr/local/php7  \
> --with-config-file-path=/etc \
> --enable-fpm \
> --enable-inline-optimization \
> --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-json \
> --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-posix
......
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:

Package 'sqlite3', required by 'virtual:world', not found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables SQLITE_CFLAGS
and SQLITE_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.   //此时报错,提示缺少sqlite3的依赖包,需要手动下载

[root@localhost php-7.4.30]# yum -y install soci-sqlite3* 
Last metadata expiration check: 7:43:37 ago on Tue 02 Aug 2022 04:34:46 PM CST.
.....
Complete!    //下载完成继续编译
[root@localhost php-7.4.30]# ./configure --prefix=/usr/local/php7  --with-config-file-path=/etc --enable-fpm --enable-inline-optimization --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-json --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-posix
......
configure: error: Package requirements (oniguruma) were not met:

Package 'oniguruma', required by 'virtual:world', not found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables ONIG_CFLAGS
and ONIG_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.    //报错缺少oniguruma,需要自己查找并下载

[root@localhost php-7.4.30]#  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  
......
Complete!         //继续编译
[root@localhost php-7.4.30]# ./configure --prefix=/usr/local/php7  --with-config-file-path=/etc --enable-fpm --enable-inline-optimization --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-json --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-posix         
.......
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:

Package 'libzip', required by 'virtual:world', not found
Package 'libzip', required by 'virtual:world', not found
Package 'libzip', required by 'virtual:world', not found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBZIP_CFLAGS
and LIBZIP_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.       //报错缺少libzip,需要手动下载,然后编译安装

[root@localhost php-7.4.30]# yum -y install libzip-devel
......
Complete!
[root@localhost php-7.4.30]# ./configure --prefix=/usr/local/php7  --with-config-file-path=/etc --enable-fpm --enable-inline-optimization --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-json --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-posix 
......
Thank you for using PHP.
[root@localhost php-7.4.30]# make && make install
安装过程略

//安装后配置

[root@localhost php-7.4.30]# cd /usr/local/php7/
[root@localhost php7]# ls
bin  etc  include  lib  php  sbin  var
[root@localhost php7]# echo 'export PATH=$PATH:/usr/local/php7/bin' > /etc/profile.d/php7.sh
[root@localhost php7]# source /etc/profile.d/php7.sh
[root@localhost php7]# ln -s /usr/local/php7/include/ /usr/include/php7
[root@localhost php7]# echo '/usr/local/php7/lib/' > /etc/ld.so.conf.d/php7.conf
[root@localhost php7]# ldconfig

//配置php-fpm

[root@localhost php7]# cd /usr/src/php-7.4.30
[root@localhost php-7.4.30]# cp php.ini-production /etc/php.ini
cp: overwrite '/etc/php.ini'? y
[root@localhost php-7.4.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.4.30]# ll -d /etc/init.d/php-fpm
-rw-r--r--. 1 root root 2402 Aug  4 18:32 /etc/init.d/php-fpm
[root@localhost php-7.4.30]# chmod +x /etc/init.d/php-fpm
[root@localhost php-7.4.30]# cd /usr/local/php7/etc/
[root@localhost etc]# ls
pear.conf  php-fpm.conf.default  php-fpm.d
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# ls
www.conf.default
[root@localhost php-fpm.d]# cp www.conf.default www.conf

//编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf):
//配置fpm的相关选项为你所需要的值:
[root@localhost ~]# vim /usr/local/php7/etc/php-fpm.conf
......
pm.max_children = 50    ;最多同时提供50个进程提供50个并发服务
pm.start_servers = 5    ;启动时启动5个进程
pm.min_spare_servers = 2    ;最小空闲进程数
pm.max_spare_servers = 8    ;最大空闲进程数

//启动php-fpm

[root@localhost php-fpm.d]# cd
[root@localhost ~]# cd /usr/lib/systemd/system
[root@localhost system]# cp sshd.service php-fpm.service
[root@localhost system]# vim php-fpm.service
[Unit]
Description=php-fpm server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/etc/init.d/php-fpm start
ExecStop=/etc/init.d/php-fpm stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl status php-fpm
● php-fpm.service - php-fpm server daemon
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
   
[root@localhost system]# systemctl start php-fpm
[root@localhost system]# systemctl enable php-fpm
Synchronizing state of php-fpm.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@localhost system]# ss -antl
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              80                                 *:3306                              *:*                            
LISTEN         0              128                                *:80                                *:*                            
LISTEN         0              128                             [::]:22                             [::]:*                              

2.4 配置apache

2.4.1 启用代理模块

在apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩展,因此,这两个模块都要加载,编辑httpd.conf文件,取消以下两行内容的注释:

  • LoadModule proxy_module modules/mod_proxy.so
  • LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

//启用httpd的相关模块

[root@localhost ~]# vim /etc/httpd24/httpd.conf
......
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so       //取消这两行内容的注释
[root@localhost ~]# httpd -t
Syntax OK

2.4.2 配置虚拟主机

在需要使用fcgi的虚拟主机中添加类似如下两行:

ProxyRequests Off //关闭正向代理
ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1

例如:

ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/var/www/html/idfsoft.com/$1

以上设置表示把以.php结尾的文件请求发送到php-fpm进程,php-fpm至少需要知道运行的目录和URI,所以这里直接在fcgi://127.0.0.1:9000后指明了这两个参数,其它参数的传递已经被mod_proxy_fcgi.so进行了封装,不需要手动指定。

注意:

这里写的/var/www/html/是yum源安装方式生成的网页存放目录,这里必须改成你编译安装指定的网页存放路径,禁止直接复制我这里的路径
这里的idfsoft.com是域名,你必须改成你所使用的域名,禁止直接复制此处的域名
这里的$1表示匹配所有以.php结尾的http请求

//创建虚拟主机目录并生成php测试页面

 [root@localhost ~]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# ls
index.html
[root@localhost htdocs]# rm -f *
[root@localhost htdocs]# ls
[root@localhost htdocs]# mkdir runtime
[root@localhost htdocs]# cd runtime/
[root@localhost runtime]# vim index.php

[root@localhost runtime]# chown -R apache.apache /usr/local/apache/

[root@localhost runtime]# vim /etc/httpd24/httpd.conf
......
# Virtual hosts
Include /etc/httpd24/extra/httpd-vhosts.conf		         //此行取消注释

[root@localhost htdocs]# vim /etc/httpd24/extra/httpd-vhosts.conf 
......

    DocumentRoot "/usr/local/apache/htdocs/runtime"
    ServerName runtime.example.com
    ErrorLog "logs/runtime.example.com-error_log"
    CustomLog "logs/runtime.example.com-access_log" common
    ProxyRequests Off                                         //关闭正向代理
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/runtime/$1
    
        Options none
        AllowOverride none
        Require all granted
    


[root@localhost runtime]# vim /etc/httpd24/httpd.conf 
......
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php        //添加此行
    AddType application/x-httpd-php-source .phps        //添加此行
......

    DirectoryIndex index.php index.html        //添加index.php


[root@localhost runtime]# cd
[root@localhost ~]# httpd -t
Syntax OK
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# ss -antl
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       80                   *:3306                *:*              
LISTEN  0       128                  *:80                  *:*              
LISTEN  0       128               [::]:22               [::]:*   

2.5 验证

1.修改/etc/hosts文件,添加域名与IP的映射。
将 Windows 系统下的C:\Windows\System32\drivers\etc\hosts文件移至桌面,使用记事本打开,添加192.168.56.162 runtime.example.com,再移回
2.在浏览器上使用域名访问,若看到以下界面则表示lamp架构搭建成功,否则请检查你的操作
Lamp架构搭建以及docker_第2张图片

docker容器技术基础入门

容器(Container)

  • 容器是一种基础工具;泛指任何可以用于容纳其他物品的工具,可以部分或完全封闭,被用于容纳、储存、运输物品;物体可以被放置在容器中,而容器则可以保护内容物;
  • 人类使用容器的历史至少有十万年,甚至可能有数百万年的历史;
  • 容器的类型
    • 瓶 - 指口部比腹部窄小、颈长的容器
    • 罐 - 指那些开口较大、一般为近圆筒形的器皿
    • 箱 - 通常是立方体或圆柱体。形状固定
    • 篮 - 以条状物编织而成
    • 桶 - 一种圆柱形的容器
    • 袋 - 柔性材料制成的容器,形状会受内容物而变化
    • 瓮 - 通常是指陶制,口小肚大的容器
    • 碗 - 用来盛载食物的容器
    • 柜 - 指一个由盒组成的家具
    • 鞘 - 用于装载刀刃的容器

传统虚拟化与容器的区别

Lamp架构搭建以及docker_第3张图片

虚拟化分为以下两类:

  • 主机级虚拟化
    • 全虚拟化
    • 半虚拟化
  • 容器级虚拟化

容器分离开的资源:

  • UTS(主机名与域名)
  • Mount(文件系统挂载树)
  • IPC
  • PID进程树
  • User
  • Network(tcp/ip协议栈)

你可能感兴趣的:(架构,容器,docker)