当前位置:首页 > 系统 > CentOS7 搭建本地yum和EPEL仓库

CentOS7 搭建本地yum和EPEL仓库

系统3年前 (2020-01-14)

CentOS7 搭建本地yum和EPEL仓库

CentOS7下搭建CentOS7、EPEL的局域网下使用的本地YUM仓库,因为在生产环境中由于安全的限制,某些服务器不允许访问公网。

如果需要使用yum安装包或update只能通过在本地自建yum源来解决。

yum源可以通过http、ftp、nfs等方式去访问使用,不过由于nfs由于自身的安全性问题并不推荐用。而ftp有主动/被动模式的问题,配置不当也会造成有无法访问。所以推荐使用http web方式提供yum源


安装nginx

rpm -Uvh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.16.1-1.el7.ngx.x86_64.rpm


设置host

echo "192.168.0.1 server1" >>/etc/hosts
tail -1 /etc/hosts


修改nginx配置

vim /etc/nginx/conf.d/repos.conf 

添加
server {
  listen 80;
  server_name server1;	
  root /u01/repos;
  location / {
  autoindex on;
  autoindex_exact_size off;
  autoindex_localtime on;
        }
		
##EPEL virtual directory
  location /epel/ {
    alias /u01/epel/;
  }
}


开启服务

systemctl start nginx && systemctl enable nginx
firewall-cmd --zone=public --permanent --add-service={http,https}
firewall-cmd --reload
reboot
curl -s 127.0.0.1


安装yum组件

yum-utils提供reposync服务,可以将远程的源同步到本地。createrepo可以将rpm包创建为Yum仓库,生成repodata目录

yum install -y yum-utils createrepo


创建文件保存目录

mkdir -p /u01/repos/{base,centosplus,extras,updates}
mkdir -p /u01/epel/


备份系统自带源

cd /etc/yum.repos.d
mkdir -p backuprepo && mv * backuprepo


修改本地源改为阿里云

wget -O CentOS-aliyun7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O epel.repo http://mirrors.aliyun.com/repo/epel-7.repo


查看本地存在的镜像

yum repolist


同步镜像到本地http根目录

reposync -g -l -d -m --repoid=base --newest-only --download-metadata --download_path=/u01/repos/
reposync -g -l -d -m --repoid=centosplus --newest-only --download-metadata --download_path=/u01/repos/
reposync -g -l -d -m --repoid=extras --newest-only --download-metadata --download_path=/u01/repos/
reposync -g -l -d -m --repoid=updates --newest-only --download-metadata --download_path=/u01/repos/
reposync -g -l -d -m --repoid=epel --newest-only --download-metadata --download_path=/u01/epel/


创建rpm包目录索引信息

createrepo -pdo /u01/repos/base /u01/repos/base
createrepo -pdo /u01/repos/centosplus /u01/repos/centosplus
createrepo -pdo /u01/repos/extras /u01/repos/extras
createrepo -pdo /u01/repos/updates /u01/repos/updates
createrepo -pdo /u01/epel /u01/epel/


创建定时同步任务

vim /etc/cron.daily/localrepos-update

添加
# Sync CentOS and EPEL repos
reposync -g -l -d -m --repoid=base --newest-only --download-metadata --download_path=/u01/repos/
reposync -g -l -d -m --repoid=centosplus --newest-only --download-metadata --download_path=/u01/repos/
reposync -g -l -d -m --repoid=extras --newest-only --download-metadata --download_path=/u01/repos/
reposync -g -l -d -m --repoid=updates --newest-only --download-metadata --download_path=/u01/repos/
reposync -g -l -d -m --repoid=epel --newest-only --download-metadata --download_path=/u01/epel/

# Build CentOS repo metadata
createrepo --update --workers=4 /u01/repos/base/
createrepo --update --workers=4 /u01/repos/centosplus/
createrepo --update --workers=4 /u01/repos/extras/
createrepo --update --workers=4 /u01/repos/updates
createrepo --update --workers=4 /u01/epel/

添加权限

chmod 755 /etc/cron.daily/localrepos-update


局域网其他服务器设置

备份本地源

echo "192.168.0.1 server1" >>/etc/hosts
cd /etc/yum.repos.d
mkdir -p backuprepo && mv * backuprepo


修改为新源

vim /etc/yum.repos.d/local.repo
添加
[base]
name=CentOS-7-base.local
baseurl=http://server1/base
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[centosplus]
name=Centos-7-plus.local
baseurl=http://server1/centosplus/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
[updates]
name=CentOS-7-updates.local
baseurl=http://server1/updates
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
[extras]
name=CentOS-7-extras.local
baseurl=http://server1/extras
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[epel]
name=CentOS-7-epel.local
baseurl=http://server1/epel
enabled=1
gpgcheck=0


测试

yum clean all
yum repolist all
yum install -y yum-plugin-fastestmirror


本站所有文章均可随意转载,转载时请保留原文链接及作者。

本文链接:https://www.vos.cn/os/387.html

相关文章

利用LVM特性对EVE-NG硬盘分区扩容

利用LVM特性对EVE-NG硬盘分区扩容

下载的EVE-NG镜像中,存放模拟器镜像的分区太小了,上传几个cisco和juniper的模拟器就快满了,所以需要使用lvm特性对ubuntu server的硬盘分区进行扩容,首先先将eve-ng虚拟...

CentOS7 搭建LNMP

CentOS7 搭建LNMP

使用CentOS 1708,其实就是RHEL 7.4,使用YUM搭建LNMP环境(Linux、Nginx、MariaDB、PHP),全部使用新版组件,比如Nginx 1.12.2、MariaDB 10...

CentOS7 iSCSI配置

CentOS7 iSCSI配置

先用5块磁盘组成RAID 6,其中4盘做RAID,1盘做热备,并在组建的阵列提供iSCSI服务yum install mdadm mdadm -Cv /dev...

CentOS7 Postfix配置

CentOS7 Postfix配置

使用Postfix+Dovecot配置简单的邮件服务器安装Bindyum install bind-chroot配置Bind  编辑主配置文件,里面的各种参数用...

RHEL6.5 + Oracle11g + RAC + ASM

RHEL6.5 + Oracle11g + RAC + ASM

实验环境操作系统:RedHat Enterprise Linux 6.5虚拟机:VMware-workstation 14.1.1数据库:Oracle Database11g 11.2.0.4存储:O...

CentOS 7转换为OEL 7

CentOS 7转换为OEL 7

参考官方提供的脚本,支持将CentOS 5, 6, 7转换为使用UEK(Unbreakable Enterprise Kernel)的Oracle Enterprise Linux转换系统curl&n...