首页 > 其他分享 >RHEL 7创建本地安装源

RHEL 7创建本地安装源

时间:2024-05-29 14:23:19浏览次数:19  
标签:00 -- 创建 repos nginx RHEL 本地 rpms rhel

声明

受限于网络环境和网络速度的影响,我们很多时候需要更加便捷的下载软件包的方式,那么创建一个不受网络因素影响的本地安装源就很有必要。本文档所有使用的账号为个人红帽开发者账号,所有安装的包以及工具或是红帽提供的安装包,或是GIT HUB上的开源项目,请大家在能力范围内积极支持正版。

安装操作系统

1、加载镜像后选择 Install Red Hat Enterprise Linux 7.9

image

2、语言选择中文(看个人习惯,安装数据库最好默认选英文)

image

3、总览需要配置的项

image

4、时区选择亚洲-上海

image

5、软件选择 最小安装

image

6、分区选择 先选择磁盘后再选择我要配置分区

image

一般情况下,没特殊要求可以选择自动分区,如果有需求知道数据具体存放在哪里,可以指定特定的分区,比如下面的/repos就是手动创建的

image

7、配置网络和主机名,选择一定连接的网卡,点击右下角的配置,选择IPv4设置,手动配置网络后,打开网卡,修改主机名

image

8、上述都配置好后,点击开始安装开始安装操作系统

image

9、配置root用户密码并创建新用户

image

10、等待系统安装完成后,重启操作系统

image

注册开发者账号

1、登录红帽开发者网站注册账号 https://developers.redhat.com/后即可成为红帽开发者一员,可以获得红帽操作系统1年的临时使用权限。

2、注册成功后,在已经安装好的红帽操作系统中使用subscription-manager register --username=username --password=password --auto-attach即可将当前系统资源添加至红帽账户。

3、注册成功后可以通过subscription-manager list查看系统的激活信息

[root@rhel ~]# subscription-manager list
+-------------------------------------------+
    Installed Product Status
+-------------------------------------------+
Product Name:   Red Hat Enterprise Linux Server
Product ID:     69
Version:        7.9
Arch:           x86_64
Status:         Subscribed
Status Details:
Starts:         03/05/2024
Ends:           03/05/2025

安装依赖包

安装工具包

reposync -- 同步rpm包工具

该命令用于rpm的同步,其中RHEL 6和7 版本需要的reposync命令需要单独安装rpm包: yum-utils,RHEL 8 版本则是集成在dnf命令中。

createrepo --创建软件仓库工具

该包用于同步完软件包后,创建本地源用。

nginx -- web服务

通过nginx可以使本地的源文件供内网中可以和本机通信的机器使用。

  1. 创建nginx安装源

    [root@rhel ~]# cat >> /etc/yum.repos.d/nginx.repo << EOF
    [nginx-stable]
    name=nginx stable repo
    baseurl=http://nginx.org/packages/rhel/\$releasever/\$basearch/
    gpgcheck=1
    enabled=1
    gpgkey=https://nginx.org/keys/nginx_signing.key
    module_hotfixes=true
    EOF
    
  2. 安装nginx最新版本

    [root@rhel ~]# yum install nginx
    Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
    nginx-stable                                                                                                                                                          | 2.9 kB  00:00:00
    nginx-stable/7Server/x86_64/primary_db                                                                                                                                |  87 kB  00:00:00
    Resolving Dependencies
    --> Running transaction check
    ---> Package nginx.x86_64 1:1.24.0-1.el7.ngx will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    =============================================================================================================================================================================================
     Package                                 Arch                                     Version                                               Repository                                      Size
    =============================================================================================================================================================================================
    Installing:
     nginx                                   x86_64                                   1:1.24.0-1.el7.ngx                                    nginx-stable                                   804 k
    
    Transaction Summary
    =============================================================================================================================================================================================
    Install  1 Package
    
    Total download size: 804 k
    Installed size: 2.8 M
    Is this ok [y/d/N]: y
    Downloading packages:
    warning: /var/cache/yum/x86_64/7Server/nginx-stable/packages/nginx-1.24.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 7bd9bf62: NOKEY-    ] 137 kB/s | 756 kB  00:00:00 ETA
    Public key for nginx-1.24.0-1.el7.ngx.x86_64.rpm is not installed
    nginx-1.24.0-1.el7.ngx.x86_64.rpm                                                                                                                                     | 804 kB  00:00:04
    Retrieving key from https://nginx.org/keys/nginx_signing.key
    Importing GPG key 0x7BD9BF62:
     Userid     : "nginx signing key <[email protected]>"
     Fingerprint: 573b fd6b 3d8f bc64 1079 a6ab abf5 bd82 7bd9 bf62
     From       : https://nginx.org/keys/nginx_signing.key
    Is this ok [y/N]: y
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : 1:nginx-1.24.0-1.el7.ngx.x86_64                                                                                                                                           1/1
    ----------------------------------------------------------------------
    
    Thanks for using nginx!
    
    Please find the official documentation for nginx here:
    * https://nginx.org/en/docs/
    
    Please subscribe to nginx-announce mailing list to get
    the most important news about nginx:
    * https://nginx.org/en/support.html
    
    Commercial subscriptions for nginx are available on:
    * https://nginx.com/products/
    
    ----------------------------------------------------------------------
      Verifying  : 1:nginx-1.24.0-1.el7.ngx.x86_64                                                                                                                                           1/1
    
    Installed:
      nginx.x86_64 1:1.24.0-1.el7.ngx
    
    Complete!
    

同步软件包

查看所有可用的软件仓库

使用yum repolist all可以查看当前账户可以使用的软件仓库,默认情况下只会启用rhel-7-server-rpms/7Server/x86_64这一个软件仓库。

下面是展示出来的部分内容。可以在实际操作中选择其他臁仓库启用。

[root@rhel ~]# yum repolist all
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
repo id                                                                      status
a-mq-clients-1-for-rhel-7-server-debug-rpms/7Server/x86_64                   disabled
a-mq-clients-1-for-rhel-7-server-rpms/7Server/x86_64                         disabled
a-mq-clients-1-for-rhel-7-server-source-rpms/7Server/x86_64                  disabled
rhel-ha-for-rhel-7-server-rpms/7Server/x86_64                                disabled
rhel-7-server-extras-rpms/x86_64                                             enabled:  1,468
...
rhel-7-server-rpms/7Server/x86_64                                            enabled: 34,270
...
repolist: 36,603

启用停用软件仓库

[root@repos ~]# subscription-manager repos --enable=rhel-7-server-extras-rpms
为这个系统启用软件仓库 'rhel-7-server-extras-rpms'。
[root@repos ~]# subscription-manager repos --disable=rhel-7-server-extras-rpms
为这个系统停用软件仓库 'rhel-7-server-extras-rpms'。

同步软件包到本地

使用命令reposync --plugins --newest-only --delete --download_path=$download_path --repoid=rhel-7-server-rpms 可以同步单个软件源到本地,如果需要同步多个软件源,可以创建一个shell脚本如下:

#!/bin/bash
 
#定义下载回来的包存放的目录
download_path="/repos"
 
reposync --plugins --newest-only --delete --download_path=$download_path --downloadcomps --repoid=rhel-7-server-rpms
reposync --plugins --newest-only --delete --download_path=$download_path --downloadcomps --repoid=rhel-7-server-extras-rpms
reposync --plugins --newest-only --delete --download_path=$download_path --downloadcomps --repoid=rhel-ha-for-rhel-7-server-rpms
 
#--plugins              启用yum插件支持
#--newest-only          每次回购仅下载最新的软件包。
#--download_path        软件包存放地址
#--repoid               需要下载的仓库ID

同步成功后会在指定的目录下生成如下的目录结构,一个comps.xml的文件,一个包含下载的所有包的Packahes目录。

[root@rheloracle home]# tree /repos/
repos
└── rhel-7-server-rpms
    ├── comps.xml
    └── Packages
        ├── 3
        │   ├──···.rpm
        ├── a
        │   ├──···.rpm
        ...
        └── z
        │   ├──···.rpm

29 directories 5515 files

创建本地仓库

进入到下载本地的repo id的目录下,使用createrepo命令将下载到本地的软件包创建成软件仓库

[root@rhel ~]# cd /repos/rhel-7-server-rpms/
[root@rhel rhel-7-server-rpms]# ls
comps.xml  Packages
[root@rhel rhel-7-server-rpms]# createrepo -g comps.xml .
Spawning worker 0 with 2757 pkgs
Spawning worker 1 with 2757 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

创建本地安装源

[root@rhel ~]# cat >> /etc/yum.repos.d/rhel7-local.repo << EOF
[rhel7-local]
name=rhel7-local
baseurl=file:///repos/rhel-7-server-rpms/  # 按照实际本地存储路径填写
enabled=1
gpgcheck=0 
EOF

查看当前可用的安装源

[root@rhel ~]# yum repolist
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
repo id                                                                        repo name                                                                                               status
nginx-stable/7Server/x86_64                                                    nginx stable repo                                                                                          324
rhel-7-server-rpms/7Server/x86_64                                              Red Hat Enterprise Linux 7 Server (RPMs)                                                                34,270
rhel-ha-for-rhel-7-server-rpms/7Server/x86_64                                  Red Hat Enterprise Linux High Availability (for RHEL 7 Server) (RPMs)                                      865
repolist: 35,459

禁用网络源

[root@rhel ~]# subscription-manager repos --disable=rhel-7-server-rpms
Repository 'rhel-7-server-rpms' is disabled for this system.
[root@rhel ~]# subscription-manager repos --disable=rhel-ha-for-rhel-7-server-rpms
Repository 'rhel-ha-for-rhel-7-server-rpms' is disabled for this system.

清理旧缓存并创建新缓存

[root@rhel ~]# yum clean all
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
Cleaning repos: nginx-stable rhel7-local
Other repos take up 1.3 G of disk space (use --verbose for details)
[root@rhel ~]# yum makecache
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
nginx-stable                                                                                                                                                          | 2.9 kB  00:00:00
rhel7-local                                                                                                                                                           | 3.6 kB  00:00:00
(1/7): nginx-stable/7Server/x86_64/primary_db                                                                                                                         |  87 kB  00:00:00
(2/7): nginx-stable/7Server/x86_64/filelists_db                                                                                                                       | 112 kB  00:00:00
(3/7): rhel7-local/group_gz                                                                                                                                           | 138 kB  00:00:00
(4/7): rhel7-local/primary_db                                                                                                                                         | 4.5 MB  00:00:00
(5/7): rhel7-local/filelists_db                                                                                                                                       | 3.7 MB  00:00:00
(6/7): rhel7-local/other_db                                                                                                                                           | 1.6 MB  00:00:00
(7/7): nginx-stable/7Server/x86_64/other_db                                                                                                                           |  53 kB  00:00:00
Metadata Cache Created

以上,本地源可以使用,如果只需要本地使用上面的部分就够了

如果需要通过局域网内使用,则需要继续下面的操作。

firewalld防火墙放行与禁用

由于启用了防火墙需要放行80端口或http服务,或者停用防火墙,一般为了安全考虑放行端口和服务比较好

[root@repos ~]# firewall-cmd --permanent --add-port=80/tcp
success
[root@repos ~]# firewall-cmd --permanent --add-service=http
success

禁用端口或服务

[root@repos ~]# firewall-cmd --permanent --remove-port=80/tcp
success
[root@repos ~]# firewall-cmd --permanent --remove-service=http
success

修改需要重新加载才能生效

[root@repos ~]# firewall-cmd --reload    
success

启用nginx代理

编辑/etc/nginx/conf.d/default.conf文件,将下面的部分按照实际情况进行修改

location / {
        root   /repos/;					//指定实际目录绝对路径;
        autoindex on;					//开启目录浏览功能;
        autoindex_exact_size off;		//关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为b;
        autoindex_localtime on;			//开启以服务器本地时区显示文件修改日期!
        charset utf-8,gbk;				// 开启中文文件名称展示
        index  index.html index.htm;
    }

启用nginx服务:systemctl start nginx

配置nginx服务开机启动:systemctl enable nginx

image

访问http://本机IP地址

image

创建网络安装源并测试

创建网络安装源

[root@rhel ~]# cat >> /etc/yum.repos.d/rhel7-net.repo << EOF
[rhel7-net]
name=rhel7-net
baseurl=http://10.60.99.46/rhel-7-server-rpms/	# 按实际数据填写
enabled=1
gpgcheck=0
EOF
[root@rhel ~]# yum makecache
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
nginx-stable                                                                                                                                                          | 2.9 kB  00:00:00
rhel7-net                                                                                                                                                             | 3.6 kB  00:00:00
(1/7): nginx-stable/7Server/x86_64/primary_db                                                                                                                         |  87 kB  00:00:00
(2/7): rhel7-net/group_gz                                                                                                                                             | 138 kB  00:00:00
(3/7): rhel7-net/primary_db                                                                                                                                           | 4.5 MB  00:00:00
(4/7): rhel7-net/filelists_db                                                                                                                                         | 3.7 MB  00:00:00
(5/7): rhel7-net/other_db                                                                                                                                             | 1.6 MB  00:00:00
(6/7): nginx-stable/7Server/x86_64/other_db                                                                                                                           |  53 kB  00:00:00
(7/7): nginx-stable/7Server/x86_64/filelists_db                                                                                                                       | 112 kB  00:00:01
Metadata Cache Created

在其他网络可通信的主机上,创建上述中rhel7-net.repo文件并建立缓存测试,是否可用

标签:00,--,创建,repos,nginx,RHEL,本地,rpms,rhel
From: https://www.cnblogs.com/xie96-blog/p/18220166

相关文章

  • 10. 创建管理表课后练习
    #1.创建数据库test01_office,指明字符集为utf8。并在此数据库下执行下述操作createdatabaseifnotexiststest01_officecharacterset'utf8';#2.创建表dept81/*字段类型idINT(7)NAMEVARCHAR(25)类型*/usetest01_office;createt......
  • 有向图的创建以及遍历
    有向图的创建有很多种方法,这里简要介绍邻接表的创建,以及通过邻接表创建的有向图进行深度优先算法以及广度优先算法可以先看看,具体文件的格式,大家想要实现的话,需要在桌面上创建一个txt格式的文件,然后将其命名为linjiebiao57v1v2v3v4v501031423243240文件......
  • cesium实现动态创建广告牌
    import{globalColorList,globalTextColorList}from"../js/positionTools.js";/***广告牌设备图标函数类*/exportdefaultclassDeviceMarker{constructor(arg){}/***初始化广告牌*@param{*}text文字*@param{*}iconType图表类型*......
  • IDEA 创建 JavaFX 工程
    JavaFX下载安装1.检查本机JDK版本CMD命令行窗口输入java--version查询JDK版本,如下:C:\Users\Administrator>java--versionjava17.0.92023-10-17LTSJava(TM)SERuntimeEnvironment(build17.0.9+11-LTS-201)JavaHotSpot(TM)64-BitServerVM(build17.0.9+......
  • 《第二节》一、FreeRTOS学习笔记-任务创建和删除
    FreeRTOS的任务创建和删除1,任务创建和删除的API函数(熟悉)任务的创建和删除本质就是调用FreeRTOS的API函数一、任务创建动态创建任务:任务的任务控制块以及任务的栈空间所需的内存,均由FreeRTOS从FreeRTOS管理的堆中分配静态创建任务:任务的任务控制块以及任务的栈空间所需......
  • Unity玩家本地得分排名系统的制作
    UI的制作首先,我们建一个新的场景把他命名为Scoring,在Scoring场景导入积分面板资源25.3(资源下载放在置顶了)并设置渲染摄像机,在游戏结束时我们将切换到这个场景。配置好将看到如下界面,资源来自biliup阿严Dev其次,制作button按钮即返回主菜单功能,只需在ScoringUI——Scori......
  • Django学习-虚拟环境创建、URL组成部分详解
    一、创建一个Django的虚拟环境 生成虚拟环境在D:\Virtualenvs下 在pycharm中引入django虚拟环境 二、URL详解 URL,统一资源定位符,一个URL由以下几部分组成:scheme://host:port/path/?query-string=xxx#anchorscheme:代表的是访问的协议,一般为http或者https以及ftp等h......
  • 4 SAP前台操作手册-MM模块-采购管理-采购申请创建、修改、显示-ME51N ME52N ME53N
    0总体说明SAP实施项目中,到了第3个阶段-系统实现,在这个阶段,因为蓝图汇报已经结束,配置也差不多完成了,自开发还在进行中,SAP标准功能下,可以进行基础业务的前台操作了,在实现阶段的尾端,客户指定的关键用户(俗称KU-KeyUser)会进行前台业务操作和练习,提高熟练程度,同时需要在外部SAP顾......
  • 2 SAP前台操作手册-MM模块-采购管理-(标准/委外/寄售)采购信息记录创建、修改、显示、
    0总体说明SAP实施项目中,到了第3个阶段-系统实现,在这个阶段,因为蓝图汇报已经结束,配置也差不多完成了,自开发还在进行中,SAP标准功能下,可以进行基础业务的前台操作了,在实现阶段的尾端,客户指定的关键用户(俗称KU-KeyUser)会进行前台业务操作和练习,提高熟练程度,同时需要在外部SAP顾......
  • 在 Cognex VisionPro CogRecordDisplay 中创建交互式矩形区域
    在CognexVisionProCogRecordDisplay中创建交互式矩形区域在图像处理和视觉检测应用中,定义和操作特定区域是至关重要的。本文将演示如何在CognexVisionPro中使用C#创建一个可交互的矩形区域,并启用拖拽和调整大小功能,从而提升图像处理的灵活性和效率。前提条件安......