前端之家收集整理的这篇文章主要介绍了
CentOS7.2 创建本地与局域网yum源,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1背景
由于客户环境只有局域网,没法使用网上的各种YUM源,来回拷贝rpm包安装麻烦,还得解决依赖问题。想着在CentOS7.2搭建个本地/局域网YUM源,方便自己跟同事安装软件。
2环境
[root@linuxidc.com ~]# cat /etc/RedHat-release
CentOS Linux release 7.2.1511 (Core)
并且是Minimal Install。
3安装
3.1本地YUM源
3.1.1 ISO源
准备rpm包
挂载CentOS-7-x86_64-Everything-1511.iso,把里面所有文件都拷贝到本地目录/yum/yum-iso
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/ /
[root@linuxidc.com ~]# ll /
total 4
dr-xr-xr-x. 8 root root 4096 Dec 10 2015 iso
[root@linuxidc.com ~]# ll /yum-iso/640
-r--r--r--. 1 root root 14 Dec 2015 CentOS_BuildTag
dr-xr-xr-x. 3 root root 33 Dec EFI
-r--r--r--. 1 root root 215 Dec EULA
-r--r--r--. 1 root root 18009 Dec GPL
dr-xr-xr-x. 69 Dec images
dr-xr-xr-x. 2 root root isolinux
dr-xr-xr-x. 2 root root 41 Dec LiveOS
dr-xr-xr-x. 2 root root 483328 Dec Packages
dr-xr-xr-x. repodata
-r--r--r--. 1 root root 1690 Dec 2015 RPM-GPG-KEY-CentOS-7
-r--r--r--. 2015 RPM-GPG-KEY-CentOS-Testing-2883 Dec TRANS.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--. 1309 Dec CR.repo
-rw-r--r--. 649 Dec Debuginfo.repo
-rw-r--r--. 290 Dec fasttrack.repo
-rw-r--r--. 630 Dec Media.repo
-rw-r--r--. 1331 Dec Sources.repo
-rw-r--r--. 1952 Dec 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-rm -f CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Sources.repo CentOS-Vault.repo
配置本地repo
[root@linuxidc.com vi CentOS-Media.repo
填入如下内容
[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///yum/yum-iso/
gpgcheck=0
enabled=1
gpgkey=etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
注释:配置repo路径、关闭gbp校验、启用这个repo
制作cache
clean all
Loaded plugins: fastestmirror
Cleaning repos: c7-
media
Cleaning up everything
Cleaning up list of fastest mirrors
[root@linuxidc.com makecache
Loaded plugins: fastestmirror
c7-media |
3.6 kB
00:
00
(1/
4): c7-media/group_gz |
155 kB
2/
4): c7-media/primary_db |
5.3 MB
3/
4): c7-media/filelists_db |
6.2 MB
4/
4): c7-media/other_db |
2.3 MB
Determining fastest mirrors
Metadata Cache Created
[root@linuxidc.com yum.repos.d]#
这样就可以使用yum安装软件啦
yum groupinstall "Development tools"
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man )
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-.el7.noarch
--> Processing Dependency: m4 >= 1.4.14 .el7.noarch
--> Processing Dependency: perl(warnings) 11.el7.noarch
或者
install tree
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 1.6.0-10.el7 will be installed
--> Finished Dependency Resolution
3.1.2 自定义YUM源
yum -y install createrepo
(需要自己确定依赖包)、目录。这里使用tree做演示。
mkdir -p /yum-custom/packages
[root@linuxidc.com ~]# cp tree-10.el7.x86_64.rpm /yum-custom/packages/
创建repo
[root@linuxidc.com ~]# createrepo -u -d /
Spawning worker 0 with pkgs
Spawning worker 1 with pkgs
Workers Finished
Saving Primary Metadata
Saving lists Metadata
Saving other Metadata
Generating sqlite DBs
sqlite DBs complete
[root@linuxidc.com ~]# ll /
drwxr-xr-x. 20 07:03 packages
drwxr-xr-x. 08 repodata
[root@linuxidc.com ~]#
配置自定义repo
vi /etc/yum.repos.d/CentOS-Media.repo
yum/yum-custom/
gpgcheck=media
Cleaning up everything
Cleaning up list of fastest mirrors
[root@linuxidc.com ~]#
[root@linuxidc.com ~]# 3.0 kB 3): c7-media/filelists_db | 880 B 3): c7-media/primary_db | 1.8 kB 3): c7-media/other_db | 1.3 kB
Determining fastest mirrors
Metadata Cache Created
[root@linuxidc.com ~]#
[root@linuxidc.com ~]# ll -a /8
drwxr-xr-x. 4 root root 37 Dec 37 .
dr-xr-xr-x. 18 root root 06:32 ..
drwxr-xr-x. 36 Dec 08 custom
dr-xr-xr-x. yum-iso
[root@linuxidc.com ~]# setenforce 0
[root@linuxidc.com ~]# reboot
[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 ~]#
[root@min-client ~]# vim /etc/ 内容如下
ftp:
//192.168.118.133/yum-custom
gpgcheck=
其中192.168.118.133为上面vsftp服务器地址
启用这个局域网的repo
[root@min-client ~]# media
Cleaning up everything
[root@min-client ~]#
(
Determining fastest mirrors
Metadata Cache Created
[root@min-client ~]#
使用
.el7 will be installed
--> Finished Dependency Resolution
目前差不多这些就够用了。以后有时间把163的YUM源爬下来,当本地源用。
原文链接:https://www.f2er.com/centos/375986.html