(服务端(双(外,内)网卡)——客户端(内网))

YUM主要用于自动安装、升级rpm软件包,它能自动查找并解决rpm包之间的依赖关系。要成功的使用YUM工具安装更新软件或系统,

就需要有一个包含各种rpm软件包的repository(软件仓库),这个软件仓库我们习惯称为yum源。网络上有大量的yum源,

但由于受到网络环境的限制,导致软件安装耗时过长甚至失败。特别是当有大量服务器大量软件包需要安装时,缓慢的进度条令人难以忍受。

因此我们在优化系统时,都会更换国内的源。相比较而言,本地YUM源服务器最大优点是局域网的快速网络连接和稳定性。有了局域网中的

YUM源服务器,即便在Internet连接中断的情况下,也不会影响其他YUM客户端的软件安装和升级。

97.1、YUM常用命令:

1、安装:

yum localinstall package1 #从本机安装包package1

yum install package1 #安装指定的安装包package1

yum groupinsall group1 #安装程序组group1

2、 更新和升级:

yum update/upgrade #更新操作系统和内核

yum update package1 #更新指定程序包package1,不删除旧的包

yum upgrade package1 #更新指定程序包package1,并删除旧的包

yum check-update #检查可更新的程序

yum grouplist #列出程序组

yum groupupdate group1 #升级程序组group1

3、查找和显示:

yum info package1 #显示安装包信息package1

yum list #显示所有已经安装和可以安装的程序包

yum list package1 #显示指定程序包安装情况package1

yum groupinfo group1 #显示程序组group1信息

yum search package1 #查找软件包package1;

yum list installed #列出已安装的软件包

yum list extras #列出不是通过软件仓库安装的软件包

yum list *ttp* #列出标题包含ttp的软件包的安装情况

yum list recent #列出新加入仓库的软件包

4、删除程序:

yum remove/erase package1 #删除程序包package1

yum groupremove group1 #删除程序组group1

yum deplist package1 #查看程序package1依赖情况

5、清除缓存:

yum clean packages #清除缓存目录下的软件包

yum clean headers #清除缓存目录下的 headers

yum clean all #清除缓存目录下的软件包及header

yum makecache #生成yum仓库缓存,生成元数据

97.2、创建yum仓库目录:

[root@nfs01 ~]# uname -r

2.6.32-573.el6.x86_64

[root@nfs01 ~]# cat /etc/redhat-release

CentOS release 6.7 (Final)

[root@nfs01 ~]# mkdir -p /application/yum/CentOS6.7/x86_64

[root@nfs01 ~]# cd /application/yum/CentOS6.7/x86_64/

[root@nfs01 x86_64]# rz -y #上传rpm包到此目录下,此目录下面还可以包括文件夹;

rz waiting to receive.

Starting zmodem transfer. Press Ctrl+C to cancel.

Transferring wordpress-4.5.1-zh_CN.tar.gz...

100% 7989 KB 7989 KB/sec 00:00:01 0 Errors

97.3、安装createrepo软件:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo #更新yum源仓库,会自动更新epel源仓库;

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo #更新epel源仓库;

yum clean all #清理yum元数据和缓存rpm包;

[root@nfs01 x86_64]# yum install createrepo -y

[root@nfs01 x86_64]# rpm -qa createrepo

createrepo-0.9.9-28.el6.noarch

97.4、初始化repodata索引文件:

[root@nfs01 x86_64]# createrepo -pdo /application/yum/CentOS6.7/x86_64/ /application/yum/CentOS6.7/x86_64/

Saving Primary metadata

Saving file lists metadata

Saving other metadata

Generating sqlite DBs

Sqlite DBs complete

97.5、提供yum服务:

1、用python的http模块更简单,但是太卡了网页打开速度非常慢,弃用:

[root@nfs01 x86_64]# pwd

/application/yum/CentOS6.7/x86_64 #使用python的http服务必须要在当前的目录中执行下面的命令;

[root@nfs01 x86_64]# python -m SimpleHTTPServer 80 &>/dev/null &

[1] 1640

2、使用apache提供web服务:

[root@nfs01 x86_64]# yum install httpd -y

[root@nfs01 x86_64]# rpm -qa httpd

httpd-2.2.15-69.el6.centos.x86_64

[root@nfs01 x86_64]# chkconfig --list httpd

httpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭

[root@nfs01 x86_64]# chkconfig httpd on

[root@nfs01 x86_64]# chkconfig --list httpd

httpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

[root@nfs01 x86_64]# vim /etc/httpd/conf/httpd.conf

276 ServerName 0127.0.0.1:8

292 DocumentRoot "/application/yum/CentOS6.7/x86_64/"

317 <Directory "/application/yum/CentOS6.7/x86_64/">

#删除欢迎文件,其实是无首页的显示的404内容,目的是为了输入ip就显示列表;

[root@nfs01 x86_64]# rm -vf /etc/httpd/conf.d/welcome.conf

已删除"/etc/httpd/conf.d/welcome.conf"

[root@nfs01 x86_64]# /etc/init.d/httpd start

正在启动 httpd: [确定]

在浏览器中查看:

97.6、添加新的rpm包:

1、yum下载rpm包到本地,不安装:

[root@nfs01 x86_64]# yumdownloader pcre-devel openssl-devel

已加载插件:fastestmirror

Loading mirror speeds from cached hostfile

* base: mirrors.aliyun.com

* extras: mirrors.cn99.com

* updates: mirrors.cn99.com

pcre-devel-7.8-7.el6.x86_64.rpm | 320 kB 00:00

pcre-devel-7.8-7.el6.i686.rpm | 320 kB 00:00

openssl-devel-1.0.1e-57.el6.x86_64.rpm | 1.2 MB 00:00

openssl-devel-1.0.1e-57.el6.i686.rpm

2、更新yum仓库repodata目录下的索引文件:

[root@nfs01 x86_64]# createrepo --update /application/yum/CentOS6.7/x86_64/

Spawning worker 0 with 4 pkgs

Workers Finished

Gathering worker results

Saving Primary metadata

Saving file lists metadata

Saving other metadata

Generating sqlite DBs

Sqlite DBs complete

每次上传新的rpm后都要执行更新命令;

3、配置yum安装缓存rpm功能:

[root@nfs01 x86_64]# vim /etc/yum.conf

[main]

#cachedir=/var/cache/yum/$basearch/$releasever

cachedir=/application/yum/CentOS6.7/x86_64/ #yum下载的rpm包的缓存目录;

keepcache=1 #rpm包缓存,默认不缓存为0;

debuglevel=2 #信息输出等级,范围是0-10,缺省值为2;

logfile=/var/log/yum.log #yum安装日志文件;

exactarch=1 #yum只会安装和系统架构匹配的软件包,默认是1;

obsoletes=1 #update参数,允许更新旧的rpm包;

gpgcheck=1 #检查安装rpm包的安全性;

plugins=1 #启用插件,默认是0不启用;

installonly_limit=5 #保留多少个内核包;

bugtracker_url=http://bugs.centos.org/set_project.php?project_id=19&ref=http://bugs.centos.org/bug_report_page.php?category=yum

distroverpkg=centos-release #根据软件包名判断rpm包的发行版本,默认是centos-release;

备注:如果以后更改网上的yum源时不能使用clean all 清除之前yum源留下的缓存,这样会把自己缓存的rpm包给删掉,最好是使用yum clean metadata命令

清除缓存的yum源信息;

96.8、客户端配置:

[root@backup x86_64]# cd /etc/yum.repos.d/

1、yum源临时生效配置:

(1)配置文件配置:

[root@backup yum.repos.d]# vim CentOS-6.7-x86_64.repo

[CentOS-6.7-x86_64]

name=CentOS-6.7

#url 支持的协议有 http://、 ftp:// 、file:// 三种。baseurl 后可以跟多个url,但baseurl 只能有一个。

baseurl=http://172.16.1.31

enabled=1 #启动此yum源,默认是1;

gpgcheck=0 #关闭检查rpm的安全性,默认是1开启,如果开启还需要在下面配置一行参数为gpgkey=http://192.16.1.31/RPM-GPG-KEY-CentOS-6

(2)清除以前的yum源缓存:

[root@backup yum.repos.d]# yum clean all #清理yum元数据和缓存rpm包

已加载插件:fastestmirror, security

Repository CentOS-6.7-x86_64 is listed more than once in the configuration

Cleaning repos: CentOS-6.7-x86_64 epel

清理一切

Cleaning up list of fastest mirrors

(3)测试:列出仓库中当前系统没有安装的软件;

[root@backup yum.repos.d]# yum --enablerepo=CentOS-6.7-x86_64 --disablerepo=base,extras,updates,epel list available

已加载插件:fastestmirror, security

Repository base is listed more than once in the configuration

Repository updates is listed more than once in the configuration

Repository extras is listed more than once in the configuration

Repository centosplus is listed more than once in the configuration

Repository contrib is listed more than once in the configuration

Loading mirror speeds from cached hostfile

可安装的软件包

openssl-devel.i686 1.0.1e-57.el6 CentOS-6.7-x86_64

openssl-devel.x86_64 1.0.1e-57.el6 CentOS-6.7-x86_64

pcre-devel.i686 7.8-7.el6 CentOS-6.7-x86_64

pcre-devel.x86_64 7.8-7.el6 CentOS-6.7-x86_64

2、yum源永久生效配置:

(1)配置文件配置:

[root@backup yum.repos.d]# vim Centos-Base.repo

[base]

…………

enabled=0

[updates]

…………

enabled=0

[extras]

…………

enabled=0

[CentOS-6.7-x86_64]

name=CentOS-6.7

baseurl=http://172.16.1.31

enabled=1

gpgcheck=0

[root@nfs01 yum.repos.d]# vim epel.repo

[epel]

enabled=0

(2)清除以前的yum源缓存:

[root@backup yum.repos.d]# yum clean all #清理yum元数据和缓存rpm包

已加载插件:fastestmirror, security

Repository CentOS-6.7-x86_64 is listed more than once in the configuration

Cleaning repos: CentOS-6.7-x86_64

清理一切

(3)测试:

[root@backup yum.repos.d]# yum install pcre-devel -y

已加载插件:fastestmirror, security

设置安装进程

Repository CentOS-6.7-x86_64 is listed more than once in the configuration

Loading mirror speeds from cached hostfile

解决依赖关系

--> 执行事务检查

---> Package pcre-devel.x86_64 0:7.8-7.el6 will be 安装

--> 完成依赖关系计算

96.9、镜像同步公网yum源配置:

服务端和客户端都可上网或服务端是双网卡(连接内外网),客户端是内网服务;

上面只是将自己制作的rpm包放入yum源,但还有一种企业需求,说的更具体一点,平时学生上课yum安装软件都是从公网下载的,占用带宽,

因此在学校里搭建一个内网yum服务器,但又考虑到学生回家也要使用yum安装软件,如果yum软件的数据库文件repodata不一样,就会有问题,

因此解决方法就是直接使用公网yum源的repodata。

1、安装httpd服务,使httpd网站根目录指向/data/yum_data/:

mkdir /data/yum_data/ -p

2、创建相应的yum源目录:

(1)创建base源目录:

mkdir -p /data/yum_data/centos/6/os/x86_64/

(2)创建extras源目录:

mkdir /data/yum_data/centos/6/extras/x86_64/

(3)创建updates源目录:

mkdir /data/yum_data/centos/6/updates/x86_64/

(4)创建epel源目录:

mkdir /data/yum_data/epel/6/x86_64/

3、同步yum源和epel源:

上游yum源必须要支持rsync协议,否则不能使用rsync进行同步,这里同步的是中科大的yum、epel源;

(1)同步base源:

/usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/6/os/x86_64/ /data/yum_data/centos/6/os/x86_64/

(2)同步extras源:

/usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/6/extras/x86_64/ /data/yum_data/centos/6/extras/x86_64/

(3)同步updates源:

/usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/6/updates/x86_64/ /data/yum_data/centos/6/updates/x86_64/

(4)同步epel源:

/usr/bin/rsync -av --exclude=debug rsync://mirrors.ustc.edu.cn/epel/6/x86_64/ /data/yum_data/epel/6/x86_64/

4、客户端配置:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo #更新yum源仓库;

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo #更新epel源仓库;

yum clean all #清理yum元数据和缓存rpm包;

如果有条件可以搭建一个dns服务器,如果没有可以可以使用hosts解析,echo '192.16.1.31 mirrors.aliyun.com' >>/etc/hosts

5、补充:

上面使用的是CentOS-6的源,如果同步完大约是21G左右,如果使用的是CentOS-7的源,则修改相应的目录就可以可了;

96.10、补充:

centos的镜像中自带了很多的rpm包,大约有3G左右,在机器不联网的情况下可以配置本地yum源,方便进行yum方式软件的安装,解决软件包之间的依赖关系:

1、挂载镜像:

[root@backup ~]# mount /dev/cdrom /mnt/

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

[root@backup ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda2 57G 1.9G 53G 4% /

tmpfs 296M 12K 296M 1% /dev/shm

/dev/sda1 190M 67M 114M 37% /boot

/dev/sr0 3.7G 3.7G 0 100% /mnt

2、yum源文件参数配置:

[root@backup yum.repos.d]# vim Centos-Base.repo

[base]

…………

enabled=0

[updates]

…………

enabled=0

[extras]

…………

enabled=0

[CentOS-6.7-x86_64]

name=CentOS-6.7

baseurl=file:///mnt/

enabled=1

gpgcheck=0

[root@nfs01 yum.repos.d]# vim epel.repo

[epel]

enabled=0

3、清除以前的yum源缓存:

[root@backup yum.repos.d]# yum clean all #清理yum元数据和缓存rpm包

已加载插件:fastestmirror, security

Repository base is listed more than once in the configuration

Repository updates is listed more than once in the configuration

Repository extras is listed more than once in the configuration

Repository centosplus is listed more than once in the configuration

Repository contrib is listed more than once in the configuration

Cleaning repos: CentOS-6.7-x86_64

清理一切

4、测试:

[root@backup yum.repos.d]# yum install zlib-devel

已加载插件:fastestmirror, security

设置安装进程

Repository base is listed more than once in the configuration

Repository updates is listed more than once in the configuration

Repository extras is listed more than once in the configuration

Repository centosplus is listed more than once in the configuration

Repository contrib is listed more than once in the configuration

Loading mirror speeds from cached hostfile

解决依赖关系

--> 执行事务检查

---> Package zlib-devel.x86_64 0:1.2.3-29.el6 will be 安装

--> 完成依赖关系计算

96.11、常用rpm包地址:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo #阿里云yum源(yum=Yellow dog Updater, Modified=更新修改程序);

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo #阿里云epel源 (epel=Extra Packages for Enterprise Linux=企业Linux的额外包)

https://mirrors.aliyun.com/centos/6/os/i386/Packages/ #阿里centos6 base rpm包 32位

https://mirrors.aliyun.com/centos/6/os/x86_64/Packages/ #阿里centos6 base rpm包 64位

https://www.centos.org/download/ #centos官方镜像下载 alternative downloads ;

96.12、总结:

1、yum源仓库添加新的rpm包时要更新repodata索引,客户端要清理以前的yum源缓存;

2、客户端更新yum源仓库地址时也要清除以前的yum源缓存;

3、要合理的使用yum clean all 和yum clean metadata 命令,不然会导致rpm包的丢失;

97、配置yum源仓库服务器的更多相关文章

  1. linux 搭建局域网YUM源仓库服务器

    yum简介 Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器.基于RPM包管理,能够从指定的服 ...

  2. 部署YUM源仓库与NFS共享存储服务

    镜像下载.域名解析.时间同步请点击 阿里巴巴开源镜像站 一.YUM YUM (Yellow dog Updater Modified) ●基于RPM包构建的软件更新机制 ●可以自动解决依赖关系 ●所有 ...

  3. 配置Yum源repo文件及搭建本地Yum服务器

    分享一篇配置Yum源repo文件及搭建本地Yum服务器的方法,希望对大家有用. Yum源的话有三大类: Base Extra Epel Base:就是你下载的光盘镜像里面的DVD1Extra:就是你下 ...

  4. linux配置yum源

    yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能够从指定的服务器自动下载RP ...

  5. redhat 配置yum源(配置163 yum repo)

    一般安装好redhat后,不能注册的话,不能使用系统自带的yum源.但是我们可以自己配置yum源来解决这一问题.下面介绍下redhat配置163yum源. 1) 查看版本号和系统类别: cat /et ...

  6. 配置 yum 源的两种方法

    配置 yum 源的两种方法 由于 redhat的yum在线更新是收费的,如果没有注册的话不能使用,如果要使用,需将redhat的yum卸载后,重启安装,再配置其他源,以下为详细过程:  1.删除red ...

  7. Linux学习Day5:Vim编辑器、配置网卡、配置Yum软件仓库

    今天首先学习Vim编辑器的使用,通过它可以对Linux系统的文件进行编写和修改.在Linux系统中一切都是文件,所以熟练掌握Vim编辑器的使用十分重要.最后通过配置主机网卡的实验,来加深Vim编辑器中 ...

  8. 克隆虚拟机及配置yum源的步骤及讲解(Hadoop基础)

    1.克隆虚拟机 找一台需要克隆的虚拟机但虚拟机必须在关机下进行,(建议将前期Linux环境 配置完成) 在VMware中右键虚拟机找到克隆的选项.   点击克隆 可以克隆他的快照(提前做快照)或者是克 ...

  9. Redhat7配置yum源(本地源和网络源)

    Redhat7配置yum源(本地源和网络源)   目录 一:配置本地yum源 二:配置网络yum源 YUM(Yellow dog Updater Modified): yum是基于RPM包构建的软件更 ...

随机推荐

  1. [c++] 分号的使用

    加分号的情况: 语句结束加分号(否则编译器不知道在哪里结束语句,编译器不识别换行,写代码时换行和退格只是为了看着舒服,但本质上代码是写给编译器看的) 声明语句后加分号(也是一种语句) 结构体.类定义后 ...

  2. [刷题] 203 Remove Linked List Elements

    要求 在链表中删除值为val的所有节点 示例 如 1->2->3->4->5->6->NULL,要求删除值为6的节点 返回1->2->3->4-& ...

  3. Linux 系统优化-workstation实践

    Linux 系统优化 关闭SELinux [root@workstation ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/seli ...

  4. kvm虚拟机迁移(6)

    一.迁移简介 迁移:      系统的迁移是指把源主机上的操作系统和应用程序移动到目的主机,并且能够在目的主机上正常运行. 在没有虚拟机的时代,物理机之间的迁移依靠的是系统备份和恢复技术.在源主机上实 ...

  5. Python小白的数学建模课-A1.国赛赛题类型分析

    分析赛题类型,才能有的放矢. 评论区留下邮箱地址,送你国奖论文分析 『Python小白的数学建模课 @ Youcans』 带你从数模小白成为国赛达人. 1. 数模竞赛国赛 A题类型分析 年份 题目 要 ...

  6. Scrapy中的错误

    TabError: Inconsistent use of tabs and spaces in indentation 需要将  .py  文件中的使用 tab 做的空格符删掉,打成空格符.任何一个 ...

  7. 将TVM集成到PyTorch

    将TVM集成到PyTorch 随着TVM不断展示出对深度学习执行效率的改进,很明显PyTorch将从直接利用编译器堆栈中受益.PyTorch的主要宗旨是提供无缝且强大的集成,而这不会妨碍用户.PyTo ...

  8. TSR交通标志检测与识别

    TSR交通标志检测与识别 说明: 传统图像处理算法的TSR集成在在ARM+DSP上运行,深度学习开发的TSR集成到FPGA上运行. 输入输出接口 Input: (1)图像视频分辨率(整型int) (2 ...

  9. 使用Relay部署编译ONNX模型

    使用Relay部署编译ONNX模型 本文介绍如何使用Relay部署ONNX模型的入门. 首先,必须安装ONNX软件包. 一个快速的解决方案是安装protobuf编译器,然后 pip install o ...

  10. CUDA C++编程手册(总论)

    CUDA C++编程手册(总论) CUDA C++ Programming Guide The programming guide to the CUDA model and interface. C ...