Linux系统之安装apache服务

简介: Linux系统之安装apache服务

一、检查本地系统版本

[root@node ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
[root@node ~]# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core) 

二、配置yum仓库

1.配置阿里的yum源

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

2.检查yum仓库

[root@node ~]# yum repolist all  |grep enable
base/7/x86_64                        CentOS-7 - Base             enabled: 10,072
docker-ce-stable/7/x86_64            Docker CE Stable - x86_64   enabled:    183
extras/7/x86_64                      CentOS-7 - Extras           enabled:    515
mongodb-org/7                        MongoDB Repository          enabled:    187
updates/7/x86_64                     CentOS-7 - Updates          enabled:  4,346
[root@node ~]# 

三、安装http软件包

[root@node ~]# yum -y install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-97.el7.centos.5 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-97.el7.centos.5 for package: httpd-2.4.6-97.el7.centos.5.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-97.el7.centos.5.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-97.el7.centos.5.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-97.el7.centos.5.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-7.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-97.el7.centos.5 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================
 Package                           Arch                         Version                                        Repository                     Size
===================================================================================================================================================
Installing:
 httpd                             x86_64                       2.4.6-97.el7.centos.5                          updates                       2.7 M
Installing for dependencies:
 apr                               x86_64                       1.4.8-7.el7                                    base                          104 k
 apr-util                          x86_64                       1.5.2-6.el7                                    base                           92 k
 httpd-tools                       x86_64                       2.4.6-97.el7.centos.5                          updates                        94 k
 mailcap                           noarch                       2.1.41-2.el7                                   base                           31 k

Transaction Summary
===================================================================================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 3.0 M
Installed size: 10 M
Downloading packages:
(1/5): apr-1.4.8-7.el7.x86_64.rpm                                                                                           | 104 kB  00:00:00     
(2/5): mailcap-2.1.41-2.el7.noarch.rpm                                                                                      |  31 kB  00:00:00     
(3/5): httpd-2.4.6-97.el7.centos.5.x86_64.rpm                                                                               | 2.7 MB  00:00:00     
(4/5): apr-util-1.5.2-6.el7.x86_64.rpm                                                                                      |  92 kB  00:00:02     
(5/5): httpd-tools-2.4.6-97.el7.centos.5.x86_64.rpm                                                                         |  94 kB  00:00:02     
---------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                              1.1 MB/s | 3.0 MB  00:00:02     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.4.8-7.el7.x86_64                                                                                                          1/5 
  Installing : apr-util-1.5.2-6.el7.x86_64                                                                                                     2/5 
  Installing : httpd-tools-2.4.6-97.el7.centos.5.x86_64                                                                                        3/5 
  Installing : mailcap-2.1.41-2.el7.noarch                                                                                                     4/5 
  Installing : httpd-2.4.6-97.el7.centos.5.x86_64                                                                                              5/5 
  Verifying  : apr-1.4.8-7.el7.x86_64                                                                                                          1/5 
  Verifying  : mailcap-2.1.41-2.el7.noarch                                                                                                     2/5 
  Verifying  : httpd-tools-2.4.6-97.el7.centos.5.x86_64                                                                                        3/5 
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                                                                                     4/5 
  Verifying  : httpd-2.4.6-97.el7.centos.5.x86_64                                                                                              5/5 

Installed:
  httpd.x86_64 0:2.4.6-97.el7.centos.5                                                                                                             

Dependency Installed:
  apr.x86_64 0:1.4.8-7.el7     apr-util.x86_64 0:1.5.2-6.el7     httpd-tools.x86_64 0:2.4.6-97.el7.centos.5     mailcap.noarch 0:2.1.41-2.el7    

Complete!

3.启动httpd服务

[root@node ~]# systemctl enable --now httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

四、新增IP地址

1.查看原有IP

[root@node conf.d]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.166  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::8a83:7297:7cb8:9934  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:4f:3c:68  txqueuelen 1000  (Ethernet)
        RX packets 3551027  bytes 4447887320 (4.1 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1082308  bytes 122960632 (117.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2.新增IP地址

[root@node conf.d]# ip addr add 192.168.3.164/24 dev ens33 
[root@node conf.d]# ip add |grep  ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 192.168.3.166/24 brd 192.168.3.255 scope global noprefixroute dynamic ens33
    inet 192.168.3.164/24 scope global secondary ens33

五、修改httpd配置文件

1.创建三个虚拟主机的根目录

 mkdir -p /var/www/web{1,2,,3}

2.添加网页文件内容

[root@node conf.d]# mkdir -p /var/www/web{1,2,,3}
[root@node conf.d]# echo "web1 service" > /var/www/web1/index.html
[root@node conf.d]# echo "web2 service" > /var/www/web2/index.html
[root@node conf.d]# echo "web3 service" > /var/www/web3/index.html

六、基于ip的虚拟主机

1.修改httpd服务配置文件

[root@node conf.d]# cat ip.conf 
#Listen 8181
<VirtualHost 192.168.3.166:80>
ServerName web1.huawei.com
DocumentRoot /var/www/web1
</VirtualHost>



<VirtualHost 192.168.3.164:80>
ServerName web2.huawei.com
DocumentRoot /var/www/web2
</VirtualHost>


#<VirtualHost *:8181>
#ServerName web3.huawei.com
#DocumentRoot /var/www/web3
#</VirtualHost>

2.重启httpd服务

 systemctl restart httpd

3.IP访问效果

[root@node conf.d]# curl 192.168.3.166
web1 service
[root@node conf.d]# curl 192.168.3.164
web2 service

七、基于端口的虚拟主机

1.修改httpd配置文件

[root@node conf.d]# cat port.conf 
Listen 8181
<VirtualHost *:8181>
ServerName web2.huawei.com
DocumentRoot /var/www/web2
</VirtualHost>



<VirtualHost *:8181>
ServerName web3.huawei.com
DocumentRoot /var/www/web3
</VirtualHost>


#<VirtualHost *:8181>
#ServerName web3.huawei.com
#DocumentRoot /var/www/web3
#</VirtualHost>




2.修改/etc/hosts


[root@node conf.d]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
#192.168.3.166 web1.huawei.com
192.168.3.166 web2.huawei.com
192.168.3.164 web3.huawei.com

3.重启httpd服务

systemctl restart httpd

4.访问测试结果

[root@node conf.d]# curl web2.huawei.com:8181
web2 service
[root@node conf.d]# curl web3.huawei.com:8181
web3 service

5.基于域名访问测试

[root@node conf.d]# curl web3.huawei.com
web2 service
[root@node conf.d]# curl web2.huawei.com
web1 service
相关文章
|
Ubuntu Linux
计算机基础知识:linux系统怎么安装?
在虚拟机软件中创建一个新的虚拟机,并选择相应操作系统类型和硬盘空间大小等参数。将下载的 ISO 镜像文件加载到虚拟机中。启动虚拟机,进入安装界面,并按照步骤进行安装。安装完成后,可以在虚拟机中使用 Linux 系统。
|
安全 Linux iOS开发
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
1072 6
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
|
网络协议 关系型数据库 Linux
【App Service Linux】在Linux App Service中安装 tcpdump 并抓取网络包
在App Service for Linux环境中,无法像Windows一样直接使用网络排查工具抓包。本文介绍了如何通过TCPDUMP在Linux环境下抓取网络包,包括SSH进入容器、安装tcpdump、执行抓包命令及下载分析文件的完整操作步骤。
693 5
|
Ubuntu 安全 Linux
Linux Docker & Docker Compose 一键安装
该脚本由轩辕镜像官方维护,支持多种Linux发行版,可一键安装Docker与docker-compose,并自动配置镜像加速源。脚本开源、安全、高效,适用于Ubuntu、CentOS等系统,内置国内镜像源,提升下载速度,同时提供一键回滚功能,保障安装稳定性。
5127 1
|
消息中间件 Kafka Linux
Linux下安装Kafka 3.9.1
本文介绍Kafka 3.9.1版本的安装与配置,包括通过ZooKeeper或KRaft模式启动Kafka。涵盖环境变量设置、日志路径修改、集群UUID生成、存储格式化及服务启停操作,适用于Linux环境下的部署实践。
1625 0
|
弹性计算 安全 Linux
阿里云服务器ECS安装宝塔Linux面板、安装网站(新手图文教程)
本教程详解如何在阿里云服务器上安装宝塔Linux面板,涵盖ECS服务器手动安装步骤,包括系统准备、远程连接、安装命令执行、端口开放及LNMP环境部署,手把手引导用户快速搭建网站环境。
|
Ubuntu 安全 Linux
Linux这5款微型发行版,体积小+精简,比win7运行还快,值得安装
以上5款微型发行版体积小且精简,如果你有台旧电脑,不妨试试?
|
人工智能 数据处理 API
阿里云、Ververica、Confluent 与 LinkedIn 携手推进流式创新,共筑基于 Apache Flink Agents 的智能体 AI 未来
Apache Flink Agents 是由阿里云、Ververica、Confluent 与 LinkedIn 联合推出的开源子项目,旨在基于 Flink 构建可扩展、事件驱动的生产级 AI 智能体框架,实现数据与智能的实时融合。
1864 6
阿里云、Ververica、Confluent 与 LinkedIn 携手推进流式创新,共筑基于 Apache Flink Agents 的智能体 AI 未来
|
存储 Cloud Native 数据处理
从嵌入式状态管理到云原生架构:Apache Flink 的演进与下一代增量计算范式
本文整理自阿里云资深技术专家、Apache Flink PMC 成员梅源在 Flink Forward Asia 新加坡 2025上的分享,深入解析 Flink 状态管理系统的发展历程,从核心设计到 Flink 2.0 存算分离架构,并展望未来基于流批一体的通用增量计算方向。
963 0
从嵌入式状态管理到云原生架构:Apache Flink 的演进与下一代增量计算范式
|
SQL 人工智能 数据挖掘
Apache Flink:从实时数据分析到实时AI
Apache Flink 是实时数据处理领域的核心技术,历经十年发展,已从学术项目成长为实时计算的事实标准。它在现代数据架构中发挥着关键作用,支持实时数据分析、湖仓集成及实时 AI 应用。随着 Flink 2.0 的发布,其在流式湖仓、AI 驱动决策等方面展现出强大潜力,正推动企业迈向智能化、实时化的新阶段。
1526 9
Apache Flink:从实时数据分析到实时AI