yum

匿名 (未验证) 提交于 2019-12-02 23:48:02

一、本地仓库

1) 挂载cd光盘,因为里面很多的软件包  [root@www.oldboyedu.com ~]# mount /dev/cdrom /mnt   2) 创建一个本地的仓库  [root@www.oldboyedu.com ~]# cd /etc/yum.repos.d/  [root@www.oldboyedu.com /etc/yum.repos.d]# gzip *  [root@www.oldboyedu.com /etc/yum.repos.d]# cat xxx.repo  [LocalBase]                            #真实的仓库名称  name=This is Local Base      #当前仓库的描述  baseurl=file:///mnt                     #仓库所在的路径,可以是 http:// https:// ftp:// file://  enabled=1                                   #启用当前的仓库,默认是启用的  gpgcheck=0  #校验安装的rpm是否是合法的,0表示不校验 1表示校验,同时还需要gpgkey参数指定校验的公钥   3) 使用当前本地的仓库  [root@www.oldboyedu.com /etc/yum.repos.d]# yum makecache  [root@www.oldboyedu.com /etc/yum.repos.d]# yum repolist  Loaded plugins: fastestmirror, langpacks  Loading mirror speeds from cached hostfile   repo id               repo  name                       status          LocalBase         This is Local Base          4,021  repolist: 4,021




1.搭建一个yum仓库 10.0.0.99 http:// https:// ftp:// file://

[root@www ~]# systemctl disable firewalld      #关闭开机自动启动firewalld防火墙  [root@www ~]# systemctl stop firewalld         #现在立即关闭firewalld防火墙  [root@www ~]# setenforce 0                          #关闭selinux防火墙 [root@www ~]# sed -i 's#^SELINUX=.*#SELINUX=disabled#g' /etc/selinux/config    #下次不再启动selinux防火墙 
[root@www ~]# yum install vsftpd -y          #安装ftp服务 [root@www ~]# systemctl start vsftpd        #启动ftp服务  [root@www ~]# systemctl status vsftpd     #查看ftp服务状态是否是active Running 
[root@www ~]# mkdir /var/ftp/centos7   #提供基础base仓库  [root@www ~]# mount /dev/cdrom /mnt/  [root@www ~]# find /mnt/Packages/ -type f -name "*.rpm" |xargs -I {} cp -rp {} /var/ftp/centos7/ 
[root@www ~]# cd /var/ftp/  [root@www ~]# mkdir zabbix  [root@www ~]# cd zabbix  [root@www ~]# wget 下载所有的软件包,通过取值的方式  [root@www ftp]# createrepo /var/ftp/zabbix/ 
wget下载      (随时,但步骤太多,而且后期的可维护性差) rsync同步     (凌晨1-8点)  
[root@www ftp]# yum install createrepo -y  [root@www ftp]# createrepo /var/ftp/centos7/ 
[root@client yum.repos.d]# gzip *  [root@client yum.repos.d]# cat ftp_99.repo [FtpRepos]  name = This is Ftp Share Repos  baseurl = ftp://10.0.0.99/centos7/  enabled = 1  gpgcheck = 0
[root@client yum.repos.d]# cat ftp_zabbix_99.repo  [FtpZabbixRepos]  name = This is Ftp Share Zabbix Repos baseurl = ftp://10.0.0.99/zabbix/  enabled = 1  gpgcheck = 0

二、公网同步yum仓库

nginx+rsync实现本地yum源以及公网yum源

1.配置nginx的autoindex模块,开启目录浏览功能 2.使用rsync同步公网源上的软件包,至本地目录中 3.配置客户端指向即可

1.安装nginx

[root@yum ~]# vim /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1  [root@yum ~]# yum install nginx -y

2.nginx提供目录浏览功能

[root@yum ~]# cat /etc/nginx/conf.d/yum.conf server {     listen 80;     listen [::]:80;     server_name mirrors.linanxi.fun;     location / {         root /repo;         autoindex on; #开启目录浏览功能     } }

3.从公网的仓库同步软件包至本地


rsync同步命令(建议将其加入定时任务)

#1.同步centos7的基础源 rsync -zaP --exclude-from /repo/exclude_7.txt rsync://rsync.mirrors.ustc.edu.cn/centos/7.6.1810/ /repo/centos  #2.同步centos7的epel源 rsync -zaP --exclude-from /repo/exclude_7_epel.txt rsync://rsync.mirrors.ustc.edu.cn/epel/7/ /repo/epel  #centos7排除的文件(保留os和extras) [root@yum ~]# cat /repo/exclude_7.txt atomic/ centosplus/ cloud/ configmanagement/ cr/ dotnet/ fasttrack/ isos/ nfv/ opstools/ paas/ rt/ sclo/ storage/ virt/ debug/ drpms/  #centos7_epel排除的文件(保留x86_64) [root@yum ~]# cat /repo/exclude_7_epel.txt SRPMS/ aarch64/ ppc64/ ppc64le/ state

4.将ftp对应的目录生成为yum的仓库

[root@yum ~]# yum install createrepo -y [root@yum ~]# createrepo /repo/centos/ [root@yum ~]# createrepo /repo/epel/

5.客户端配置本地yum仓库

[centos] name = Local Base Repository baseurl = http://mirrors.linanxi.fun/centos enable = 1 gpgcheck = 0  [epel] name = Local Epel Repository baseurl = http://mirrors.linanxi.fun/epel enable = 1 gpgcheck = 0

注意:如果是虚拟机,需要在/etc/hosts配置解析:10.0.0.222 mirrors.linanxi.fun

6.扩展:

如果想为下游提供同步服务,我们可以使用rsync协议将目录共享出去,让其他人也可以同步(一般玩不起,毕竟没钱)。

[root@xuliangwei ~]# cat /etc/rsyncd.conf uid = nginx gid = nginx use chroot = no max connections = 2000 timeout = 600 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log  ignore errors read only = true #只提供同步,所以只读即可 list = true #允许查看列表,认证的什么的不需要配置 hosts allow = 0.0.0.0/0 #允许任何人同步  ##########提供同步的模块 [centos] path = /repo/centos [epel] path = /repo/epel
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!