Redhat8 yum源內網部署

hellohf123發表於2023-10-31

Redhat8 內部yum源部署手冊

1 Yum 服務概述

Yum (全稱 Yellow Dog Updater)是一個在 Fedora 和 RedHat 以及 CentOS 中的 Shell 前端軟體包管理器。基於 RPM 包管理,能夠從指定的伺服器自動下載RPM包並且安裝,可以自動處理依賴性關係,並且一次安裝所有依賴的軟體包.

2 、搭建Redhat 8 源伺服器

2.1 使用 VDC 對虛擬化環境的 redhat 服務進行註冊

        主要流程:

1、   選擇一臺可以聯網的 RHEL 虛擬機器,在其上安裝 virt-who 軟體包,並配置 virt-who 服務。

 

安裝 virt-who 軟體包可以透過掛載 ISO 映象,配置本地 yum 源進行安裝:

[root@yumserver8 ~]# yum install virt-who

 

2、   配置 virt-who 服務,需要您建立並編輯如下檔案 :

[root@yumserver8 ~]# cat   /etc/virt-who.d/virt-who.conf

[vmware]

type=esx

server=10.xx.xx.13

username=administrator@vsphere.local

password=77b6513b6baf65d0b4e858a6d5bea92c1f4c7b21d697dafb895e6e34da940597

owner=17xxx593

env=Library

hypervisor_id=hostname

 

注:實際vcenter 密碼錯誤也不會影響

 

# vim /etc/virt-who.d/virt-who.conf

[vmware]

type=esx

server=[vCenter.domain.com] [1]

username=[vCenterusername]  [2]

password=[vCenterpassword]  [3]

owner=[org ID]              [4]

env=Library

hypervisor_id=hostname

 

[1][2][3][4] 處需要您根據實際情況修改:

 

[1] 處請替換問 VCenter 的域名或IP,[2]處替換為 VCenter 具有管理員許可權的賬戶名,[3]處替換為[2]處使用者名稱所對應的密碼。

[4] 處請在 RHEL 虛擬機器執行如下命令來獲取 org ID(會需要您輸入登入客戶入口網站時使用者名稱和密碼):

 

# subscription-manager register

[root@yumserver8 ~]#   subscription-manager register

Registering to:   subscription.rhsm.redhat.com:443/subscription

Username: nixxd

Password:

The system has been registered with ID:   4e3b164c-1151-4f2b-aa03-4fee80b03f71

The registered system name is:   yumserver8

[root@yumserver8 ~]#

 

# subscription-manager identity

[root@yumserver8 ~]#   subscription-manager identity

system identity:   4e3b164c-1151-4f2b-aa03-4fee80b03f71

name: yumserver8

org name: 17xxx593

org ID: 17xxx593

[root@yumserver8 ~]#

 

 

如何使用加密密碼配置virt-who
# virt-who-password
#password:(在此處輸入字元後系統返回字串,填入[3])

[root@yumserver8 ~]# virt-who-password

Password:

Use following as value for   encrypted_password key in the configuration file:

77b6513b6baf65d0b4e858a6d5bea92c1f4c7b21d697dafb895e6e34da940597

[root@yumserver8 ~]#


3 、完畢後,請執行如下命令開啟 virt-who 服務:

 

[root@yumserver8 ~]# systemctl start   virt-who

[root@yumserver8 ~]#  systemctl enable virt-who

 

4 、在此之後,如果 virt-who 配置正確,此服務會將 VCenter 中的宿主機的資訊對映到我們的客戶入口網站,然後您需要登入客戶入口網站為宿主機附加上 Physical 型別的 VDC 訂閱,附加完畢後,會自動解鎖 Virtual 型別的 VDC 訂閱供虛擬機器使用。

 


 

5、 最後,使用如下命令檢視註冊狀態:

 

[root@yumserver8 ~]#   subscription-manager  status

+-------------------------------------------+

     System Status Details

+-------------------------------------------+

Overall Status: Disabled

Content Access Mode is set to Simple   Content Access. This host has access to content, regardless of subscription   status.

 

System Purpose Status: Disabled

 

[root@yumserver8 ~]#

 

6、 最後,檢視yum源狀態並嘗試用紅帽yum源安裝一個軟體測試一下

[root@yumserver8 ~]# yum repolist enabled

Updating Subscription Management   repositories.

repo id                                                           repo name

rhel-8-for-x86_64-appstream-rpms                                Red Hat   Enterprise Linux 8 for x86_64 - AppStream (RPMs)

rhel-8-for-x86_64-baseos-rpms                                   Red Hat   Enterprise Linux 8 for x86_64 - BaseOS (RPMs)

 

[root@yumserver8 ~]# yum install   net-tools

測試安裝ok

 

2.2 搭建內部 Yum 源同步 Redhat

2.2.1 、檢視系統版本.

[root@yumserver8 ~]# cat   /etc/redhat-release

Red Hat Enterprise Linux release 8.5   (Ootpa)

 

2.2.2 、放開系統防火牆, 關閉selinux

(為部署httpd服務準備)

[root@yumserver8 yum.repos.d]#   firewall-cmd --add-port=80/tcp --permanent

success

[root@yumserver8 yum.repos.d]#  firewall-cmd --reload

success

[root@yumserver8 yum.repos.d]#  firewall-cmd  --list-ports

80/tcp

 

 

[root@yumserver8 ~]# cat   /etc/selinux/config

 

# This file controls the state of SELinux   on the system.

# SELINUX= can take one of these three   values:

#       enforcing - SELinux security   policy is enforced.

#       permissive - SELinux prints warnings instead of enforcing.

#       disabled - No SELinux policy is loaded.

SELINUX= permissive

# SELINUXTYPE= can take one of these   three values:

#       targeted - Targeted processes are protected,

#       minimum - Modification of targeted policy. Only selected processes are   protected.

#       mls - Multi Level Security protection.

SELINUXTYPE=targeted

  

2.2.3 、安裝相關軟體

[root@yumserver8 ~]# yum install -y wget   make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel httpd   yum-utils

 

2.2.4 、指定目錄同步紅帽yum 源軟體包

指定目錄/mirror(自定義目錄)

Redhat8 不用createrepo了,直接用reposync,所有都搞定了

reposync -p /mirror   --download-metadata --repoid=rhel-8-for-x86_64-appstream-rpms

reposync -p /mirror   --download-metadata --repoid=rhel-8-for-x86_64-baseos-rpms

實際包大概有30000+個,時間有點久

 

2.3 啟動並配置 Apache 服務

配置httpd服務,找到/etc/httpd/conf/httpd.conf中的DocumentRoot,並新增以下的內:

 

 

[root@yumserver8   ~]# cat /etc/httpd/conf/httpd.conf

#DocumentRoot   "/var/www/html"

DocumentRoot   "/mirror/"

<Directory   "/mirror/">

        Options Indexes FollowSymLinks

        AllowOverride  None

        Order allow,deny

        Allow from all

        Require all granted

</Directory>

#

#   Relax access to content within /var/www.

 

[root@yumserver8   ~]# systemctl start httpd

[root@yumserver8   ~]# systemctl enable httpd

Created   symlink /etc/systemd/system/multi-user.target.wants/httpd.service →   /usr/lib/systemd/system/httpd.service.

[root@yumserver8   ~]# systemctl status  httpd

 

### 修改 Apache 預設首頁 index.html

cat << EOF   > /usr/share/httpd/noindex/index.html

<!DOCTYPE   html>

<html>

<head>

<meta   charset="utf-8">

<title>Redhat   8 映象</title>

<script>document.createElement("myHero")</script>

<style>

myHero {

        display: block;

        background-color: #ddd;

        padding: 10px;

        font-size: 20px;

}

</style>

</head>

<body>

    <h1> 簡介</h1>

    <hr>

    <p>Redhat ,是基於 Red Hat Linux 提供的企業級 Linux 發行版本。</p>

    <hr>

    <br>

    <br>

        <h1> Redhat 8 配置內部YUM </h1>

    <br>

        <h2>1 、備份</h2>

        <myHero>mkdir   /etc/yum.repos.d/backup </myHero>

        <myHero>mv   /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/</myHero>

    <br>

        <h2>2 、下載新的 redhat.repo     /etc/yum.repos.d/ </h2>

        <myHero>curl -o /etc/yum.repos.d/redhat.repo   http:/ /x.x.x.x/repo/ redhat.repo</myHero>

        

    <br>

        <h2>3 、執行 yum makecache 生成快取</h2>

    <br>

        <h2>4 、執行 yum repolist   檢視已經生成快取</h2>

    <br>

    <br>

</body>

</html>

EOF

在瀏覽器輸入: 即可訪問客戶端升級方法

2.4 編寫 yum 源客戶端檔案

2.4.1 Redhat8 檔案配置

[root@yumserver8 repo]# cat   /mirror/repo/redhat.repo

[AppStream]

name=AppStream

baseurl= http xxxxxxxxx/rhel-8-for-x86_64-appstream-rpms/

enable=1

gpgcheck=0

 

[BaseOS]

name=BaseOS

baseurl= http xxxxxxxxx/ rhel-8-for-x86_64-baseos-rpms/

enable=1

gpgcheck=0

 


3 redhat 客戶端測試

再需要配置的客戶端上操作。

mkdir /etc/yum.repos.d/backup

mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/

curl -o /etc/yum.repos.d/redhat.repo

 

[root@yum8test ~]# yum repolist all

Updating Subscription Management   repositories.

Unable to read consumer identity

 

This system is not registered with an   entitlement server. You can use subscription-manager to register.

 

repo id                                                        repo name                                                       status

AppStream                                                      AppStream                                                       enabled

BaseOS                                                         BaseOS                                                          enabled

 

 

[root@yum8test yum.repos.d]# yum install   net-tools

測試 ok


4 、配置定時任務

### 配置指令碼 ###

[root@yumserver8 mirror]# mkdir -p   /var/log/yumupdatelog/

 

[root@yumserver8 mirror]# cat   /mirror/redhat_yum_update.sh

#!/bin/bash

echo 'Updating Redhat Source'

DATETIME=`date +%F_%T`

exec >   /var/log/yumupdatelog/Redhat_$DATETIME.log

reposync -p /mirror --download-metadata   --repoid=rhel-8-for-x86_64-appstream-rpms

reposync -p /mirror --download-metadata   --repoid=rhel-8-for-x86_64-baseos-rpms

if [ $? -eq 0 ];then

      echo "SUCESS: $DATETIME Redhat_yum update successful"

      else

       echo "ERROR: $DATETIME Redhat_yum update failed"

      fi

[root@yumserver8 mirror]#

 

### 新增定時任務 ### 每週一凌晨 1 點執行

[root@yumserver8 mirror]# crontab -l

0 1 * * 1 /bin/bash /mirror/redhat_yum_update.sh

 


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70004783/viewspace-2992107/,如需轉載,請註明出處,否則將追究法律責任。

相關文章