《OpenShift / RHEL / DevSecOps 汇总目录》
本文将说明如何构建本地的软件 Repo,以供那些运行在本地且无法直接联网的 RHEL 主机使用。实现方法是在一个可以联网的 RHEL 主机(例如 rhel-repo)中构建本地软件 Repo,然后将其共享给所有无法联网的 RHEL主机使用。
$ yum install httpd -y
$ firewall-cmd --list-services
ssh dhcpv6-client
$ firewall-cmd --add-service=http --permanent
success
$ firewall-cmd --reload
$ firewall-cmd --list-services
ssh dhcpv6-client http
本方法使用下载到本地的 RHEL 安装介质 ISO 文件制作本地共享 Repo。它的特点如下:
优势 :
劣势:
$ chmod +x yumrepoconfig.sh
$ ./yumrepoconfig.sh
$ yum install unzip -y
$ unzip allRepos.zip
$ scp RHEL7-7.9-x86_64-RedHatEnterpriseLinuxServer-0.repo root@rhel-1:/etc/yum.repos.d/
$ yum repolist
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is registered with an entitlement server, but is not receiving updates. You can use subscription-manager to assign subscriptions.
repo id repo name status
RHEL7-7.9-RedHatEnterpriseLinuxServer-DVD0 Red Hat Enterprise Linux 7Server - x86_64 (DVD) 5,230
本方法是在 Repo 主机上使用 reposync 工具直接从 RedHat 官方将订阅中指定 Reop 中包含的软件同步下载到本地,然后再共享给其他 RHEL 主机。
优势 :
劣势:
$ yum install -y yum-utils createrepo
$ subscription-manager repos --enable=rhel-ha-for-rhel-7-server-rpms
$ yum repolist -v
Not loading "rhnplugin" plugin, as it is disabled
Loading "product-id" plugin
Loading "search-disabled-repos" plugin
Loading "subscription-manager" plugin
Updating Subscription Management repositories.
This system is registered with an entitlement server, but is not receiving updates. You can use subscription-manager to assign subscriptions.
Config time: 6.378
Yum version: 3.4.3
Setting up Package Sacks
pkgsack time: 0.013
Repo-id : rhel-7-server-rpms/7Server/x86_64
Repo-name : Red Hat Enterprise Linux 7 Server (RPMs)
Repo-revision: 1704892603
Repo-updated : Wed Jan 10 08:16:43 2024
Repo-pkgs : 34,148
Repo-size : 64 G
Repo-baseurl : https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/os
Repo-expire : 86,400 second(s) (last: Mon Jan 15 11:54:40 2024)
Filter : read-only:present
Repo-filename: /etc/yum.repos.d/redhat.repo
Repo-id : rhel-ha-for-rhel-7-server-rpms/7Server/x86_64
Repo-name : Red Hat Enterprise Linux High Availability (for RHEL 7 Server) (RPMs)
Repo-revision: 1704710878
Repo-updated : Mon Jan 8 05:47:58 2024
Repo-pkgs : 865
Repo-size : 1.5 G
Repo-baseurl : https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/highavailability/os
Repo-expire : 86,400 second(s) (last: Mon Jan 15 11:54:41 2024)
Filter : read-only:present
Repo-filename: /etc/yum.repos.d/redhat.repo
repolist: 35,013
$ HTTP_DOC_ROOT=/var/www/html
$ mkdir -p $HTTP_DOC_ROOT/repos/rhel7
$ reposync -m --download-metadata --gpgcheck -p $HTTP_DOC_ROOT/repos/rhel7 --repoid=rhel-ha-for-rhel-7-server-rpms
$ createrepo $HTTP_DOC_ROOT/repos/rhel7/rhel-ha-for-rhel-7-server-rpms
如果索引已有,则可更新索引。
$ createrepo --update $HTTP_DOC_ROOT/repos/rhel7/rhel-ha-for-rhel-7-server-rpms
$ chcon -R -t httpd_sys_content_t /var/www/html
$ firewall-cmd --add-service=http --permanent
$ firewall-cmd --reload
$ cat << EOF > /etc/yum.repos.d/rhel-ha-for-rhel-7-server.repo
[rhel-ha-for-rhel-7-server]
name=rhel-ha-for-rhel-7-server
baseurl=http://192.168.1.100/repo/rhel7/rhel-ha-for-rhel-7-server-rpms
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
EOF
$ yum repolist
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is registered with an entitlement server, but is not receiving updates. You can use subscription-manager to assign subscriptions.
repo id repo name status
rhel-ha-for-rhel-7-server rhel-ha-for-rhel-7-server 865
repolist: 865
此方法类似“方法2”,只能制作和 Repo 节点具有相同 RHEL 主版本的 Repo。和“方法2” 的区别是本方法可针对特定次要版本的 RHEL 中包含所的特定软件包、CVE、RHSA/RHBA/RHEA 制作对应的 Repo。
$ yum install -y yum-utils createrepo
$ mkdir /var/tmp/httpd
$ mkdir /var/tmp/httpd-installroot
$ yum install --downloadonly --installroot=/var/tmp/httpd-installroot --releasever=7.9 --downloaddir=/var/tmp/httpd httpd
$ createrepo --database /var/tmp/httpd
$ tar zcvf httpd.tar.gz /var/tmp/httpd
$ tar zxvf httpd.tar.gz
$ cat << EOF | tee /etc/yum.repos.d/offline-httpd.repo
[offline-httpd]
name=rhel-$releasever - httpd
baseurl=file:///var/tmp/httpd
enabled=1
gpgcheck=0
EOF
$ yum install --disablerepo=\* --enablerepo=offline-httpd httpd
RedHat Satellite 具备以上方法1/2/3 所包含的全部优势,即可在单节点(考虑到可靠性,可以是双机部署)同时提供个多个主次版本的 RHEL 和其相关附加软件的 Repo,因此优势最为明显。使用方法参见:
Red Hat Satellite - 为主机配置可使用的内容(存储库),注册主机并安装软件包
https://access.redhat.com/solutions/29269
https://access.redhat.com/solutions/7227
https://access.redhat.com/solutions/23016
https://access.redhat.com/solutions/7019225
https://access.redhat.com/zh_CN/solutions/7045415
https://access.redhat.com/solutions/3459631
https://access.redhat.com/discussions/4358851
https://access.redhat.com/documentation/zh-cn/red_hat_ansible_automation_platform/2.3/html-single/red_hat_ansible_automation_platform_installation_guide/index#proc-synchronizing-rpm-repositories-by-using-reposync_disconnected-installation
https://www.cnblogs.com/vilenx/p/12533361.html