CentOS 创建本地yum源

1 背景

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

2 环境

[[email protected] ~]# 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
[[email protected] ~]# mkdir /mnt/yum-iso
[[email protected] ~]# mount /dev/cdrom /mnt/yum-iso/
mount: /dev/sr0 is write-protected, mounting read-only
[[email protected] ~]# mkdir /yum/
[[email protected] ~]# cp -a /mnt/yum-iso/ /yum/
[[email protected] ~]# ll /yum/
total 4
dr-xr-xr-x. 8 root root 4096 Dec 10 2015 yum-iso
[[email protected] ~]# ll /yum/yum-iso/
total 640
-r–r--r–. 1 root root 14 Dec 10 2015 CentOS_BuildTag
dr-xr-xr-x. 3 root root 33 Dec 10 2015 EFI
-r–r--r–. 1 root root 215 Dec 10 2015 EULA
-r–r--r–. 1 root root 18009 Dec 10 2015 GPL
dr-xr-xr-x. 3 root root 69 Dec 10 2015 images
dr-xr-xr-x. 2 root root 4096 Dec 10 2015 isolinux
dr-xr-xr-x. 2 root root 41 Dec 10 2015 LiveOS
dr-xr-xr-x. 2 root root 483328 Dec 10 2015 Packages
dr-xr-xr-x. 2 root root 4096 Dec 10 2015 repodata
-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 2015 TRANS.TBL
[[email protected] ~]#
备份、移除其他repo
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] 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
[[email protected] 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
[[email protected] yum.repos.d]# rm -f CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Sources.repo CentOS-Vault.repo
配置本地repo
[[email protected] yum.repos.d]# vi CentOS-Media.repo
填入如下内容
[c7-media]
name=CentOS-KaTeX parse error: Expected 'EOF', got '#' at position 190: …om yum.repos.d]#̲ yum clean all …releasever - Media
baseurl=file:///yum/yum-custom/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
制作cache
[[email protected] ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: c7-media
Cleaning up everything
Cleaning up list of fastest mirrors
[[email protected] ~]#
[[email protected] ~]# yum makecache
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:00
Determining fastest mirrors
Metadata Cache Created
[[email protected] ~]#
使用自定义repo
[[email protected] ~]# yum install tree
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
[[email protected] ~]# yum -y install vsftpd
配置vsftpd
编辑vsftp.conf
[[email protected] ~]# vi /etc/vsftpd/vsftpd.conf
并增加匿名用户root目录(默认已经启用匿名访问)
anon_root=/yum/
注意目录权限如下
[[email protected] ~]# ll -a /yum/
total 8
drwxr-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
临时
[[email protected] ~]# setenforce 0
或者,永久:
编辑config
[[email protected] ~]# vi /etc/selinux/config
设置
SELINUX=disabled
重启
[[email protected] ~]# reboot
启用vsftp
[[email protected] ~]# systemctl start vsftpd
[[email protected] ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
[[email protected] ~]#
局域网使用
局域网另外一台机器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=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
其中192.168.118.133为上面vsftp服务器地址
启用这个局域网的repo
[root@min-client ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: c7-media
Cleaning up everything
[root@min-client ~]# yum makecache
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:00
Determining fastest mirrors
Metadata Cache Created
[root@min-client ~]#
使用
[[email protected] ~]# yum -y install tree
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源爬下来,当本地源用。

猜你喜欢

转载自blog.csdn.net/qq_31977125/article/details/89277639