CentOS7.9 搭建内部yum源服务器同步阿里yum源
环境说明:
1、企业内网需求:企业内部许多服务器是不能连接互联网,但每台centos主机安装软件包时都配置本地yum源很麻烦,也缺少第三方yum源,因此在内网搭建一台yum源服务器满足这一需求,同时网络层面策略只允许此yum源服务器每周日晚限时联网同步阿里云的yum源。
参考连接:http://blog.itpub.net/70004783/viewspace-2790196/
2、准备两台测试主机,一台用作yum源服务器(能连互联网),一台用作客户端。
3、系统版本:CentOS 7.9
实操步骤:
一、添加阿里云yum源
备份原系统的repo
[root@yumserver ~]# mkdir /etc/yum.repos.d/backup
[root@yumserver ~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
添加阿里云yum源并缓存(Centos-7.repo是软件仓库配置文件,epel-7.repo是扩展源、提供额外的软件包)
[root@yumserver ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@yumserver ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@yumserver ~]# yum makecache
[root@yumserver ~]# yum repolist
二、安装相关软件
[root@yumserver ~]# yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel httpd yum-utils createrepo
备注:
yum-utils:yum-utils是yum的工具包集合,reposync一个同步工具。
createrepo:createrepo是一个对rpm文件进行索引建立的工具,就是对指定目录下的rpm文件进行检索,把每个rpm文件的信息存储到指定的索引文件中,这样方便远程yum命令在安装更新时进行检索。
httpd:通过Apache软件提供web服务,也可以使用nginx。
三、同步阿里云yum源软件包到本地服务器指定目录/mirror(自定义目录)
创建存放软件包目录/mirror,(chown设置文件所有者和文件关联组,chmod控制用户对文件的权限)
[root@yumserver ~]# mkdir -p /mirror
[root@yumserver ~]# chown -R apache:apache /mirror
[root@yumserver ~]# chmod -R 755 /mirror
同步阿里云yum源软件包
###参数-n指下载最新软件包,-p指定目录,指定本地的源--repoid(如果不指定就同步本地服务器所有的源),下载过程比较久(10个小时左右)
[root@yumserver ~]# reposync -n --repoid=extras --repoid=updates --repoid=base --repoid=epel -p /mirror
[root@yumserver ~]# du -sh /mirror/*
9.0G /mirror/base
16G /mirror/epel
323M /mirror/extras
3.3G /mirror/updates
四、创建仓库索引
createrepo -po /mirror/base/ /mirror/base/
createrepo -po /mirror/extras/ /mirror/extras/
createrepo -po /mirror/updates/ /mirror/updates/
createrepo -po /mirror/epel/ /mirror/epel/
五、更新数据源
createrepo --update /mirror/base/
createrepo --update /mirror/extras/
createrepo --update /mirror/updates/
createrepo --update /mirror/epel/
六、启动并配置Apache服务
6.1、启动Apache(httpd)服务(如果没有httpd,需要yum install -y httpd 安装一下)
[root@yumserver ~]# systemctl start httpd
[root@yumserver ~]# systemctl enable httpd
[root@yumserver ~]# systemctl status httpd
6.2、系统防火墙放行80端口(apache服务使用的是80端口)
[root@yumserver ~]# firewall-cmd --permanent --zone=public --add-port=80/tcp
success
[root@yumserver ~]# firewall-cmd --reload
success
备注:必要时可以运行 systemctl restart httpd 重启一下服务。
6.3、关闭selinux(SELINUX=disabled)
[root@yumserver ~]# vi /etc/selinux/config
6.4、配置httpd.conf文件
[root@yumserver ~]# vi /etc/httpd/conf/httpd.conf
DocumentRoot "/mirror/"
<Directory "/mirror/">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Require all granted
</Directory>
注意:上面配置的httpd.conf文件,需要找到如下图DocumentRoot字样的行进行更改,而不是直接复制粘贴插入。
6.5、修改web界面的 index.html 文件
###修改Apache默认首页index.html,直接复制粘贴执行
cat << EOF > /usr/share/httpd/noindex/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CentOS 7 镜像</title>
<script>document.createElement("myHero")</script>
<st