小白带你学习linuxAPACHE安装和管理 (二十)

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: 小白带你学习linuxAPACHE安装和管理 (二十)



一、概述

web服务器提供者,web中间件

能够提供html文本文档的传输

传输协议是http/https协议

默认端口:80/443

二、安装

1、 yum安装

systemctl stop NetworkManager

systemctl disable NetworkManager           关闭网络图形管

理工具

2、配置静态ip

进入网卡配置

  cd /etc/sysconfig/network-scripts/

3、编辑网卡配置

vim ifcfg-ens33

文件内容

配置网卡后重启网络服务

三、选择安装方式

1、yum install httpd -y

2、编译安装

步骤

配置           ./configure

编译             make

安装             make install

编译安装的卸载只需要删除对应的安装目录

运维案例

基于CentOS7.9操作系统安装apache web组件。

操作流程

收集适合CentOS7.9操作系统的apache软件包版本

https://httpd.apache.org/download.cgi

将软件拖入并解压

rpm -q httpd                  查看是否yum安装httpd,有的话卸载

./configure -h              查看配置的使用方法

根据编译的报错信息安装依赖关系

apr-devel

apr-util

apr-util-devel

pcre-devel

pcre-static

 pcre-tools

 pcre2-static

  pcre2-devel  

 pcre2-tools  

  pcre2-utf32

 make&&make install  安装完依赖

优化命令路径                 ln -s /usr/local/apache2/bin /usr/sbin

优化启动服务管理

cp /usr/local/apache2/bin/apachectl* /etc/init.d/apached
vim  /etc/init.d/apached
#!/bin/bash
# chkconfig: 235 85 75
chkconfig --add  /etc/init.d/apached

可以使用systemd管理                     systemctl  start apached

开机自启                  chkconfig  --level 35 apached

四、目录结构

1、yum安装

/etc/httpd        安装主目录

conf.modules.d                   模块加载配置文件存储目录

conf.d                 conf目录的附属目录

conf                  主配置文件存储目录                  

httpd.conf

ServerRoot "/etc/httpd"                           服务安装根目录

Listen 80                                      监听端口

Include conf.modules.d/*.conf                              引用外部配置文件到当前文件中

User apache                                运行账户

Group apache                              运行组

ServerName www.example.com:80                            可用域名

DocumentRoot "/var/www/html"                             网页文档根目录

DirectoryIndex index.html                        默认访问首页

/usr/sbin            命令目录

/var/log/httpd

日志目录

日志级别           debug, info, notice, warn, error, crit,alert, emerg

日志类型

访问日志                 access_log

错误日志              error_log

/var/www/html          网页源码存放目录

/run/httpd         PID存储目录

/usr/share/doc/httpd-2.4.6        模板配置文件

httpd-vhosts.conf           虚拟主机头配置文件

2、编译安装

/usr/local/apache2

配置文件         conf

extra               httpd-vhosts.conf           虚拟主机头配置

httpd.conf            

主配置

ServerRoot "/usr/local/apache2                        服务安装根目录

Listen 80                       监听端口

Include conf.modules.d/*.conf                         引用外部配置文件到当前文件中

User daemon                      运行账户

Group daemon                         运行组

ServerName www.example.com:80                         可用域名

DocumentRoot "/usr/local/apache2/htdocs"                    网页文档根目录

  DirectoryIndex index.html                      默认访问首页

五、虚拟主机头配置

基本配置

1、yum安装

mkdir /etc/httpd/extra

cp /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf /etc/http/extra

vim /etc/httpd/conf/httpd.conf在文件末尾追加:    IncludeOptional extra/*.conf

将htpd.conf中Listen 80 注释掉

在httpd-vhosts.conf中加入:Listen 80

2、编译安装

vim /usr/local/apache2/conf/httpd.conf中去掉注释:Include conf/exta/httpd-vhosts.conf

将htpd.conf中Listen 80 注释掉

在httpd-vhosts.conf中加入:Listen 80

实现方式

基于不同的端口号

cd /etc/httpd/extra

Listen 80

Listen 81

基于不同的域名

cd /etc/httpd/extra

Listen 80

基于不同的IP地址

cd /etc/httpd/extra/

Listen 192.168.115.128:80

Listen 192.168.115.135:80

配置多地址

修改ens33的配置文件

IPADDR1=192.168.115.128

PREFIX1=24

IPADDR2=192.168.115.135

PREFIX2=24

利用ens33的子接口实现

临时                    ifconfig ens33:0 192.168.115.136/24

永久                   cd /etc/sysconfig/network-scripts/

cp ifcfg-ens33 ifcfg-ens33:1

vim ifcfg-ens33:1

六、配置文件语法检查

httpd -t -f /usr/local/apache2/conf/httpd.conf

七、配置https访问

yum安装

httpd-vhosts.conf内容全部注释

yum install -y mod_ssl

cd /etc/httpd/conf.d/

证书存储目录       /etc/pki/tls

vim ssl.conf

systemctl restart httpd

访问测试

curl      返回结果为html的源码

-I(大写i)        返回响应头

firefox     https://192.168.115.128

ctrl + F5         深度刷新,忽略本地的浏览器缓存

相关实践学习
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
相关文章
|
数据采集 自然语言处理 搜索推荐
ModelScope问题之模型encoder配置报错如何解决
ModelScope模型报错是指在使用ModelScope平台进行模型训练或部署时遇到的错误和问题;本合集将收集ModelScope模型报错的常见情况和排查方法,帮助用户快速定位问题并采取有效措施。
727 0
|
3月前
|
存储 机器学习/深度学习 人工智能
告别OOM!这款开源神器,如何为你精准预测AI模型显存?
在 AI 开发中,CUDA 显存不足常导致训练失败与资源浪费。Cloud Studio 推荐一款开源工具——AI 显存计算器,可精准预估模型训练与推理所需的显存,支持主流模型结构与优化器,助力开发者高效利用 GPU 资源。项目地址:github.com/st-lzh/vram-wuhrai
|
PHP Apache
centos7.9 安装php7.0以上版本
centos7.9 安装php7.0以上版本
471 2
|
网络协议 Linux
CentOS7 yum安装报错“Could not resolve host: mirrorlist.centos.org;"之解决办法(换源)
CentOS7 yum安装报错“Could not resolve host: mirrorlist.centos.org; Name or service not known“之解决办法(换源)
|
SQL 开发框架 .NET
常用的 4 种 ORM 框架(EF Core,SqlSugar,FreeSql,Dapper)对比总结
常用的 4 种 ORM 框架(EF Core,SqlSugar,FreeSql,Dapper)对比总结
3406 0
Access denied for user ‘xxx’@‘localhost‘(using password:YES)
Access denied for user ‘xxx’@‘localhost‘(using password:YES)
|
存储 Linux 网络安全
centos7使用yum网络安装
这些是使用Yum进行网络安装的基本步骤。根据你的需求,你可以重复步骤3和4来安装其他软件包。请注意,执行Yum操作需要root或具有sudo权限的用户。
763 1
|
Linux
CentOS 7 配置yum阿里源 (三步即可)
CentOS 7 配置yum阿里源 (三步即可)
24686 1
|
Ubuntu Linux Shell
Linux安装及管理程序:rpm软件包、源代码安装( 时间最美的地方,就是让你我成为了我们)(一)
Linux安装及管理程序:rpm软件包、源代码安装( 时间最美的地方,就是让你我成为了我们)(一)
516 0
Linux安装及管理程序:rpm软件包、源代码安装( 时间最美的地方,就是让你我成为了我们)(一)
|
运维 Linux 虚拟化
远程终端工具Xshell、Xftp传输工具、VMware 、CentOS7的下载、安装和使用教程(完整版)
通常在工作过程中,公司中使用的真实服务器或者是云服务器,都不允许除运维人员之外的员工直接接触,因此就需要通过远程登录的方式来操作。所以,远程登录工具就是必不可缺的,目前,比较主流的有Xshell,SecureCRT等,同学们可以根据自己的习惯自行选择,以下以Xshell7为例。...
远程终端工具Xshell、Xftp传输工具、VMware 、CentOS7的下载、安装和使用教程(完整版)