Skip to content

局域网yum源

这里记录使用Nginx进行搭建

Nginx信息

nginx
server {
	listen       10086;
	listen       [::]:10086;
	# server_name _;
	
	location / {
		root         /opt/repo/;
		autoindex            on;
		autoindex_exact_size on;
		autoindex_localtime  on;
	}
}

通过iso准备yum资源

Centos 7.9

资源准备

bash
#  创建目录
mkdir -p /opt/temp
mkdir -p /opt/repo/x86_64/Centos7.9

# 挂载镜像
mount -o loop /data/iso/CentOS-7.9-x86_64-Everything-2009.iso /opt/temp

# 复制镜像内容,避免每次重启等需要重新挂载
cp -r /opt/temp/* /opt/repo/x86_64/Centos7.9/

# 取消挂载
umount /opt/temp

本地使用

shell
$cat /etc/yum.repos.d/local.repo
 
[local]
name=local
baseurl=file:///opt/repo/x86_64/Centos7.9
gpgcheck=1
enabled=1
gpgkey=file:///opt/repo/x86_64/Centos7.9/RPM-GPG-KEY-CentOS-7

内网使用

shell
$cat /etc/yum.repos.d/CentOS-Base.repo

[base]
name=CentOS-7.9.2009 - Base
baseurl=http://xxx.xxx.xxx.xxx:10086/x86_64/Centos7.9
enabled=1
gpgcheck=0
gpgkey=http://xxx.xxx.xxx.xxx:10086/x86_64/Centos7.9/RPM-GPG-KEY-CentOS-7

openEuler 20.03-SP3

资源准备

bash
#  创建目录
mkdir -p /opt/temp
mkdir -p /opt/repo/x86_64/openEuler-20.03-LTS-SP3

# 挂载镜像
mount -o loop /data/iso/openEuler-20.03-LTS-SP3-everything-x86_64-dvd.iso /opt/temp

# 复制镜像内容,避免每次重启等需要重新挂载
cp -r /opt/temp/* /opt/repo/x86_64/openEuler-20.03-LTS-SP3/

# 取消挂载
umount /opt/temp

本地使用

shell
$cat /etc/yum.repos.d/local.repo
 
[local]
name=local
baseurl=file:///opt/repo/x86_64/openEuler-20.03-LTS-SP3
gpgcheck=1
enabled=1
gpgkey=file:///opt/repo/x86_64/openEuler-20.03-LTS-SP3/RPM-GPG-KEY-openEuler

内网使用

shell
$cat /etc/yum.repos.d/openEuler_20_03_x86_64.repo

[everything]
name=everything
baseurl=http://xxx.xxx.xxx.xxx:10086/x86_64/openEuler-20.03-LTS-SP3
enabled=1
gpgcheck=1
gpgkey=http://xxx.xxx.xxx.xxx:10086/x86_64/openEuler-20.03-LTS-SP3/RPM-GPG-KEY-openEuler

重新构建元数据

bash
# 清除缓存
yum clean all
# 建立缓存
yum makecache
# 列出所有已配置的yum仓库及其包含软件包的数量
yum repolist
# 安装
yum install -y xxxx

Alpine安装源

访问:Alpine 根据自己需要的版本找到community、main以及对应架构如aarch64、x86_64在Linux服务器上执行命令,下载到本地,如:

bash
wget -r -np -nH https://dl-cdn.alpinelinux.org/alpine/v3.9/main/aarch64/
wget -r -np -nH https://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/
wget -r -np -nH https://dl-cdn.alpinelinux.org/alpine/v3.9/community/aarch64/
wget -r -np -nH https://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/
  • -r--recursive:这个选项让 wget 递归地下载指定的网页及其所有依赖资源(如图片、CSS文件、JavaScript文件等)。这意味着,如果网页中有链接到其他资源,wget 会尝试下载这些链接指向的所有文件。
  • -np--no-parent:使用此选项后,wget 在递归下载时不会上升到父目录。换句话说,它只会下载指定URL下的资源,而不会尝试下载该URL父级目录下的资源。这对于避免下载整个网站非常有用。
  • -nH--no-host-directories:这个选项告诉 wget 在本地保存文件时,不创建以远程主机名命名的目录。默认情况下,wget 会为每个下载的网站创建一个以其域名命名的目录。使用 -nH 选项后,所有下载的文件会直接保存在当前目录或其指定的子目录中,而不会首先进入一个以网站域名命名的目录。

下载后传到内网,通过Nginx参考yum源的搭建,搭建出来,然后尝试更新软件源

bash
apk update

统信Uos安装源

获得认证头

python
import base64
import os.path


def generate_basic_auth_header(username: str, password: str) -> str:
    """
    生成 Uos Basic 认证头
    :param username: auth_u,  获取:/etc/yum/vars/auth_u
    :param password: auth_p,  获取:/etc/yum/vars/auth_p
    :return: Authorization 头
    """
    # 将用户名和密码组合为 "username:password"
    credentials = f"{username}:{password}"
    # 编码为 Base64
    encoded_credentials = base64.b64encode(credentials.encode()).decode()
    # 生成 Authorization 头
    auth_header = f"Basic {encoded_credentials}"
    # print(auth_header)
    return auth_header


# auth_*文件所在目录
base_dir = './'
# 读取用户名
with open(os.path.join(base_dir, 'auth_u'), encoding='utf8') as f:
    username = f.read()
    f.close()

# 读取密码
with open(os.path.join(base_dir, 'auth_p'), encoding='utf8') as f:
    password = f.read()
    f.close()

# 打印认证头
print(generate_basic_auth_header(username, password))

获得后大致为

shell
Basic dW9zLWh0dHBzOi8vbGljZW5.....

下载到本地

shell
#!/bin/bash
header='Basic dW9zLWh0dHBzOi8vbGljZW5.....'
base_url='https://euler-packages.chinauos.com/server-euler'
releasever='1070'
basearch='aarch64'
wget -r -np -nH --header="Authorization: ${header}" ${base_url}/fuyu/${releasever}/OS/${basearch}/
wget -r -np -nH --header="Authorization: ${header}" ${base_url}/fuyu/${releasever}/update/${basearch}/
wget -r -np -nH --header="Authorization: ${header}" ${base_url}/fuyu/${releasever}/everything/${basearch}/
wget -r -np -nH --header="Authorization: ${header}" ${base_url}/fuyu/${releasever}/kernel510/${basearch}/
wget -r -np -nH --header="Authorization: ${header}" ${base_url}/fuyu/${releasever}/Modular/${basearch}/

下载后传到内网,通过Nginx参考yum源的搭建,搭建出来,然后尝试 重新构建元数据/更新软件源