离线环境中使用ISO文件构建Yum源
背景说明
项目中客户现场都是离线的环境,需要自己构建Yum源。算是记录一下这个步骤,网上的文档也很多。大家随便看看
准备材料
- 操作系统的ISO(完整版)文件: https://mirrors.nwafu.edu.cn/openeuler/openEuler-24.03-LTS-SP2/ISO/aarch64/openEuler-24.03-LTS-SP2-everything-aarch64-dvd.iso
- Linux服务器
配置步骤
- 将ISO文件挂载
mkdir -p /mnt/iso
vi /etc/fstab
/data/openEuler-24.03-LTS-SP2-everything-aarch64-dvd.iso /mnt/iso iso9660 loop 0 0
mount -a
- 配置本地Yum源并按照Nginx服务
#vi /etc/yum.repos.d/local.repo
[local-iso]
name=Local ISO Repo
baseurl=file:///mnt/iso
enabled=1
gpgcheck=0
yum makecache
yum install -y nginx
- 配置Nginx
#vi /etc/nginx/nginx.conf
# 全局配置
user nginx;
worker_processes 2;error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;# 事件配置
events {worker_connections 1024;
}# HTTP 配置
http {include /etc/nginx/mime.types;default_type application/octet-stream;log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log /var/log/nginx/access.log main;sendfile on;keepalive_timeout 65;# YUM 仓库服务server {listen 18080;server_name _;access_log /var/log/nginx/yum_repo_access.log;error_log /var/log/nginx/yum_repo_error.log;location /openeuler {alias /mnt/iso/; # 指向挂载的 ISO 目录autoindex on; # 开启目录索引autoindex_exact_size off; # 友好显示文件大小autoindex_localtime on; # 使用本地时间sendfile on;tcp_nopush on;tcp_nodelay on;}}# 载入额外的虚拟主机配置include /etc/nginx/conf.d/*.conf;
}
systemctl enable nginx && systemctl start nginx
- 在其它服务器上配置并使用本地的Yum源
#vi /etc/yum.repos.d/local.repo
[remote-iso]
name=Remote ISO Repo
baseurl=http://<服务器IP>:18080/openeuler
enabled=1
gpgcheck=0
- 可以通过Ansible的方式分发到其它服务器上
---
- name: Distribute local.repo to remote servershosts: allbecome: yesgather_facts: notasks:- name: Copy local.repo to remote serverscopy:src: /etc/yum.repos.d/local.repo # 控制节点上的文件dest: /etc/yum.repos.d/local.repo # 被控节点的目标路径owner: rootgroup: rootmode: '0644'- name: Clean and make yum cachecommand: "{{ item }}"with_items:- yum clean all- yum makecache