当前位置:首页 > CN2资讯 > 正文内容

服务器文件 镜像 服务器镜像部署

3天前CN2资讯


CentOS7 同步远程镜像 搭建本地yum服务器

同步CentOS镜像站点的数据到本地服务器,使用nginx实现http服务向局域网内的其他机器提供yum服务,解决内网yum安装软件的问题。

一、前提条件:

1、本机连接互联网,能正常访问CentOS镜像站点,本例使用中科大的源:mirrors.ustc.edu.cn。

2、CentOS镜像站点需要支持 rsync 协议。

二、搭建过程:

1、本机安装所需工具:

yum -y install rsync createrepo

2、创建目录(位置随意):

(1)、centos仓库目录,centosplus可以不同步,一般用不到:

mkdir -p /storage/repos/centos/7/{os,updates,extras,centosplus}/x86_64

(2)、epel仓库目录:

mkdir -p /storage/repos/epel/7/x86_64 #如果需要EPEL软件的源码,请同时创建以下目录 mkdir -p /storage/repos/epel/7/SRPMS/

3、同步远程镜像(该过程需要很长时间,与你的外网带宽有关):

rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/7/os/x86_64/ /storage/repos/centos/7/os/x86_64/ rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/7/updates/x86_64/ /storage/repos/centos/7/updates/x86_64/ rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/7/extras/x86_64/ /storage/repos/centos/7/extras/x86_64/ rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/7/centosplus/x86_64/ /storage/repos/centos/7/centosplus/x86_64/ #同步gpgkey rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7 /storage/repos/centos/

4、生成本地仓库元数据及索引

createrepo /storage/repos/centos/7/os/x86_64/ createrepo /storage/repos/centos/7/updates/x86_64/ createrepo /storage/repos/centos/7/extras/x86_64/ createrepo /storage/repos/centos/7/centosplus/x86_64/

5、同步脚本,如果你的服务器一直连接外网可以配置在定时任务里,定期与远程镜像保持同步:

vi /etc/cron.daily/update-repos # create new #!/bin/bash VER='7' ARCH='x86_64' CENTOS_REPOS=(os updates extras centosplus) #同步centos镜像 for REPO in ${CENTOS_REPOS[@]} do rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/${VER}/${REPO}/${ARCH}/ /storage/repos/centos/${VER}/${REPO}/${ARCH}/ createrepo /storage/repos/centos/${VER}/${REPO}/${ARCH}/ done #同步gpgkey rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7 /storage/repos/centos/ #同步epel镜像 rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/epel/7/x86_64/ /storage/repos/epel/7/x86_64/ createrepo /storage/repos/epel/7/x86_64/ #如果需要epel软件的源码,同步epel软件源码仓库 #rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/epel/7/SRPMS/ /storage/repos/epel/7/SRPMS/ #createrepo /storage/repos/epel/7/SRPMS/ #同步gpgkey rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/epel/RPM-GPG-KEY-EPEL-7 /storage/repos/epel/ # wq 保存退出后,给脚本赋予可执行权限 # chmod 755 /etc/cron.daily/update-repo

6、关闭selinux:

# 1、永久关闭 vi /etc/selinux/config #将其中的 SELINUX=enforcing 配置项 修改为: SELINUX=disabled # 2、临时关闭 setenforce 0

7、nginx的安装及配置(cenos官方源中没有包含nginx, 通过epel源安装nginx):

(1)、安装epel源:

yum install epel-release

(2)、安装nginx:

yum install -y nginx

(3)、启动nginx:

systemctl start nginx.service

(4)、开机自动启动nginx服务:

systemctl enable nginx.service

(5)、防火墙允许nginx服务:

firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https firewall-cmd --reload

(6)、在/etc/nginx/conf.d/下面创建repos.conf配置文件: 

vim /etc/nginx/conf.d/repos.conf server { listen 80; server_name _; # 404 错误页面重定向配置 error_page 404 /404.html; # 50x 错误页面重定项配置 error_page 500 503 504 /50x.html; error_log /var/log/nginx/repos_error.log; access_log /var/log/nginx/repos_access.log; root /storage/repos/; location / { autoindex on; } location = /50x.html { root /usr/share/nginx/html; } location = /404.html { root /usr/share/nginx/html; } }

(7)、修改 /etc/nginx/nginx.conf 注释掉nginx默认的80端口服务:

# server { # listen 80 default_server; # listen [::]:80 default_server; # server_name _; # root /usr/share/nginx/html; # # # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; # location / { # } # error_page 404 /404.html; # location = /40x.html { # } # error_page 500 502 503 504 /50x.html; # location = /50x.html { # } # }

(8)、重启nginx服务或让nginx重新加载配置:

systemctl restart nginx.service #或 systemctl reload nginx.service

现在应该可能通过 http://{ipaddress} 能查看到内容了,如果报403之类的错误,请查找nginx相关错误的解决办法。

三、yum客户端(机)配置:

1、修改 /etc/yum.repos.d/CentOS-Base.repo 文件中各仓库的baseurl 和 gpgkey 配置项,模板中的{ipaddress}替换为你的实际IP地址。

# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$releasever - Base #mirrorlist=http:///?release=$releasever&arch=$basearch&repo=os&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ baseurl=http://{ipaddress}/centos/$releasever/os/$basearch/ gpgcheck=1 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 gpgkey=http://{ipaddress}/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates #mirrorlist=http:///?release=$releasever&arch=$basearch&repo=updates&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ baseurl=http://{ipaddress}/centos/$releasever/updates/$basearch/ gpgcheck=1 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 gpgkey=http://{ipaddress}/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras #mirrorlist=http:///?release=$releasever&arch=$basearch&repo=extras&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/ baseurl=http://{ipaddress}/centos/$releasever/extras/$basearch/ gpgcheck=1 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 gpgkey=http://{ipaddress}/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus #mirrorlist=http:///?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/ baseurl=http://{ipaddress}/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 gpgkey=http://{ipaddress}/centos/RPM-GPG-KEY-CentOS-7

2、与修 1 的方式 修改 /etc/yum.repos.d/epel.repo 配置文件,如果没有就创建一个配置文件,内容如下:

[epel] name=Extra Packages for Enterprise Linux 7 - $basearch #baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch #metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch baseurl=http://{ipaddress}//epel/7/$basearch failovermethod=priority enabled=1 gpgcheck=1 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 gpgkey=http://{ipaddress}/epel/RPM-GPG-KEY-EPEL-7 [epel-debuginfo] name=Extra Packages for Enterprise Linux 7 - $basearch - Debug #baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug #metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch baseurl=http://{ipaddress}/epel/7/$basearch/debug failovermethod=priority enabled=0 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 gpgkey=http://{ipaddress}/epel/RPM-GPG-KEY-EPEL-7 gpgcheck=1 #[epel-source] #如果已同步SRPMS仓库,请取消该配置注释 #name=Extra Packages for Enterprise Linux 7 - $basearch - Source ##baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS #metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch #failovermethod=priority #enabled=0 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 #gpgkey=http://{ipaddress}/epel/RPM-GPG-KEY-EPEL-7 #gpgcheck=1

3、清除yum缓存:

yum clean all

4、删除yum缓存目录:

rm -rf /var/cache/yum/*

5、创建yum缓存:

yum makecache

配置结束!!!

    你可能想看:

    扫描二维码推送至手机访问。

    版权声明:本文由皇冠云发布,如需转载请注明出处。

    本文链接:https://www.idchg.com/info/20981.html

    分享给朋友:

    “服务器文件 镜像 服务器镜像部署” 的相关文章

    VPN测评:2023年最佳VPN服务推荐及选择指南

    当我第一次接触VPN时,感觉这个概念既神秘又充满吸引力。VPN,全称为虚拟专用网络,它为用户提供了一种安全、私人上网的方式。不论是为了保护个人隐私,还是为了突破地域限制,VPN已经成为现代网上活动中不可或缺的工具。 我发现VPN有许多用途。首先,它能加密我的网络连接,让我的在线活动在网络上变得更加私...

    Vorboss:伦敦领先的商业光纤网络提供商,互联网速度与稳定性之选

    Vorboss概述 在现代商业环境中,服务的速度和稳定性比以往任何时候都重要。Vorboss的出现,为伦敦的企业带来了一个崭新的光纤网络选择。作为伦敦唯一专用的商业光纤网络,Vorboss提供至少10Gbps的互联网速度,并且支持扩展到100Gbps。这种高效的网络解决方案为雄心勃勃的公司提供了直接...

    甲骨文云免费套餐与ARM CPU优势解析

    甲骨文云(Oracle Cloud)是一个强大的云服务平台,近年来受到了越来越多用户的关注。我自己也曾经探索过这个平台,在这里我想和大家聊聊甲骨文云的免费套餐,这对中小企业以及开发者来说真的是一个不错的选择。免费的套餐不仅简化了入门程序,也为新用户提供了足够的资源来尝试不同的云服务。 甲骨文云的免费...

    深入了解LOC VPS:选择、评测与未来发展趋势

    LOC VPS,顾名思义,是一种基于位置的虚拟专用服务器。简单来说,LOC VPS是一种通过虚拟化技术在数据中心创建和管理的服务器环境。它为用户提供了一种灵活、可扩展的计算资源,可以满足不同需求的业务。相较于物理服务器,LOC VPS在资源利用率、成本和管理上都更加高效。 LOC VPS有几个显著的...

    外网域名哪里最便宜?选择最佳注册商的指南

    1.1 什么是外网域名注册商? 外网域名注册商是提供域名注册服务的公司,它们通常允许用户选择和注册自己希望拥有的网站地址。这些注册商的作用不仅仅是处理注册申请。它们还提供一系列相关服务,例如域名转移、续费、DNS管理以及隐私保护等。选择合适的注册商对于建立网站而言非常重要,它直接影响到域名的成本和后...

    Hostwinds评测:全面解析优秀的网络托管服务

    Hostwinds概述 在了解Hostwinds之前,首先想分享一下我对这家公司的印象。Hostwinds成立于2010年,作为一家相对年轻的网络托管服务提供商,虽然起步不久,但它的发展速度却让我感到惊叹。起初,Hostwinds仅是一家提供基本虚拟主机服务的小公司,随着需求的不断增长,他们逐步扩展...