背景:
有这样的需求,测试环境网段不能上网,但是测试环境centos安装软件包每一台都配置本地yum源很麻烦,也缺少第三方yum源,特此在内网搭建一台yum源服务器满足这一需求,同时防火墙层面只允许此yum源服务器每周日晚限时联网同步阿里云的yum源.
一.yum源服务器的系统环境,最小化安装
1
2
|
[root@yumserver ~] # cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
|
yum源服务器地址 10.8.98.222
放开系统防火墙,关闭selinux
1
2
3
4
|
[root@yumserver ~] # firewall-cmd --add-port=80/tcp --permanent
success
[root@yumserver ~] # firewall-cmd --reload
success
|
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@yumserver ~] # cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
|
二.添加阿里云yum源并检查
备份好原系统的repo
1
2
3
4
|
[root@yumserver yum.repos.d] # pwd
/etc/yum .repos.d
[root@yumserver yum.repos.d] # mkdir backup
[root@yumserver yum.repos.d] # mv *.repo backup/
|
1
2
3
4
|
curl -o /etc/yum .repos.d /CentOS-Base .repo https:999999 //mirrors .aliyun.com /repo/Centos-7 .repo
curl -o /etc/yum .repos.d /epel .repo http:999999 //mirrors .aliyun.com /repo/epel-7 .repo
yum makecache
yum repolist
|
去掉999999
三.安装相关软件
1
|
yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel httpd yum-utils createrepo
|
标注:
yum-utils:reposync同步工具
createrepo:编辑yum库工具
httpd:通过Apache软件提供web服务,也可以使用nginx
四、同步阿里云yum源软件包到本地服务器指定目录/mirror(自定义目录)
1
2
3
4
5
6
7
8
9
10
|
mkdir -p /mirror
chown -R apache:apache /mirror
chmod -R 755 /mirror
###参数-n指下载最新软件包,-p指定目录,指定本地的源--repoid(如果不指定就同步本地服务器所有的源),下载过程比较久
reposync -n --repoid=extras --repoid=updates --repoid=base --repoid=epel -p /mirror
[root@yumserver ~] # du -sh /mirror/*
9.0G /mirror/base
16G /mirror/epel
321M /mirror/extras
2.2G /mirror/updates
|
五 、创建仓库索引
1
2
3
4
|
createrepo -po /mirror/base/ /mirror/base/
createrepo -po /mirror/extras/ /mirror/extras/
createrepo -po /mirror/updates/ /mirror/updates/
createrepo -po /mirror/epel/ /mirror/epel/
|
六 、更新数据源
1
2
3
4
|
createrepo --update /mirror/base/
createrepo --update /mirror/extras/
createrepo --update /mirror/updates/
createrepo --update /mirror/epel/
|
七、启动并配置Apache服务
1
2
3
4
5
6
7
8
9
10
11
12
|
systemctl start httpd
systemctl enable httpd
systemctl status httpd
[root@yumserver ~] # vim /etc/httpd/conf/httpd.conf
DocumentRoot "/mirror/"
<Directory "/mirror/" >
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Require all granted
< /Directory >
|
###修改Apache默认首页index.html,直接复制粘贴执行
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
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>
<style>
myHero {
display: block;
background-color: #ddd;
padding: 10px;
font-size: 20px;
}
</style>
</head>
<body>
<h1>简介</h1>
<hr>
<p>CentOS,是基于 Red Hat Linux 提供的可自由使用源代码的企业级 Linux 发行版本。</p>
<hr>
<br>
<br>
<h1>CentOS 7 配置内部YUM源</h1>
<br>
<h2>1、备份</h2>
<myHero>mkdir /etc/yum.repos.d/backup </myHero>
<myHero>mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/</myHero>
<br>
<h2>2、下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/ </h2>
<myHero>curl -o /etc/yum.repos.d/CentOS-Base.repo xxxx://x.x.x.x/repo/CentOS-Base.repo</myHero>
<br>
<h2>3、运行 yum makecache 生成缓存</h2>
<br>
<h2>4、运行 yum repolist 查看已经生成缓存</h2>
<br>
<br>
</body>
</html>
EOF
|
注意:上面
更改为自己对应的
我这里为http : // 10.8.98.222 /
八、编写yum源客户端配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
[root@yumserver ~] # mkdir -p /mirror/repo/
###直接复制粘贴执行
cat << EOF > /mirror/repo/CentOS-Base .repo
[base]
name=CentOS-$releasever - Base - 10.8.98.222
failovermethod=priority
baseurl=
enable =1
gpgcheck=0
#released updates
[updates]
name=CentOS-$releasever - Updates - 10.8.98.222
failovermethod=priority
baseurl=
enable =1
gpgcheck=0
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 10.8.98.222
failovermethod=priority
baseurl=
enable =1
gpgcheck=0
#additional packages that may be useful
[epel]
name=CentOS-$releasever - Epel - 10.8.98.222
failovermethod=priority
baseurl=
enable =1
gpgcheck=0
EOF
|
九、客户端配置yum源
用户可以浏览器访问10.8.98.222查看配置客户端yum源的方法
1
2
|
curl -o /etc/yum .repos.d /CentOS-Base .repo
yum makecache
|
十 、设置定时同步yum源的任务
[root@yumserver ~]# cat /mirror/script/centos_yum_update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#!/bin/bash
echo 'Updating Aliyum Source'
DATETIME=` date +%F_%T`
exec > /var/log/aliyumrepo_ $DATETIME.log
reposync -np /mirror
if [ $? - eq 0 ]; then
createrepo --update /mirror/base
createrepo --update /mirror/extras
createrepo --update /mirror/updates
createrepo --update /mirror/epel
echo "SUCESS: $DATETIME aliyum_yum update successful"
else
echo "ERROR: $DATETIME aliyum_yum update failed"
fi
|
添加定时任务,每周一凌晨1点执行
1
2
|
[root@yumserver ~] # crontab -l
0 1 * * 1 /bin/bash /mirror/script/centos_yum_update .sh
|
CentOS 搭建内部Yum源同步阿里Yum源相关推荐
- 制作内网yum源 同步阿里的源
本文参考:http://www.studylinux.net/?p=4515 操作系统centos7(selinux firewalld关闭 ) 安装cobbler命令修改为阿里的yum源 163 ...
- [记录]CentOS搭建SVN服务器(主从同步)
CentOS搭建SVN服务器(主从同步) 1.安装步骤如下: 1)安装: #yum install subversion 2)查看安装位置: #rpm -ql subversion 3)查看版本: # ...
- Centos/RedHat 7/6/5切换阿里云源并安装EPEL/IUS/REMI仓库
Centos/RedHat 7/6/5切换阿里云源并安装EPEL/IUS/REMI仓库 CentOS安装完毕后,默认的yum源是国外的,国内访问速度很慢,需要切换为国内的源,这里选用的是阿里云的源.此 ...
- linux如何更换yum源为阿里云源
1.找到yum源得老家备份自己原有得yum源 cd /etc/yum.repos.d/ 2.找到阿里巴巴得yum源网站: https://developer.aliyun.com/mirror/ 3. ...
- 修改Centos7默认yum源为阿里云源
1.备份本地yum源: mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 2.下载新的Cent ...
- ubuntu 设置清华源、阿里云源
撸了今年阿里.头条和美团的面试,我有一个重要发现.......>>> https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/ Ubuntu ...
- Ubuntu18.04下更改apt源为阿里云源
为了下载更方便,速度更快,我们往往在使用Linux系列系统时修改apt源为国内的源,一般选择有阿里云,豆瓣之类的,下面简单说下如何更改为阿里云源. 1.复制源文件备份,以防万一 我们要修改的文件是so ...
- Linux Ubuntu 18.04 换源(阿里云源)
文章目录 一.比较好用的源 二.使用步骤 一.比较好用的源 阿里云源 清华源 二.使用步骤 这个可以直接在终端中运行 打开终端,输入以下命令 如下(阿里云源): sudo touch /etc/apt ...
- ubuntu 更换sources.list源为阿里云源
Ubuntu 的源存放在在 /etc/apt/ 目录下的 sources.list 文件中,修改前我们先做个备份,在终端中执行以下命令: sudo cp /etc/apt/sources.list / ...
最新文章
- optee3.14中的异常向量表解读--中断处理解读
- 有关;;;的基础小节
- Python 批量处理特定格式文件
- 阿里云centos mysql_阿里云ECS服务器CentOS7上安装MySql服务-阿里云开发者社区
- 《MySQL—— 业务高峰期的性能问题的紧急处理的手段 》
- linux怎样写java代码,linux 怎么写java
- Mysql Update 流程摘抄
- 使用esp8266制作wifi干扰器
- [学习笔记] Cordova+AmazeUI+React 做个通讯录 - 使用 SQLite
- 在 Linux 上配置一个 syslog 服务器
- 八个方便C#开发的省时的国外工具
- 003 第一个Python程序
- 多功能通用报修管理平台后勤维修软件
- MATLAB的简单动画制作
- 还有没换国旗头像的么 头像领取方法 不要再@微信官方啦
- java实现录屏_java录屏详细代码
- python语言设计二级教程答案2019_全国计算机等级考试二级教程2019年版——Python语言程序设计参考答案...
- AI时代已经起航,一些问题仍待解决
- hellojs使用 推特登录/api nuxt vue
- 手机无线连接(GSM/GPRS)方式
热门文章
- java bean工厂_java-将Service用作“工厂”以返回不同的Bean...
- linux 系统lv扩展_Linux增加LV(逻辑卷)容量
- pycharm short-cut
- Java算法-符号~
- 极大似然估计(Maximum Likelihood)与无监督
- topcoder SRM 625 DIV2 IncrementingSequence
- The Zen of Python, by Tim Peters
- 【转】独家教程:用PHP编写Android应用程序
- 在处理向该请求提供服务所需的配置文件时出错。请检查下面的特定错误详细信息并适当地修改配置文件。...
- 让Qt应用程序跑在Android上