CentOS7搭建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 iswrite-protected, mounting read-only

[[email protected]~]#mkdir/yum/[[email protected]~]#cp-a /mnt/yum-iso/ /yum/[[email protected]~]# ll /yum/total 4dr-xr-xr-x.8root root4096Dec102015yum-iso

[[email protected]~]# ll /yum/yum-iso/total 640-r--r--r--.1root root14Dec102015 CentOS_BuildTag

dr-xr-xr-x.3root root33Dec102015 EFI-r--r--r--.1root root215Dec102015 EULA-r--r--r--.1root root18009Dec102015 GPL

dr-xr-xr-x.3root root69Dec102015 images

dr-xr-xr-x.2root root4096Dec102015 isolinux

dr-xr-xr-x.2root root41Dec102015 LiveOS

dr-xr-xr-x.2root root483328Dec102015 Packages

dr-xr-xr-x.2root root4096Dec102015 repodata-r--r--r--.1root root1690Dec102015RPM-GPG-KEY-CentOS-7-r--r--r--.1root root1690Dec102015RPM-GPG-KEY-CentOS-Testing-7-r--r--r--.1root root2883Dec102015 TRANS.TBL

[[email protected]~]#

备份、移除其他repo

[[email protected] ~]# cd /etc/yum.repos.d/[[email protected]]# ll-rw-r--r--.1root root1664Dec92015CentOS-Base.repo-rw-r--r--.1root root1309Dec92015CentOS-CR.repo-rw-r--r--.1root root649Dec92015CentOS-Debuginfo.repo-rw-r--r--.1root root290Dec92015CentOS-fasttrack.repo-rw-r--r--.1root root630Dec92015CentOS-Media.repo-rw-r--r--.1root root1331Dec92015CentOS-Sources.repo-rw-r--r--.1root root1952Dec92015CentOS-Vault.repo

[[email protected]]#tarzcvf 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]]#rm-f CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Sources.repo CentOS-Vault.repo

配置本地repo

[[email protected]]#viCentOS-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

[[email protected]]#yum clean all

Loaded plugins: fastestmirror

Cleaning repos: c7-media

Cleaning up everything

Cleaning up list of fastest mirrors

[[email protected]]#yum makecache

Loaded plugins: fastestmirror

c7-media                                                                                                        |3.6kB00:00:00   

(1/4): c7-media/group_gz                                                                                        |155kB00:00:00   

(2/4): c7-media/primary_db                                                                                      |5.3MB00:00:00   

(3/4): c7-media/filelists_db                                                                                    |6.2MB00:00:00   

(4/4): c7-media/other_db                                                                                        |2.3MB00:00:00   

Determining fastest mirrors

Metadata Cache Created

[[email protected]]#

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

[[email protected]]#yumgroupinstall"Development tools"Loaded plugins: fastestmirror

There is no installed groupsfile.

Maybe run: yumgroupsmark convert (seemanyum)

Loading mirror speeds from cached hostfile

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

或者

[[email protected]]#yuminstall tree

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

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

3.1.2 自定义YUM源

[[email protected]]#yum-yinstallcreaterepo

准备rpm包

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

[[email protected] ~]#mkdir-p /yum/yum-custom/packages

[[email protected]~]#cptree-1.6.0-10.el7.x86_64.rpm /yum/yum-custom/packages/

创建repo

[[email protected] ~]# createrepo -u -d  /yum/yum-custom/Spawning worker 0with1 pkgs

Spawning worker 1with0 pkgs

Workers Finished

Saving Primary metadata

Saving file lists metadata

Saving other metadata

Generating sqlite DBs

Sqlite DBs complete

[[email protected]~]# ll /yum/yum-custom/total 4drwxr-xr-x.2root root41Dec2007:03 packages

drwxr-xr-x.2root root4096Dec2007:08 repodata

[[email protected]~]#

配置自定义repo

[[email protected] ~]#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

[[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.0kB00:00:00   

(1/3): c7-media/filelists_db                                                                                    |880B00:00:00   

(2/3): c7-media/primary_db                                                                                      |1.8kB00:00:00   

(3/3): c7-media/other_db                                                                                        |1.3kB00:00:00   

Determining fastest mirrors

Metadata Cache Created

[[email protected]~]#

使用自定义repo

[[email protected] ~]#yuminstall tree

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

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

3.2 局域网YUM源

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

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

下载vsftpd

[[email protected] ~]#yum-yinstallvsftpd

配置vsftpd

编辑vsftp.conf

[[email protected] ~]#vi/etc/vsftpd/vsftpd.conf

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

anon_root=/yum/

注意目录权限如下

[[email protected] ~]# ll -a /yum/total 8drwxr-xr-x.4root root37Dec2007:37 .

dr-xr-xr-x.18root root4096Dec2006:32 ..

drwxr-xr-x.4root root36Dec2007:08yum-custom

dr-xr-xr-x.8root root4096Dec102015yum-iso

 关闭selinux

临时

[[email protected] ~]# setenforce0

或者,永久:

编辑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-customgpgcheck=0enabled=1gpgkey=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.0kB00:00(1/3): c7-media/filelists_db                                                                                    |880B00:00(2/3): c7-media/other_db                                                                                        |1.3kB00:00(3/3): c7-media/primary_db                                                                                      |1.8kB00:00Determining fastest mirrors

Metadata Cache Created

[root@min-client ~]#

使用

[[email protected] ~]#yum-yinstall tree

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

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

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

你可能感兴趣的:(CentOS7搭建YUM源)