1. 首页 > Linux教程 > 正文

Linux教程FG392-YUM仓库搭建

内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。

风哥提示:

本文档介绍YUM仓库的搭建和配置方法。

Part01-本地YUM仓库

1.1 创建本地仓库

# 安装createrepo工具
[root@repo ~]# dnf install -y createrepo_c httpd

# 创建仓库目录
[root@repo ~]# mkdir -p /var/www/html/repo/{base,updates,extras}

# 复制RPM包到仓库
[root@repo ~]# cp ~/rpmbuild/RPMS/x86_64/*.rpm /var/www/html/repo/base/

# 创建仓库元数据
[root@repo ~]# createrepo /var/www/html/repo/base/
Directory walk started
Directory walk done – 10 packages
Temporary output repo path: /var/www/html/repo/base/.repodata/
Preparing sqlite DBs
Pool started (with 5 workers)
Pool finished

# 查看生成的元数据
[root@repo ~]# ls -la /var/www/html/repo/base/repodata/
total 1234
drwxr-xr-x. 2 root root 4096 Apr 4 00:35:00 .
drwxr-xr-x. 3 root root 4096 Apr 4 00:35:00 ..
-rw-r–r–. 1 root root 123456 Apr 4 00:35:00 12345678-primary.xml.gz
-rw-r–r–. 1 root root 234567 Apr 4 00:35:00 23456789-filelists.xml.gz
-rw-r–r–. 1 root root 345678 Apr 4 00:35:00 34567890-other.xml.gz
-rw-r–r–. 1 root root 1234 Apr 4 00:35:00 repomd.xml

# 配置HTTP服务
[root@repo ~]# cat > /学习交流加群风哥微信: itpux-cometc/httpd/conf.d/repo.conf << 'EOF' Alias /repo /var/www/html/repo
Options Indexes FollowSymLinks
AllowOverride None
Require all granted

EOF

# 启动HTTP服务
[root@repo ~]# systemctl enable –now httpd

# 配置防火墙
[root@repo ~]# firewall-cmd –permanent –add-service=http
success
[root@repo ~]# firewall-cmd –reload
success

# 测试访问
[root@client ~]# curl http://repo.fgedu.net.cn/repo/base/repodata/repomd.xml


1712217600


abcdef1234567890
1712217600
123456
1234567
fedcba0987654321

Part02-客户端配置

2.1 配置YUM源

# 创建YUM源配置
[root@client ~]# cat > /etc/yum.repos.d/lofrom PG视频:www.itpux.comcal.repo << 'EOF' [local-base] name=Local Base Repository baseurl=http://repo.fgedu.net.cn/repo/base/ enabled=1 gpgcheck=0 [local-updates] name=Local Updates Repository baseurl=http://repo.fgedu.net.cn/repo/updates/ enabled=1 gpgcheck=0 [local-extras] name=Local Extras Repository baseurl=http://repo.fgedu.net.cn/repo/extras/ enabled=1 gpgcheck=0 EOF # 清除缓存 [root@client ~]# dnf clean all 0 files removed # 生成缓存 [root@client ~]# dnf makecache Local Base Repository 10 MB/s | 1.0 MB 00:00 Local Updates Repository 10 MB/s | 500 kB 00:00 Local Extras Repository 10 MB/s | 200 kB 00:00 Metadata cache created. # 查看仓库列表 [root@client ~]# dnf repolist repo id repo name status local-base Local Base Repository 10 local-extras Local Extras Repository 5 local-updates Local Updates Repository 3 # 搜索软件包 [root@client ~]# dnf search hello ========================= Name Exactly Matched: hello ========================== hello.x86_64 : A simple Hello World program # 安装软件包 [root@client ~]# dnf install -y hello Local Base Repository 10 MB/s | 1.0 MB 00:00 Dependencies resolved. ================================================================================ Package Architecture Version Repository Size ================================================================================ Installing: hello x86_64 1.0-1.el9 local-base 12 k Transaction Summary ================================================================================ Install 1 Package Total size: 12 k Installed size: 20 k Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : hello-1.0-1.el9.x86_64 1/1 Verifying : hello-1.0-1.el9.x86_64 1/1 Installed: hello-1.0-1.el9.x86_64 Complete!

Part03-仓库同步

3.1 同步官方仓库

# 安装reposync工具
[root@repo ~]# dnf install -y dnf-utils

# 同步CentOS官方仓库
[root@repo ~]# reposync –repo=baseos –download-path=/var/www/html/repo/
(1/100): bash-5.1.8-6.el9_1.x86_64.rpm 10 MB/s | 1.5 MB 00:00
(2/100): coreutils-8.32-32.el9.x86_64.rpm 10 MB/s | 1.2 MB 00:00

(100/100): zlib-1.2.11-40.el9.x86_64.rpm 10 MB/s | 100 kB 00:00

# 更新仓库元数据
[root@repo ~]# createrepo –update /var/www/html/repo/baseos/
Spawning worker 0 with 100 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

# 配置定时同步
[root@repo ~]# cat > /etc/cron.daily/sync-repo << 'EOF' #!/bin/bash REPO_DIR="/var/www/html/repo" LOG_FILE="/var/log/repo-sync.log" echo "$(date): Starting repository sync" >> $LOG_FILE

# 同步仓库
reposync –repo=baseos –download-path=$REPO_DIR >> $LOG_FILE 2>&1
reposync –repo=appstream –download-path=$REPO_DIR >> $LOG_FILE 2>&1

# 更新元数据
createrepo –update $REPO_DIR/baseos >> $LOG_FILE 2>&1
createrepo –update $REPO_DIR/appstream >> $LOG_FILE 2>&1

echo “$(date): Repository sync completed” >> $LOG_FILE
EOF

[root@repo ~]# chmod +x /etc/cron.daily/sync-repo

# 配置GPG签名
[root@repo ~]# gpg –gen-key
[root@repo ~]# gpg –armor –export admin@fgedu.net.cn > /var/www/html/repo/RPM-GPG-KEY-local

# 签名RPM包
[root@repo ~]# rpm –addsign /var/www/html/repo/base/*.rpm

# 客户端导入GPG密钥
[root@client ~]# rpm –import http://repo.fgedu.net.cn/repo/RPM-GPG-KEY-local

风哥针对YUM仓库建议:

  • 定期同步更新仓库
  • 配置GPG签名验证
  • 使用缓存提高效率
  • 配置多镜像源
  • 监控仓库磁盘空间

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息