基于Linux系统的本地Yum源搭建与配置(ISO方式、RPM方式)
sinye56 2024-12-11 16:53 8 浏览 0 评论
前言:
?由于公司业务服务器大部分都在内网环境下运行,内网环境无法直接使用yum安装升级更新软件,所以需要自建Yum源来满足目前日常工作需要。
YUM 常用命令参数:
yum makecache #构建缓存
yum check-update #列出所有可更新的软件清单命令
yum list all #列出所有已安装及可安装的软件包
yum provides ifconfig #列出ifconfig命令是那个软件包提供的
yum grouplist #查询可以用安装的组
yum update #内核升级或者更新所有软件(*谨慎使用*)
yum update nginx #仅更新指定的nginx软件包
yum -y install nginx #安装nginx软件包
yum search nginx #YUM搜索nginx软件包
yum list httpd #显示指定程序包安装情况nginx
yum remove httpd #删除程序包nginx
yum erase httpd #删除程序包httpd
yum update httpd #升级httpd 服务
yum clean all #清除缓存目录下的软件包及旧的 headers
基于ISO系统镜像包来构建本地YUM源:
1.添加YUM源配置文件
[root@centos ~]# cat /etc/yum.repos.d/iso.repo
[ios]
name=iso
baseurl=file:///mnt
enabled=1
gpgcheck=0
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-7 #指定挂载目录下的GPG-KEY文件验证
2.挂载光盘步骤
[root@centos ~]# mount /dev/cdrom /mnt/ #挂载光盘
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos ~]# df -h #查看挂载情况
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 1.6G 18G 8% /
devtmpfs 901M 0 901M 0% /dev
tmpfs 912M 9.0M 903M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda2 197M 121M 77M 62% /boot
tmpfs 183M 0 183M 0% /run/user/0
dev/sr0 4.3G 4.3G 0 100% /mnt #挂载的ISO系统镜像包
3.开启开机自启动挂载
- 方式一:vim /etc/fstab
- 方式二:vim /etc/rc.local
添加内容:/dev/cdrom /mnt iso9660 defaults 0 0
[root@centos ~]# cat /etc/fstab |grep iso9660 #在/etc/fstab文件中添加
/dev/cdrom /mnt iso9660 defaults 0 0
添加内容:/dev/cdrom /mnt
[root@centos ~]# cat /etc/rc.local |grep /mnt #在/etc/rc.local文件中添加
/dev/cdrom /mnt
基于RPM包来构建本地Yum源:
httpd:使用http协议来搭建本地Yum源
createrepo:用于生成yum源各软件之间的依赖索引
yum-utils:安装后可使用 yumdownloader、reposync等命令下载所需软件包
1.下载网络Yum源中的RPM软件包
[root@centos ~]# yum -y install httpd yum-utils createrepo #安装几个必须要的软件包
[root@centos ~]# mkdir /var/www/html/centos6/ #创建RPM软件包下载存放目录
[root@centos ~]# ls /var/www/html/
centos6
[root@centos ~]# ss -antulp | grep :80 #查看httpd服务运行情况(Yum源通过http服务来搭建,需要启动httpd服务)
tcp LISTEN 0 128 :::80 :::* users:(("httpd",1952,6),("httpd",4551,6),("httpd",4552,6),("httpd",4553,6),("httpd",4554,6),("httpd",4555,6),("httpd",4556,6),("httpd",4557,6),("httpd",4558,6))
[root@centos ~]# yum repolist #查看网络Yum源情况(自行配置想要下载的网络Yum源)
Loading mirror speeds from cached hostfile
仓库标识 仓库名称 状态
extras Qcloud centos extras - x86_64 47
os Qcloud centos os - x86_64 6,713
updates Qcloud centos updates - x86_64 1,169
repolist: 7,929
[root@centos ~]# reposync -r extras -p /var/www/html/centos6/ #根据网络Yum源的仓库标识,下载Yum源中的所有RPM软件包到文件夹
[extras: 1 of 47 ] Downloading Packages/bakefile-0.2.8-3.el6.centos.x86_64.rpm
bakefile-0.2.8-3.el6.centos.x86_64.rpm | 250 kB 00:00
[extras: 2 of 47 ] Downloading Packages/centos-release-azure-1.0-2.el6.centos.noarch.rpm
centos-release-azure-1.0-2.el6.centos.noarch.rpm | 4.0 kB 00:00
[extras: 3 of 47 ] Downloading Packages/centos-release-cr-6-0.el6.centos.x86_64.rpm
centos-release-cr-6-0.el6.centos.x86_64.rpm | 3.9 kB 00:00
[extras: 4 of 47 ] Downloading Packages/centos-release-gluster-legacy-3.10-1.el6.centos.noarch.rpm
centos-release-gluster-legacy-3.10-1.el6.centos.noarch.rpm | 4.6 kB 00:00
[extras: 5 of 47 ] Downloading Packages/centos-release-gluster-legacy-4.0-1.el6.centos.noarch.rpm
centos-release-gluster-legacy-4.0-1.el6.centos.noarch.rpm | 4.9 kB 00:00
[extras: 6 of 47 ] Downloading Packages/centos-release-gluster-legacy-4.0-3.el6.centos.noarch.rpm
centos-release-gluster-legacy-4.0-3.el6.centos.noarch.rpm | 5.1 kB 00:00
...
...
[root@vos7 ~]# reposync -r updates -p /var/www/html/centos6/ #下载网络Yum源仓库标识updates中所有的RPM软件包
[updates: 1 of 1169 ] Downloading Packages/389-ds-base-1.2.11.15-97.el6_10.x86_64.rpm
389-ds-base-1.2.11.15-97.el6_10.x86_64.rpm | 1.5 MB 00:00
[updates: 2 of 1169 ] Downloading Packages/389-ds-base-devel-1.2.11.15-97.el6_10.i686.rpm
389-ds-base-devel-1.2.11.15-97.el6_10.i686.rpm | 148 kB 00:00
[updates: 3 of 1169 ] Downloading Packages/389-ds-base-devel-1.2.11.15-97.el6_10.x86_64.rpm
389-ds-base-devel-1.2.11.15-97.el6_10.x86_64.rpm | 148 kB 00:00
[updates: 4 of 1169 ] Downloading Packages/389-ds-base-libs-1.2.11.15-97.el6_10.i686.rpm
389-ds-base-libs-1.2.11.15-97.el6_10.i686.rpm | 450 kB 00:00
[updates: 5 of 1169 ] Downloading Packages/389-ds-base-libs-1.2.11.15-97.el6_10.x86_64.rpm
389-ds-base-libs-1.2.11.15-97.el6_10.x86_64.rpm | 446 kB 00:00
[updates: 6 of 1169 ] Downloading Packages/adcli-0.8.1-3.el6_10.x86_64.rpm
adcli-0.8.1-3.el6_10.x86_64.rpm | 100 kB 00:00
[updates: 7 of 1169 ] Downloading Packages/autofs-5.0.5-140.el6_10.1.x86_64.rpm
autofs-5.0.5-140.el6_10.1.x86_64.rpm | 730 kB 00:00
[updates: 8 of 1169 ] Downloading Packages/autofs-5.0.5-140.el6_10.x86_64.rpm
autofs-5.0.5-140.el6_10.x86_64.rpm | 730 kB 00:00
...
...
2.生成Yum源repodata索引依赖
[root@centos ~]# ll /var/www/html/centos6/ #查看从网络Yum源下载的所有RPM包(会根据仓库标识下载到相关的文件夹)
drwxr-xr-x 3 root root 4096 10月 31 14:28 extras
drwxr-xr-x 3 root root 4096 10月 31 14:28 os
drwxr-xr-x 3 root root 4096 10月 31 13:14 updates
[root@centos ~]# createrepo /var/www/html/centos6/extras/ #生成extras仓库的repodata索引依赖
Spawning worker 0 with 47 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@centos ~]# createrepo /var/www/html/centos6/os/ #生成os仓库的repodata索引依赖
Spawning worker 0 with 6713 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@centos ~]# createrepo /var/www/html/centos6/updates ##生成updates仓库的repodata索引依赖
Spawning worker 0 with 1169 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
?3.在Packages同级目录中可以看到生成的repodata索引目录
[root@centos ~]# ll /var/www/html/centos6/extras/
drwxr-xr-x 2 root root 4096 10月 31 14:28 Packages
drwxr-xr-x 2 root root 4096 10月 31 17:02 repodata
[root@centos ~]# ll /var/www/html/centos6/os/
drwxr-xr-x 2 root root 491520 10月 31 14:59 Packages
drwxr-xr-x 2 root root 4096 10月 31 17:04 repodata
[root@centos ~]# ll /var/www/html/centos6/updates/
drwxr-xr-x 2 root root 102400 10月 31 13:41 Packages
drwxr-xr-x 2 root root 4096 10月 31 17:11 repodata
[root@centos ~]# ll /var/www/html/centos6/extras/repodata/
-rw-r--r-- 1 root root 15328 10月 31 17:02 1ed5ff978f03e8fcf39583179c7f9985dd8750070c91bbe7d1352352ccdd59ee-other.sqlite.bz2
-rw-r--r-- 1 root root 31139 10月 31 17:02 6da60a601f4110345fe68378f9d645de44fd0c15c69920d12158edb117ce6dca-primary.sqlite.bz2
-rw-r--r-- 1 root root 19175 10月 31 17:02 858ad62599b6ab53cec5925757610c9b0c27f9f945e10d83f73649907222b304-filelists.xml.gz
-rw-r--r-- 1 root root 15164 10月 31 17:02 a6e80104250eaf5059025683e2e1a20cfdc5be28ca826f777b5565133c6097e5-primary.xml.gz
-rw-r--r-- 1 root root 26118 10月 31 17:02 ae6f61c5aea047a4dca9ea8a04f9b1cac9a74c93fc97f1691fe109c8d0d07f26-filelists.sqlite.bz2
-rw-r--r-- 1 root root 9129 10月 31 17:02 dd8378435f46ef4730b55355947f224f69d1a16184ddbb4f3cf9aa6f2f459bfc-other.xml.gz
-rw-r--r-- 1 root root 2993 10月 31 17:02 repomd.xml
4.备份原Yum源配置文件,创建新Yum源配置文件
[root@centos ~]# vi /root/centos6.repo
[extras] #yum源的ID,本地唯一,用于区分不同yum源
name=extras #描述信息
baseurl=http://192.168.1.36/centos6/extras #前面的http://是协议,后面的/centos6/extras是yum源包路径
gpgcheck=0 #值为1表示用公钥验证rpm包的正确性,值为0表示不验证
enabled=1 #值为1表示启用yum源,值为0表示禁用yum源
[os]
name=extras
baseurl=http://192.168.1.36/centos6/os
gpgcheck=0
enabled=1
[updates]
name=uodates
baseurl=http://192.168.1.36/centos6/updates
gpgcheck=0
enabled=1
?注意:baseurl 可以使用file 、ftp或http,目录路径要写到Package和repodata的目录。
测试验证自建的本地Yum源
[root@centos ~]# yum clean all
Cleaning repos: extras os updates
清理一切
Cleaning up list of fastest mirrors
[root@centos ~]# yum makecache
Determining fastest mirrors
extras | 2.9 kB 00:00
extras/filelists_db | 26 kB 00:00
extras/primary_db | 30 kB 00:00
extras/other_db | 15 kB 00:00
os | 2.9 kB 00:00
os/filelists_db | 6.4 MB 00:00
os/primary_db | 4.7 MB 00:00
os/other_db | 2.8 MB 00:00
updates | 3.0 kB 00:00
updates/filelists_db | 12 MB 00:00
updates/primary_db | 14 MB 00:00
updates/other_db | 697 kB 00:00
元数据缓存已建立
[root@centos ~]# yum repolist
Loading mirror speeds from cached hostfile
仓库标识 仓库名称 状态
extras extras 47
os extras 6,713
updates uodates 1,169
repolist: 7,929
?可以看到我们基于RPM包来构建的本地Yum源已经完成了。
“点赞+评论+转发”,开启今日暴富!
相关推荐
- linux 查看当前应用内存状况,以及内存参数含义
-
1、查看进程号ps-ef|greptomcat2、查看当前内存分配,200ms打印一次jstat-gc进程号2001jstat-gc344802001S0CS1C...
- 如何显示 Linux 系统上的可用内存?这几个命令很好用!
-
在Linux系统中,了解可用内存是优化系统性能、故障排查以及资源管理的重要一环。本文将详细介绍如何在Linux系统上显示可用内存,包括多种方法和工具的使用。在讨论可用内存之前,我们需要了解一些...
- Linux 下查看内存使用情况方法总结
-
Q:我想监视Linux系统的内存使用情况,在Linux下有哪些视图或者命令行工具可用呢?在做Linux系统优化的时候,物理内存是其中最重要的一方面。自然的,Linux也提供了非常多的方法来监控宝贵的内...
- 2、linux命令-用户管理
-
linux命令-用户管理用户切换[root@eric~]#sueric#切换到用户eric[eric@ericroot]$[eric@ericroot]$su#切换到rootPas...
- Centos 7 进入单用户模式详解
-
1、开机在启动菜单按e进入编辑模式找到linux16行,在最后添加init=/bin/sh编辑完后,按ctrl+x退出2、进单用户模式后,使用passwd修改密码,提示以下错误:passwd:Aut...
- 每日一个Linux命令解析——newusers
-
newusers:在Linux系统中,newusers是一个用于批量创建用户的命令。它从一个文件中读取多行用户信息,每行描述一个用户的详细信息,并根据这些信息创建多个用户或对现有用户进行批量修改。一...
- openEuler操作系统管理员指南:管理用户与用户组
-
在Linux中,每个普通用户都有一个账户,包括用户名、密码和主目录等信息。除此之外,还有一些系统本身创建的特殊用户,它们具有特殊的意义,其中最重要的是管理员账户,默认用户名是root。同时Linux也...
- Linux用户管理
-
1、用户信息文件/etc/passwdroot:x:0:0:root:/root:/bin/bash第一列:用户名第二列:密码位第三列:用户ID0超级用户UID。如果用户UID...
- centos7基础-用户、组、权限管理
-
用户和组(1)用户、组、家目录的概念linux系统支持多用户,除了管理员,其他用户一般不应该使用root,而是应该向管理员申请一个账号。组类似于角色,系统可以通过组对有共性的用户进行统一管理。每个用户...
- LINUX基础 ----------组及用户的概念
-
在Linux中,用户和组都是非常重要的概念,可以控制文件访问权限和资源的管理。用户是标识一个进程、应用程序或系统管理员的账号,Linux中每个用户用一个用户ID(UID)来标识。对于一个...
- 从零入门Linux(四)用户与权限管理
-
在Linux系统中,用户和权限管理是系统安全的重要组成部分。通过合理配置用户和权限,可以确保系统的安全性和资源的合理分配。以下是一些与用户和权限管理相关的常用命令和概念。1.用户管理1.1添加...
- 如何在 Linux 中管理用户?
-
在Linux系统中,用户是系统资源的主要使用者,每个用户都有一个唯一的标识符(用户ID)。为了更好地组织和管理用户,Linux还引入了用户组的概念。用户组是用户的集合,有助于更有效地分配权限和资...
- 在 Linux 中将用户添加到特定组的四种方法
-
在Linux多用户操作系统中,用户组管理是系统安全架构的基石。通过合理的组权限分配,管理员可以实现:精确控制文件访问权限(chmod775project/)简化批量用户权限管理(setfacl-...
- 我不是网管 - 如何在Ubuntu Linux下创建sudo用户
-
Sudo用户是Linux系统的普通用户,具有一定的管理权限,可以对系统执行管理任务。在Linux中,root是超级用户,拥有完全的管理权限,但不建议将root凭证授予其他用户或作为r...
- Linux创建普通用户,为密钥方式登录做准备
-
Hi,我是聪慧苹果8,就是江湖上人见人爱、花见花开,土到掉榨的Linux爱好者,一起学习吧!上一篇关于SSH安全加固的文字,有网友点评通过密钥登录更加安全,先创建一个普通用户,拒绝直接使用密码登录,这...
你 发表评论:
欢迎- 一周热门
- 最近发表
- 标签列表
-
- oracle忘记用户名密码 (59)
- oracle11gr2安装教程 (55)
- mybatis调用oracle存储过程 (67)
- oracle spool的用法 (57)
- oracle asm 磁盘管理 (67)
- 前端 设计模式 (64)
- 前端面试vue (56)
- linux格式化 (55)
- linux图形界面 (62)
- linux文件压缩 (75)
- Linux设置权限 (53)
- linux服务器配置 (62)
- mysql安装linux (71)
- linux启动命令 (59)
- 查看linux磁盘 (72)
- linux用户组 (74)
- linux多线程 (70)
- linux设备驱动 (53)
- linux自启动 (59)
- linux网络命令 (55)
- linux传文件 (60)
- linux打包文件 (58)
- linux查看数据库 (61)
- linux获取ip (64)
- linux进程通信 (63)