linux7.2 安装yum源,CentOS7.2 创建本地YUM源和局域网YUM源

1背景

由于开发环境只有局域网,没法使用网上的各种YUM源,来回拷贝rpm包安装麻烦,还得解决依赖问题。想着在CentOS7.2搭建个本地/局域网YUM源,方便自己跟同事安装软件。

2环境

[root@linuxidc.com ~]# cat /etc/RedHat-release

CentOS Linux release7.2.1511 (Core)

并且是Minimal Install。

3安装

3.1本地YUM源

3.1.1 ISO源

准备rpm包

挂载CentOS-7-x86_64-Everything-1511.iso,把里面所有文件都拷贝到本地目录/yum/yum-iso

[root@linuxidc.com ~]# mkdir /mnt/yum-iso

[root@linuxidc.com ~]# mount /dev/cdrom /mnt/yum-iso/

mount: /dev/sr0 is write-protected, mounting read-only

[root@linuxidc.com ~]# mkdir /yum/[root@linuxidc.com ~]# cp -a /mnt/yum-iso/ /yum/[root@linuxidc.com ~]# ll /yum/total4dr-xr-xr-x. 8 root root 4096 Dec 10 2015 yum-iso

[root@linuxidc.com ~]# ll /yum/yum-iso/total640

-r--r--r--. 1 root root 14 Dec 10 2015CentOS_BuildTag

dr-xr-xr-x. 3 root root 33 Dec 10 2015EFI-r--r--r--. 1 root root 215 Dec 10 2015EULA-r--r--r--. 1 root root 18009 Dec 10 2015GPL

dr-xr-xr-x. 3 root root 69 Dec 10 2015images

dr-xr-xr-x. 2 root root 4096 Dec 10 2015isolinux

dr-xr-xr-x. 2 root root 41 Dec 10 2015LiveOS

dr-xr-xr-x. 2 root root 483328 Dec 10 2015Packages

dr-xr-xr-x. 2 root root 4096 Dec 10 2015repodata-r--r--r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7

-r--r--r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7

-r--r--r--. 1 root root 2883 Dec 10 2015TRANS.TBL

[root@linuxidc.com ~]#

备份、移除其他repo

[root@linuxidc.com ~]# cd /etc/yum.repos.d/[root@linuxidc.com yum.repos.d]# ll-rw-r--r--. 1 root root 1664 Dec 9 2015 CentOS-Base.repo-rw-r--r--. 1 root root 1309 Dec 9 2015 CentOS-CR.repo-rw-r--r--. 1 root root 649 Dec 9 2015 CentOS-Debuginfo.repo-rw-r--r--. 1 root root 290 Dec 9 2015 CentOS-fasttrack.repo-rw-r--r--. 1 root root 630 Dec 9 2015 CentOS-Media.repo-rw-r--r--. 1 root root 1331 Dec 9 2015 CentOS-Sources.repo-rw-r--r--. 1 root root 1952 Dec 9 2015 CentOS-Vault.repo

[root@linuxidc.com yum.repos.d]# tar zcvf repo-bk.tar.gz CentOS-*CentOS-Base.repo

CentOS-CR.repo

CentOS-Debuginfo.repo

CentOS-fasttrack.repo

CentOS-Media.repo

CentOS-Sources.repo

CentOS-Vault.repo

[root@linuxidc.com yum.repos.d]# rm -f CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Sources.repo CentOS-Vault.repo

配置本地repo

[root@linuxidc.com yum.repos.d]# vi CentOS-Media.repo

填入如下内容

[c7-media]

name=CentOS-$releasever -Media

baseurl=file:///yum/yum-iso/

gpgcheck=0enabled=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

注释:配置repo路径、关闭gbp校验、启用这个repo

制作cache

[root@linuxidc.com yum.repos.d]# yumclean all

Loaded plugins: fastestmirror

Cleaning repos: c7-media

Cleaning up everything

Cleaning up list of fastest mirrors

[root@linuxidc.com yum.repos.d]# yummakecache

Loaded plugins: fastestmirror

c7-media | 3.6 kB 00:00:00(1/4): c7-media/group_gz | 155 kB 00:00:00(2/4): c7-media/primary_db | 5.3 MB 00:00:00(3/4): c7-media/filelists_db | 6.2 MB 00:00:00(4/4): c7-media/other_db | 2.3 MB 00:00:00Determining fastest mirrors

Metadata Cache Created

[root@linuxidc.com yum.repos.d]#

这样就可以使用yum安装软件啦

[root@linuxidc.com yum.repos.d]# yum groupinstall "Development tools"Loaded plugins: fastestmirror

There is no installedgroups file.

Maybe run:yum groups mark convert (see man yum)

Loading mirror speeds from cached hostfile

Resolving Dependencies-->Running transaction check---> Package autoconf.noarch 0:2.69-11.el7 will be installed--> Processing Dependency: perl >= 5.006 for package: autoconf-2.69-11.el7.noarch--> Processing Dependency: m4 >= 1.4.14 for package: autoconf-2.69-11.el7.noarch--> Processing Dependency: perl(warnings) for package: autoconf-2.69-11.el7.noarch

或者

[root@linuxidc.com yum.repos.d]# yum installtree

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

Resolving Dependencies-->Running transaction check---> Package tree.x86_64 0:1.6.0-10.el7 will be installed--> Finished Dependency Resolution

3.1.2 自定义YUM源

[root@linuxidc.com yum.repos.d]# yum -y install createrepo

准备rpm包

(需要自己确定依赖包)、目录。这里使用tree做演示。

[root@linuxidc.com ~]# mkdir -p /yum/yum-custom/packages

[root@linuxidc.com ~]# cp tree-1.6.0-10.el7.x86_64.rpm /yum/yum-custom/packages/

创建repo

[root@linuxidc.com ~]# createrepo -u -d /yum/yum-custom/Spawning worker0 with 1pkgs

Spawning worker1 with 0pkgs

Workers Finished

Saving Primary metadata

Savingfilelists metadata

Saving other metadata

Generating sqlite DBs

Sqlite DBs complete

[root@linuxidc.com ~]# ll /yum/yum-custom/total4drwxr-xr-x. 2 root root 41 Dec 20 07:03packages

drwxr-xr-x. 2 root root 4096 Dec 20 07:08repodata

[root@linuxidc.com ~]#

配置自定义repo

[root@linuxidc.com ~]# vi /etc/yum.repos.d/CentOS-Media.repo

填入如下内容

[c7-media]

name=CentOS-$releasever -Media

baseurl=file:///yum/yum-custom/

gpgcheck=0enabled=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

制作cache

[root@linuxidc.com ~]# yumclean all

Loaded plugins: fastestmirror

Cleaning repos: c7-media

Cleaning up everything

Cleaning up list of fastest mirrors

[root@linuxidc.com ~]#

[root@linuxidc.com ~]# yummakecache

Loaded plugins: fastestmirror

c7-media | 3.0 kB 00:00:00(1/3): c7-media/filelists_db | 880 B 00:00:00(2/3): c7-media/primary_db | 1.8 kB 00:00:00(3/3): c7-media/other_db | 1.3 kB 00:00:00Determining fastest mirrors

Metadata Cache Created

[root@linuxidc.com ~]#

使用自定义repo

[root@linuxidc.com ~]# yum installtree

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

Resolving Dependencies-->Running transaction check---> Package tree.x86_64 0:1.6.0-10.el7 will be installed--> Finished Dependency Resolution

3.2 局域网YUM源

局域网YUM源可以配成:本地YUM源 + FTP服务器

这里使用自定义源yum-custom(见上面) + VSFTP演示。

下载vsftpd

[root@linuxidc.com ~]# yum -y install vsftpd

配置vsftpd

编辑vsftp.conf

[root@linuxidc.com ~]# vi /etc/vsftpd/vsftpd.conf

并增加匿名用户root目录(默认已经启用匿名访问)

anon_root=/yum/

注意目录权限如下

[root@linuxidc.com ~]# ll -a /yum/total8drwxr-xr-x. 4 root root 37 Dec 20 07:37.

dr-xr-xr-x. 18 root root 4096 Dec 20 06:32..

drwxr-xr-x. 4 root root 36 Dec 20 07:08 yum-custom

dr-xr-xr-x. 8 root root 4096 Dec 10 2015 yum-iso

关闭selinux

临时

[root@linuxidc.com ~]# setenforce 0

或者,永久:

编辑config

[root@linuxidc.com ~]# vi /etc/selinux/config

设置

SELINUX=disabled

重启

[root@linuxidc.com ~]# reboot

启用vsftp

[root@linuxidc.com ~]# systemctl start vsftpd

[root@linuxidc.com ~]# systemctl enable vsftpd

Created symlink from/etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

[root@linuxidc.com ~]#

局域网使用

局域网另外一台机器min-client,

配置repo

编辑repo

[root@min-client ~]# vim /etc/yum.repos.d/CentOS-Media.repo

内容如下

[c7-media]

name=CentOS-$releasever -Media

baseurl=ftp://192.168.118.133/yum-custom

gpgcheck=0enabled=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

其中192.168.118.133为上面vsftp服务器地址

启用这个局域网的repo

[root@min-client ~]# yumclean all

Loaded plugins: fastestmirror

Cleaning repos: c7-media

Cleaning up everything

[root@min-client ~]# yummakecache

Loaded plugins: fastestmirror

c7-media | 3.0 kB 00:00(1/3): c7-media/filelists_db | 880 B 00:00(2/3): c7-media/other_db | 1.3 kB 00:00(3/3): c7-media/primary_db | 1.8 kB 00:00Determining fastest mirrors

Metadata Cache Created

[root@min-client ~]#

使用

[root@linuxidc.com ~]# yum -y installtree

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

Resolving Dependencies-->Running transaction check---> Package tree.x86_64 0:1.6.0-10.el7 will be installed--> Finished Dependency Resolution

目前差不多这些就够用了。以后有时间把163的YUM源爬下来,当本地源用。

更多YUM相关教程见以下内容:

0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
redhat 7.2 可用的yum源, 亲自测试可以使用 ,使用过程: 1.卸载已经存在的yum: rpm -qa | grep yum | xargs rpm -e --nodeps 2.将yum 文件放到server中 3.执行rpm -ivh yum-* 4.创建repo文件: #CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$7 - Base - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$7&arch;=$basearch&repo=os baseurl=http://mirrors.163.com/centos/7/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$7 - Updates - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$7&arch;=$basearch&repo=updates baseurl=http://mirrors.163.com/centos/7/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$7 - Extras - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$7&arch;=$basearch&repo=extras baseurl=http://mirrors.163.com/centos/7/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$7 - Plus - 163.com baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 5.测试是否安装成功 yum -y install tree
要将RedHat 7.2更换为CentOS 7的yum源,可以按照以下步骤操作: 1. 卸载RedHat原有的yum源: 使用命令`rpm -qa | grep yum`查看已安装的yum软件包。 使用命令`rpm -qa | grep yum | xargs rpm -e --nodeps`卸载已安装的yum软件包。 2. 下载CentOS的yum源: 前往CentOS镜像站点,例如阿里云镜像站点`https://mirrors.aliyun.com/centos/`,找到对应版本的yum源地址。 在镜像站点中找到合适的版本,例如CentOS 7的yum源码地址为`https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/`。 根据需求选择需要下载的包,例如`python-urlgrabber-3.10-10.el7.noarch.rpm`、`yum-3.4.3-167.el7.centos.noarch.rpm`等。 使用命令`wget`或其他下载工具下载所需的包。 3. 安装下载的CentOS的yum源: 执行命令`rpm -ivh --force *.rpm`来安装下载的所有包。 由于这些包之间存在依赖关系,所以需要使用`--force`参数来强制安装。 现在,你已经成功将RedHat 7.2更换为CentOS 7的yum源。你可以通过使用命令`rpm -qa | grep yum`来验证新的yum源已经安装成功。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Red hat7替换centos7Yum源](https://blog.csdn.net/qq_42956179/article/details/109618774)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Redhat7更换centos7yum源方法步骤](https://blog.csdn.net/weixin_43837883/article/details/89179533)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值