14、yum仓库搭建

一、本地仓库

1.yum搭建本地仓库(单台如何实现)

1) 挂载cd光盘,因为里面很多的软件包 
[[email protected] ~]# mount /dev/cdrom /mnt 

2) 创建一个本地的仓库 
[[email protected] ~]# cd /etc/yum.repos.d/ 
[[email protected] /etc/yum.repos.d]# gzip * 
[[email protected] /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) 使用当前本地的仓库 
[[email protected] /etc/yum.repos.d]# yum makecache 
[[email protected] /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

2.yum搭建本地仓库--->共享给局域网中的所有服务器使用

环境准备:
10.0.0.99 作为yum仓库
10.0.0.98 作为使用yum仓库的客户端
1.搭建一个yum仓库 10.0.0.99 http:// https:// ftp:// file://

2.1.初识环境

[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防火墙 

2.2.安装ftp服务,并启动

[root@www ~]# yum install vsftpd -y          #安装ftp服务
[root@www ~]# systemctl start vsftpd        #启动ftp服务 
[root@www ~]# systemctl status vsftpd     #查看ftp服务状态是否是active Running 

2.3.给ftp共享的目录准备基础软件包

[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/ 

2.4.给ftp共享的目录准备扩展软件包(需要去同步公网上面的软件)

[root@www ~]# cd /var/ftp/ 
[root@www ~]# mkdir zabbix 
[root@www ~]# cd zabbix 
[root@www ~]# wget 下载所有的软件包,通过取值的方式 
[root@www ftp]# createrepo /var/ftp/zabbix/ 

2.5.如果需要同步jenkins这个仓库怎么办?

wget下载      (随时,但步骤太多,而且后期的可维护性差)
rsync同步     (凌晨1-8点) 

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

[root@www ftp]# yum install createrepo -y 
[root@www ftp]# createrepo /var/ftp/centos7/ 

2.7.客户端指向并使用内部的yum仓库 10.0.0.98

[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

2.8.检查yum仓库服务器从公网下载下来的软件包能否正常的使用

[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




猜你喜欢

转载自www.cnblogs.com/Forever-x/p/e8a3c60420e128ebdf32103aa82c0943.html