0
点赞
收藏
分享

微信扫一扫

Linux基于Apache服务搭建简易镜像站


Linux基于Apache服务搭建简易镜像站_html

💗wei_shuo的个人主页

💫wei_shuo的学习社区

🌐Hello World !

Linux基于Apache服务搭建简易镜像站

• 安装Apache服务器
yum install -y httpd.x86_64
• 配置Apache服务器:编辑Apache配置文件/etc/httpd/conf/httpd.conf

#ServerName www.example.com:80#Listen 12.34.56.78:80
Listen
修改为:
#ServerName www.example.com:80
ServerName 192.168.51.140:80#Listen 12.34.56.78:80
Listen 192.168.51.140:80
Apache配置文件末尾添加如下:配置虚拟主机
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    #网站的根目录,存放位置
    DocumentRoot /var/www/html/mirrors
    #网站的域名或 IP 地址
    ServerName 192.168.51.140

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
• 使用httpd -t命令检查配置文件是否书写错误:重启Apache服务器
httpd -t
systemctl restart httpd
• 创建镜像站目录
mkdir /var/www/html/mirrors
• 编写HTML代码
mirrors 目录下创建一个名为 index.html 的文件:
nano /var/www/html/mirrors/index.html<!DOCTYPE html>
<html>
<head>
	<title>My Mirror Site</title>
</head>
<body>
	<h1>Hello, world!</h1>
</body>
</html>
• 配置阿里云镜像源:创建目录备份yum.repos.d路径下的文件
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv CentOS-* bak/
• 下载阿里云Yum源
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2023-04-14 22:51:21--  https://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 119.36.62.54, 119.36.62.60, 119.36.62.61, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|119.36.62.54|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”

100%[==========================================================================>] 2,523       --.-K/s 用时 0s      

2023-04-14 22:51:26 (1.36 GB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])

[root@localhost yum.repos.d]# ll
总用量 4
drwxr-xr-x. 2 root root  219 4月  15 2023 bak
-rw-r--r--. 1 root root 2523 8月   4 2022 CentOS-Base.repo
• 清除yum缓存,测试是否成功
[root@localhost yum.repos.d]# yum clean all 
已加载插件:fastestmirror, langpacks
正在清理软件源: base extras updates
Cleaning up list of fastest mirrors
Other repos take up 19 M of disk space (use --verbose for details)
[root@localhost yum.repos.d]# yum repolist 
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                         | 3.6 kB  00:00:00     
extras                                                                                       | 2.9 kB  00:00:00     
updates                                                                                      | 2.9 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                                                                | 153 kB  00:00:05     
(2/4): extras/7/x86_64/primary_db                                                            | 249 kB  00:00:05     
(3/4): updates/7/x86_64/primary_db                                                           |  20 MB  00:00:06     
base/7/x86_64/primary_db       FAILED                                          
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/6d0c3a488c282fe537794b5946b01e28c7f44db79097bb06826e1c0c88bad5ef-primary.sqlite.bz2: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/6d0c3a488c282fe537794b5946b01e28c7f44db79097bb06826e1c0c88bad5ef-primary.sqlite.bz2: (28, 'Connection timed out after 30000 milliseconds')
正在尝试其它镜像。
(4/4): base/7/x86_64/primary_db                                                              | 6.1 MB  00:00:00     
源标识                                     源名称                                                             状态
base/7/x86_64                              CentOS-7 - Base - mirrors.aliyun.com                               10,072
extras/7/x86_64                            CentOS-7 - Extras - mirrors.aliyun.com                                515
updates/7/x86_64                           CentOS-7 - Updates - mirrors.aliyun.com                             4,886
repolist: 15,473
• 测试是否成功
curl 192.168.51.140:80


Linux基于Apache服务搭建简易镜像站_html_02

或者浏览器访问192.168.51.140:80

Linux基于Apache服务搭建简易镜像站_服务器_03

  • 如无法访问则关闭防火墙SELinux

stop firewalld.service setenforce 0

基于Apache页面搭建镜像站

  • 使用yum 工具同步镜像:下载yum工具

sudo yum install yum-utils yum install createrepo reposync sudo yum clean all yum makecache

  • 创建对应镜像目录

mkdir -p /var/www/html/mirrors/centos/7/os/x86_64/

  • 使用 reposync 命令同步 CentOS 7 OS 软件源

reposync -g -l -d -m --repoid=base --newest-only --download-metadata --download_path=/var/www/html/mirrors/centos/7/os/x86_64/

  • 使用createrepo 工具来创建一个 RPM 包的元数据库

createrepo /var/www/html/mirrors/centos/7/os/x86_64/

  • 配置Apache配置文件/etc/httpd/conf/httpd.conf

配置映射路径:访问/mirrors映射到/var/www/html/mirrors

# Alias /webpath /full/filesystem/path Alias /mirrors "/var/www/html/mirrors"

配置目录访问权限

<Directory "/var/www/html/mirrors"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>

  1. "var/www/html/mirrors" 指定了要配置的目录路径
  2. Options Indexes FollowSymLinks 指定了该目录允许列出文件和子目录,并且允许使用符号链接
  3. AllowOverride None 指定了该目录不允许使用 .htaccess 文件覆盖 Apache 的全局配置
  4. Require all granted 指定了该目录允许所有用户访问
  • 测试:浏览器访问http://192.168.51.140/mirrors/

Linux基于Apache服务搭建简易镜像站_apache_04

镜像站常用目录

/var/www/html/mirrors
├── centos
│   ├── 7
│   │   ├── os
│   │   ├── updates
│   │   ├── extras
│   │   └── ...
│   ├── 8
│   │   ├── BaseOS
│   │   ├── AppStream
│   │   ├── extras
│   │   └── ...
│   └── ...
├── epel
│   ├── 7
│   │   ├── x86_64
│   │   ├── noarch
│   │   └── ...
│   ├── 8
│   │   ├── x86_64
│   │   ├── noarch
│   │   └── ...
│   └── ...
├── docker-ce
│   ├── centos7
│   │   ├── x86_64
│   │   └── ...
│   ├── centos8
│   │   ├── x86_64
│   │   └── ...
│   └── ...
└── ...

🌼 结语:创作不易,如果觉得博主的文章赏心悦目,还请——点赞👍收藏⭐️评论📝

Linux基于Apache服务搭建简易镜像站_Apache_05


举报

相关推荐

0 条评论