CentOS7.2 创建本地YUM源和局域网YUM源

1背景

由于开发环境只有局域网,没法使用网上的各种YUM源,来回拷贝rpm包安装麻烦,还得解决依赖问题。

想着搭建个本地/局域网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]-base ~]# mount /dev/cdrom /mnt/yum-iso/
mount: /dev/sr0 is write-protected, mounting read-only
[[email protected]-base ~]# mkdir /yum/
[[email protected]-base ~]# cp -a /mnt/yum-iso/ /yum/
[[email protected]-base ~]# ll /yum/
total 4
dr-xr-xr-x. 8 root root 4096 Dec 10  2015 yum-iso
[[email protected]-base ~]# 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]-base ~]# 

备份、移除其他repo

[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected]-base 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]-base 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]-base 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-$releasever - Media
baseurl=file:///yum/yum-iso/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

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

制作cache

[[email protected] yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: c7-media
Cleaning up everything
Cleaning up list of fastest mirrors
[[email protected]-base yum.repos.d]# yum makecache
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:00
Determining fastest mirrors
Metadata Cache Created
[[email protected]-base yum.repos.d]# 

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

[[email protected] yum.repos.d]# yum groupinstall "Development tools"
Loaded plugins: fastestmirror
There is no installed groups 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

或者

[[email protected] yum.repos.d]# 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.1.2 自定义YUM源

[[email protected] yum.repos.d]# yum -y install createrepo

准备rpm包

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

[[email protected] ~]# mkdir -p /yum/yum-custom/packages
[[email protected]-base ~]# cp tree-1.6.0-10.el7.x86_64.rpm /yum/yum-custom/packages/

创建repo

[[email protected] ~]# createrepo -u -d  /yum/yum-custom/
Spawning worker 0 with 1 pkgs
Spawning worker 1 with 0 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[[email protected]-base ~]# ll /yum/yum-custom/
total 4
drwxr-xr-x. 2 root root   41 Dec 20 07:03 packages
drwxr-xr-x. 2 root root 4096 Dec 20 07:08 repodata
[[email protected]-base ~]# 

配置自定义repo

[[email protected] ~]# vi /etc/yum.repos.d/CentOS-Media.repo

填入如下内容

[c7-media]
name=CentOS-$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]-base ~]#
[[email protected]-base ~]# 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]-base ~]# 

使用自定义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]-base ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
[[email protected]-base ~]# 

局域网使用

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

配置repo

编辑repo

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

[[email protected] ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: c7-media
Cleaning up everything
[[email protected]-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
[[email protected]-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源爬下来,当本地源用。

时间: 2024-11-09 00:20:49

CentOS7.2 创建本地YUM源和局域网YUM源的相关文章

CentOS7.3 创建本地YUM源和局域网YUM源

由于某某公司针对安全这一块做的比较严谨,服务器全部都不可以连接外网.由于开发环境只有局域网,没法使用网上的各种YUM源,来回拷贝rpm包安装麻烦,还得解决依赖问题.想着在CentOS7.3搭建个本地/局域网YUM源,方便自己跟同事安装软件. 创建本地YUM源 环境: [[email protected] ~]# cat /etc/centos-release CentOS Linux release 7.3.1611 (Core) 并且是Minimal Install. 准备rpm包 : 挂载C

配置网络YUM源和第三方YUM源及编译安装Apache

配置网络YUM源和第三方YUM源及编译安装Apache 系统软硬件环境平台: VMware Workstation Pro 12.5.5 build-5234757 CentOS Linux release 7.3.1611 内核版本:3.10.0-514.el7.x86_64 测试时间:2017年6月13日 实验1:实现网络YUM源 1.准备相关系统光盘,搭建网络服务ftp或http [执行命令]#ls /mnt [执行命令]#mount | grep "/dev/sr0" [执行命

RHEL5.1创建本地及FTP的yum源

原材料: 一台已经装好RHEL5.1的旧电脑主机,没有键盘鼠标,没有显示器 一台安装windows7 的笔记本 工具: RHEL5.1 安装光盘 Xmanager Enterprise 4 软件 步骤: 本地 yum 源 1.创建一个目录,用于挂载光盘镜像 [[email protected] ~]# mkdir -pv /var/yum.d 2.挂载光盘镜像到刚刚创建的目录中 [[email protected] ~]# mount /dev/cdrom /var/yum.d/ 3.备份/et

Centos 7 配置阿里云 yum源和 安装 EPEL源

配置阿里云 yumwget -O /etc/yum.repos.d/CentOS-Baseali.repo http://mirrors.aliyun.com/repo/Centos-7.repo下载 repo到相应目录中 cd /etc/yum.repos.d/切换至 yum.repos.d 目录 ls查看目录中文件 yum clean all清空yum缓存 yum makecache建立yum缓存 yum reposlist查看仓库列表 安装EPEL源 yum list | grep epe

centos7创建本地源并搭建局域网yum源服务器

1:关闭firewell防火墙[[email protected] ~]# systemctl stop firewelld.service #停止firewell[[email protected] ~]# systemctl disable firewalld.service #禁止firewell开机启动 2:安装并启动vsftpd 查看是否已安装 方法一 [[email protected] ~]# rpm -q vsftpdvsftpd-3.0.2-21.el7.x86_64 查看是否

centos7创建本地 yum源 epel源

centos7创建本地 yum源 epel源 1.安装httpd服务,提供网页浏览 yum-y install httpd systemctlstart httpd systemctlenable httpd 2.创建yum仓库目录和epel目录 mkdir/var/www/html/yum 3.安装创建仓库软件包:createrepo yum-y install createrepo 4.初始化仓库索引文件 createrepo-p -d -o /var/www/html/yum/ /var/

Centos7.4配置本地yum源和阿里源并配置yum优先级

一.用Centos镜像搭建本地yum源 安装完linux系统的默认yum源为centos的官方地址,在"国内的特殊环境"下使用很慢甚至无法访问,所以一般的做法都是把默认的yum源替换成aliyun的yum源或者163等国内的yum源.但是以上的方法都是需要网络的,当没有网络的时候就无法使用了,所以还有一个常用的方法就是用Centos的iso镜像搭建本地yum源,这样安装软件的速度就会飞快,缺点是可能有些需要的包文件本地里没有. ? ?# 1.安装Centos后默认的yum源如下 [[e

本地yum仓库与局域网yum仓库配置

一.CentOS本地源设置 1.备份并删除原始的repo源文件 [[email protected] yum.repos.d]# tar -jcv -f CentOS.repo.tar.bz3 CentOS-* CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo [[email protected] yum.repos.d]# ll total 21 -rw-r--r-- 2 root root 2

在CentOS 7.3中创建本地yum源

1.挂载系统光盘 1.1创建挂载文件 [[email protected] ~]# mkdir /mnt/cdrom                          #创建文件 1.2挂载光驱 [[email protected] ~]# mount /dev/cdrom /mnt/cdrom/              #挂载光驱  mount: /dev/sr0 is write-protected, mounting read-only      #挂载成功 [[email protec