(在centos环境下部署测试网站)
一、web服务介绍
1.1 web简介
WEB服务器也称为WWW(WORLD WIDE WEB,万维网)服务器,主要功能是提供网上信息浏览服务。
1.2 Apache简介
Apache HTTPD又可以简称为httpd或者Apache,它是Internet使用最广泛的web服务器之一,使用Apache提供的web服务器是由守护进程httpd。
1.3 Apache特点
1.支持最新的HTTP/1.1通信协议 2.拥有简单而强有力的基于文件的配置过程 3.支持通用网关接口 4.支持基于IP和基于域名的虚拟主机 5.支持多种方式的HTTP认证 6.集成Perl处理模块 7.集成代理服务器模块 8.支持实时监视服务器状态和定制服务器日志 9.支持服务器端包含指令(SSI) 10.支持安全Socket层(SSL) 11.提供用户会话过程的跟踪 12.支持FastCGI 13.通过第三方模块可以支持JavaServlets
二、部署环境介绍
hostname | IP地址 | httpd版本 | 操作系统版本 |
---|---|---|---|
myserver | 192.168.3.157 | Apache/2.4.6 | centos 7.6 |
三、安装httpd软件
3.1 检查yum仓库
检查本地yum仓库的镜像源,确定可用。
[root@myserver ~]# yum repolist all |grep enable
!base/7/x86_64 CentOS-7 - Base enabled: 10,072
!docker-ce-stable/7/x86_64 Docker CE Stable - enabled: 210
!extras/7/x86_64 CentOS-7 - Extras enabled: 515
!mysql-connectors-community/x86_64 MySQL Connectors Co enabled: 213
!mysql-tools-community/x86_64 MySQL Tools Communi enabled: 96
!mysql80-community/x86_64 MySQL 8.0 Community enabled: 386
!updates/7/x86_64 CentOS-7 - Updates enabled: 4,839
!zabbix/x86_64 Zabbix Official Rep enabled: 103
!zabbix-agent2-plugins/x86_64 Zabbix Official Rep enabled: 4
!zabbix-non-supported/x86_64 Zabbix Official Rep enabled: 5
3.2 搜索httpd软件
使用yum搜索httpd软件
[root@myserver ~]# yum list all |grep httpd
httpd.x86_64 2.4.6-98.el7.centos.6 updates
httpd-devel.x86_64 2.4.6-98.el7.centos.6 updates
httpd-manual.noarch 2.4.6-98.el7.centos.6 updates
httpd-tools.x86_64 2.4.6-98.el7.centos.6 updates
keycloak-httpd-client-install.noarch 0.8-1.el7 base
libmicrohttpd.i686 0.9.33-2.el7 base
libmicrohttpd.x86_64 0.9.33-2.el7 base
libmicrohttpd-devel.i686 0.9.33-2.el7 base
libmicrohttpd-devel.x86_64 0.9.33-2.el7 base
libmicrohttpd-doc.noarch 0.9.33-2.el7 base
python2-keycloak-httpd-client-install.noarch
3.3 安装hhtpd
直接使用yum安装httpd
[root@myserver ~]# yum -y install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
extras | 2.9 kB 00:00:00
mysql-connectors-community | 2.6 kB 00:00:00
mysql-tools-community | 2.6 kB 00:00:00
mysql80-community | 2.6 kB 00:00:00
updates | 2.9 kB 00:00:00
zabbix | 2.9 kB 00:00:00
zabbix-agent2-plugins | 2.9 kB 00:00:00
zabbix-non-supported | 2.9 kB 00:00:00
updates/7/x86_64/primary_db | 20 MB 00:00:01
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-98.el7.centos.6 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-98.el7.centos.6 for package: httpd-2.4.6-98.el7.centos.6.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-98.el7.centos.6.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-98.el7.centos.6 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-98.el7.centos.6 updates 2.7 M
Installing for dependencies:
httpd-tools x86_64 2.4.6-98.el7.centos.6 updates 94 k
mailcap noarch 2.1.41-2.el7 base 31 k
Transaction Summary
==================================================================================================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 2.8 M
Installed size: 9.6 M
Downloading packages:
(1/3): httpd-tools-2.4.6-98.el7.centos.6.x86_64.rpm | 94 kB 00:00:00
(2/3): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00
(3/3): httpd-2.4.6-98.el7.centos.6.x86_64.rpm | 2.7 MB 00:00:00
--------------------------------------------------------------------------------------------------------------------------------------------------
Total 7.1 MB/s | 2.8 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mailcap-2.1.41-2.el7.noarch 1/3
Installing : httpd-tools-2.4.6-98.el7.centos.6.x86_64 2/3
Installing : httpd-2.4.6-98.el7.centos.6.x86_64 3/3
Verifying : httpd-tools-2.4.6-98.el7.centos.6.x86_64 1/3
Verifying : mailcap-2.1.41-2.el7.noarch 2/3
Verifying : httpd-2.4.6-98.el7.centos.6.x86_64 3/3
Installed:
httpd.x86_64 0:2.4.6-98.el7.centos.6
Dependency Installed:
httpd-tools.x86_64 0:2.4.6-98.el7.centos.6 mailcap.noarch 0:2.1.41-2.el7
Complete!
四、httpd的配置工作
4.1 检查httpd版本
检查httpd版本
[root@myserver ~]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Jan 27 2023 17:36:29
4.2 查看httpd配置文件
查看httpd默认配置文件,网站根目录默认在/var/www/html,监听端口默认80,我们不用更改,直接使用默认配置即可。
[root@myserver ~]# cd /etc/httpd/conf/
[root@myserver conf]# ls
httpd.conf magic
[root@myserver conf]#
4.3 编辑网站测试内容
编辑index.html测试文件
echo "test web aba1" > /var/www/html/index.html
4.4 启动httpd服务
启动httpd服务
[root@myserver conf]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
4.5 检查httpd服务状态
检查httpd服务状态
[root@myserver conf]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2023-03-22 19:55:25 CST; 35s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 24365 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─24365 /usr/sbin/httpd -DFOREGROUND
├─24366 /usr/sbin/httpd -DFOREGROUND
├─24367 /usr/sbin/httpd -DFOREGROUND
├─24368 /usr/sbin/httpd -DFOREGROUND
├─24369 /usr/sbin/httpd -DFOREGROUND
└─24370 /usr/sbin/httpd -DFOREGROUND
Mar 22 19:55:25 myserver systemd[1]: Starting The Apache HTTP Server...
Mar 22 19:55:25 myserver httpd[24365]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe8... message
Mar 22 19:55:25 myserver systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
五、关闭防火墙和selinux
5.1 关闭selinux
关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0
5.2 关闭防火墙
在测试环境下直接关闭防火墙,也可以在防火墙开启状态下,放行80端口。
systemctl disable firewalld && systemctl stop firewalld
六、访问测试网站内容
6.1 本机访问web内容
在本机直接访问web内容
[root@myserver conf]# curl 192.168.3.157
test web aba1
6.2 访问web服务器内容
访问web服务器内容