14、yum仓库搭建
发布时间:2020-12-15 21:12:44 所属栏目:安全 来源:网络整理
导读:一、本地仓库 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 * [[e
一、本地仓库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搭建本地仓库--->共享给局域网中的所有服务器使用环境准备: 2.1.初识环境[[email?protected] ~]# systemctl disable firewalld #关闭开机自动启动firewalld防火墙 [[email?protected] ~]# systemctl stop firewalld #现在立即关闭firewalld防火墙 [[email?protected] ~]# setenforce 0 #关闭selinux防火墙 [[email?protected] ~]# sed -i ‘s#^SELINUX=.*#SELINUX=disabled#g‘ /etc/selinux/config #下次不再启动selinux防火墙 2.2.安装ftp服务,并启动[[email?protected] ~]# yum install vsftpd -y #安装ftp服务 [[email?protected] ~]# systemctl start vsftpd #启动ftp服务 [[email?protected] ~]# systemctl status vsftpd #查看ftp服务状态是否是active Running 2.3.给ftp共享的目录准备基础软件包[[email?protected] ~]# mkdir /var/ftp/centos7 #提供基础base仓库 [[email?protected] ~]# mount /dev/cdrom /mnt/ [[email?protected] ~]# find /mnt/Packages/ -type f -name "*.rpm" |xargs -I {} cp -rp {} /var/ftp/centos7/ 2.4.给ftp共享的目录准备扩展软件包(需要去同步公网上面的软件)[[email?protected] ~]# cd /var/ftp/ [[email?protected] ~]# mkdir zabbix [[email?protected] ~]# cd zabbix [[email?protected] ~]# wget 下载所有的软件包,通过取值的方式 [[email?protected] ftp]# createrepo /var/ftp/zabbix/ 2.5.如果需要同步jenkins这个仓库怎么办?wget下载 (随时,但步骤太多,而且后期的可维护性差) rsync同步 (凌晨1-8点) 2.6.将ftp对应的目录生成为yum的仓库[[email?protected] ftp]# yum install createrepo -y [[email?protected] ftp]# createrepo /var/ftp/centos7/ 2.7.客户端指向并使用内部的yum仓库 10.0.0.98[[email?protected] yum.repos.d]# gzip * [[email?protected] 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仓库服务器从公网下载下来的软件包能否正常的使用[[email?protected] 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[[email?protected] ~]# vim /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1 [[email?protected] ~]# yum install nginx -y 2.nginx提供目录浏览功能[[email?protected] ~]# cat /etc/nginx/conf.d/yum.conf server { listen 80; listen [::]:80; server_name mirrors.linanxi.fun; location / { root /repo; autoindex on; #开启目录浏览功能 } } 3.从公网的仓库同步软件包至本地需要注意,如果全同步,会特别占用空间,所以我们可以将不需要的软件包进行过滤。 #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) [[email?protected] ~]# 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) [[email?protected] ~]# cat /repo/exclude_7_epel.txt SRPMS/ aarch64/ ppc64/ ppc64le/ state 4.将ftp对应的目录生成为yum的仓库[[email?protected] ~]# yum install createrepo -y [[email?protected] ~]# createrepo /repo/centos/ [[email?protected] ~]# 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协议将目录共享出去,让其他人也可以同步(一般玩不起,毕竟没钱)。 [[email?protected] ~]# 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
来自为知笔记(Wiz)
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |