Loading

RHEL9.4上使用apache搭建http服务器提供repo源

时间:2024.11.24
计划:使用apache搭建HTTP(Hypertext Transfer Protocol)服务器,共享iso镜像为环境内其他主机提供repo(repository)源
参照:

安装httpd(apache)

[root@RHEL9 ~]# dnf info httpd
Updating Subscription Management repositories.
Last metadata expiration check: 2:16:03 ago on Sun 24 Nov 2024 12:21:38 AM CST.
Available Packages
Name         : httpd
Version      : 2.4.62
Release      : 1.el9
Architecture : x86_64
Size         : 51 k
Source       : httpd-2.4.62-1.el9.src.rpm
Repository   : rhel-9-for-x86_64-appstream-rpms
Summary      : Apache HTTP Server
URL          : https://httpd.apache.org/
License      : ASL 2.0
Description  : The Apache HTTP Server is a powerful, efficient, and extensible
             : web server.
[root@RHEL9 ~]# dnf install -y httpd

在http默认共享目录 /var/www/html/ 创建一个软连接 /var/www/html/iso 指向autofs挂载iso文件的路径 /misc/

[root@RHEL9 ~]# ln -s /misc/ /var/www/html/iso
[root@RHEL9 ~]# ls /var/www/html/iso/alma8
AppStream  BaseOS  EFI  EULA  extra_files.json  GPL  images  isolinux  media.repo  RPM-GPG-KEY-AlmaLinux  TRANS.TBL

启动服务

[root@RHEL9 ~]# systemctl status httpd.service 
○ httpd.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled)
     Active: inactive (dead)
       Docs: man:httpd.service(8)
[root@RHEL9 ~]# systemctl enable --now httpd.service 
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

配置防火墙

[root@RHEL9 ~]# firewall-cmd --list-services 
ssh
[root@RHEL9 ~]# firewall-cmd --info-service=http
http
  ports: 80/tcp
  protocols: 
  source-ports: 
  modules: 
  destination: 
  includes: 
  helpers: 
[root@RHEL9 ~]# firewall-cmd --query-service=http || firewall-cmd --add-service=http
no
success
[root@RHEL9 ~]# firewall-cmd --runtime-to-permanent 
success
[root@RHEL9 ~]# firewall-cmd --list-services
http ssh

局域网访问成功

脚本化从autofs自动挂载到http共享
[root@centos7 ~]# cat rhel9iso2web.sh 
#rhel9iso2web.sh
#Date: 2024-11-24
#!/bin/bash

#脚本功能
#将镜像文件实现autofs自动挂载并通过安装apache使用http协议共享出来

isodir=/data/ISO/
webdir=/var/www/html/iso

#安装autofs服务
rpm -q autofs || yum install -y autofs

#配置/etc/auto.misc文件
sed -Ei.bak "/^cd[[:blank:]]+-fstype=iso9660,ro,nosuid,nodev[[:blank:]]+:\/dev\/cdrom/a\*       -fstype=iso9660,ro,nosuid,nodev :${isodir}&.iso" /etc/auto.misc

#启动autofs服务
systemctl enable --now autofs.service

#安装httpd服务
rpm -q httpd || yum install -y httpd

#为misc目录创建软连接至http共享目录
[ -L ${webdir} ] || ln -s /misc/ ${webdir}

#启动httpd服务
systemctl enable --now httpd.service

#配置防火墙
firewall-cmd --query-service=http || firewall-cmd --add-service=http
firewall-cmd --runtime-to-permanent
posted @ 2024-11-24 23:38  李蔚  阅读(94)  评论(0)    收藏  举报