CentOS7搭建yum源仓库(阿里源)
文章目录
注意:环境要求
`阿里源的centos6和centos7各14G不到,注意磁盘空间`
'环境准备,修改hostname,关闭防火墙,disabled selinux'
[root@localhost ~]# hostnamectl set-hostname --static yum-server
[root@yum-server ~]# systemctl disable firewalld --now
[root@yum-server ~]# sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/sysconfig/selinux
1、配置服务器端yum
1.1、安装yum源工具
[root@yum-server ~]# yum -y install epel-release.noarch # nginx需要epel源
[root@yum-server ~]# yum -y install nginx # 安装nginx
[root@yum-server ~]# yum -y install createrepo yum-utils # 安装repository管理工具
1.2、配置nginx
[root@yum-server nginx]# cd /etc/nginx/
[root@yum-server nginx]# cp nginx.conf{,.bak} # 备份!备份!备份!
[root@yum-server nginx]# vim nginx.conf
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
# 在server段加入以下三段内容
autoindex on; # 表示:自动在index.html的索引打开
autoindex_exact_size on; # 表示:如果有文件,则显示文件的大小
autoindex_localtime on; # 表示:显示更改时间,以当前系统的时间为准
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
[root@yum-server nginx]# nginx -t # 检测一下nginx语法是否有错
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@yum-server nginx]# systemctl enable nginx.service --now # 启动nginx,设为开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@yum-server nginx]# curl -I http://localhost # 访问本地,状态码返回200,服务正常
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Sun, 05 Jul 2020 09:48:05 GMT
Content-Type: text/html
Content-Length: 4833
Last-Modified: Fri, 16 May 2014 15:12:48 GMT
Connection: keep-alive
ETag: "53762af0-12e1"
Accept-Ranges: bytes
1.2.1、配置nginx页面目录
[root@yum-server nginx]# cd /usr/share/nginx/html/
[root@yum-server html]# mkdir -p CentOS-YUM/Aliyun/{version_6,version_7}/64bit
[root@yum-server html]# tree /usr/share/nginx/html/CentOS-YUM/
/usr/share/nginx/html/CentOS-YUM/
└── Aliyun
├── version_6
│ └── 64bit
└── version_7
└── 64bit
5 directories, 0 files
[root@yum-server html]# cd CentOS-YUM/
[root@yum-server CentOS-YUM]# vim index.html
<p style="font-weight:bolder;color:green;font-size:30px;">ALL of the packages in the below:</p>
<br/>
<a href="http://192.168.57.133/CentOS-YUM/Aliyun">version_6</a><br/>
These packagers using for Centos 6<br/>
<a href="http://192.168.57.133/CentOS-YUM/Aliyun">version_7</a><br/>
These packagers using for Centos 7<br/>
<p style="font-weight:bolder;color:red;font-size:18px;">Please replace the file and fill in the f ollowing content:</p>
<p style="font-weight:bolder;color:blue;font-size:15px;">Way: /etc/yum.repos.d/CentOS-Base.repo</ p>
1.3、替换yum源文件
# 备份原来的官方yum源
[root@yum-server CentOS-YUM]# cd /etc/yum.repos.d/
[root@yum-server yum.repos.d]# mv ./* /tmp/
[root@yum-server yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo # 下载aliyun的centos7的yum源
[root@yum-server yum.repos.d]# vim yum.reposync.sh # 同步脚本
#!/usr/bin/bash
reposync -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7/64bit/
# 同步/etc/yum.repos.d/CentOS-Base.repo内的rpm包
/usr/bin/sed -i "s/7/6/g" /etc/yum.repos.d/CentOS-Base.repo
# 将CentOS-Base.repo内的7改成6,后续同步centos6的rpm包使用
reposync -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_6/64bit/
# 同步/etc/yum.repos.d/CentOS-Base.repo内的rpm包(此时是centos6的包)
/usr/bin/sed -i "s/6/7/g" /etc/yum.repos.d/CentOS-Base.repo
# 重新将CentOS-Base.repo内的6改回成7,下次同步的时候,不会出错
[root@yum-server yum.repos.d]# chmod +x yum.reposync.sh # 要给执行权限
[root@yum-server yum.repos.d]# ll
total 8
-rw-r--r-- 1 root root 2523 Jun 16 2018 CentOS-Base.repo
-rwxr-xr-x 1 root root 303 Jul 5 19:02 yum.reposync.sh
[root@yum-server yum.repos.d]# sh yum.reposync.sh
# 等待同步完成
# 同步完成,查看文件大小,合计27G
[root@yum-server CentOS-YUM]# du -ch Aliyun/
9.0G Aliyun/version_7/64bit/base/Packages
9.0G Aliyun/version_7/64bit/base
616M Aliyun/version_7/64bit/extras/Packages
616M Aliyun/version_7/64bit/extras
3.6G Aliyun/version_7/64bit/updates/Packages
3.6G Aliyun/version_7/64bit/updates
14G Aliyun/version_7/64bit
14G Aliyun/version_7
9.0G Aliyun/version_6/64bit/base/Packages
9.0G Aliyun/version_6/64bit/base
616M Aliyun/version_6/64bit/extras/Packages
616M Aliyun/version_6/64bit/extras
3.6G Aliyun/version_6/64bit/updates/Packages
3.6G Aliyun/version_6/64bit/updates
14G Aliyun/version_6/64bit
14G Aliyun/version_6
27G Aliyun/
27G total
1.4、建立yum源仓库
'因为建仓最终的目的也是可供client来进行检索的,所以得每个Packages目录都要建成仓库,所以建仓的时候,目录指到最底层的Packages,而-np更新的时候只用指定到64bit的目录就可以了,否则会重复建立base、extras、updates三个目录进行下载
[root@yum-server ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7/64bit/base/Packages/
Spawning worker 0 with 10070 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@yum-server ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7/64bit/extras/Packages/
Spawning worker 0 with 397 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@yum-server ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7/64bit/updates/Packages/
Spawning worker 0 with 884 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@yum-server ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_6/64bit/base/Packages/
Spawning worker 0 with 10070 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@yum-server ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_6/64bit/updates/Packages/
Spawning worker 0 with 884 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@yum-server ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_6/64bit/extras/Packages/
Spawning worker 0 with 397 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete[root@yum-server ~]# tree -d /usr/share/nginx/html/CentOS-YUM/Aliyun/ # 建仓完成后,会自动生成一个repodata目录
/usr/share/nginx/html/CentOS-YUM/Aliyun/
├── version_6
│ └── 64bit
│ ├── base
│ │ └── Packages
│ │ └── repodata
│ ├── extras
│ │ └── Packages
│ │ └── repodata
│ └── updates
│ └── Packages
│ └── repodata
└── version_7
└── 64bit
├── base
│ └── Packages
│ └── repodata
├── extras
│ └── Packages
│ └── repodata
└── updates
└── Packages
└── repodata
22 directories
'可以写一个更新yum源的脚本,然后写一个计划任务,定期更新yum源(reposync -np 就是更新新的rpm包)
#!/usr/bin/bash
reposync -np /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7/64bit/
echo "centos7 is sync complate"
/usr/bin/sed -i "s/7/6/g" /etc/yum.repos.d/CentOS-Base.repo`
reposync -np /usr/share/nginx/html/CentOS-YUM/Aliyun/version_6/64bit/
echo "centos6 is sync complate"
/usr/bin/sed -i "s/6/7/g" /etc/yum.repos.d/CentOS-Base.repo
2、配置客户端yum
# 备份原来的yum源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo epel-testing.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo epel.repo
[root@localhost yum.repos.d]# mkdir back
[root@localhost yum.repos.d]# mv *.repo back/
[root@localhost yum.repos.d]# ls
back
[root@localhost yum.repos.d]# vim CentOS-Base.repo # 需要6,就使用6,需要7,就使用7,也可以使用yum-plugin-priorities工具来控制优先级,加上priority=1(2|3|4都可以)来控制优先级
[Aliyun_7_base]
name=source_from_localserver
baseurl=http://192.168.57.133/CentOS-YUM/Aliyun/version_7/64bit/base/Packages
gpgcheck=0
enable=1
[Aliyun_7_extras]
name=source_from_localserver
baseurl=http://192.168.57.133/CentOS-YUM/Aliyun/version_7/64bit/extras/Packages
gpgcheck=0
enable=1
[Aliyun_7_updates]
name=source_from_localserver
baseurl=http://192.168.57.133/CentOS-YUM/Aliyun/version_7/64bit/updates/Packages
gpgcheck=0
enable=1
# [Aliyun_6_base]
# name=source_from_localserver
# baseurl=http://192.168.57.133/CentOS-YUM/Aliyun/version_6/64bit/base/Packages
# gpgcheck=0
# enable=1
#
# [Aliyun_6_extras]
# name=source_from_localserver
# baseurl=http://192.168.57.133/CentOS-YUM/Aliyun/version_6/64bit/extras/Packages
# gpgcheck=0
# enable=1
#
# [Aliyun_6_updates]
# name=source_from_localserver
# baseurl=http://192.168.57.133/CentOS-YUM/Aliyun/version_6/64bit/updates/Packages
# gpgcheck=0
# enable=1
[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache
# 安装软件来测试一下
[root@localhost yum.repos.d]# yum -y install net-tools
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package net-tools.x86_64 0:2.0-0.25.20131004git.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================
Package Arch Version Repository Size
=====================================================================================================
Installing:
net-tools x86_64 2.0-0.25.20131004git.el7 Aliyun_7_base 306 k
Transaction Summary
=====================================================================================================
Install 1 Package
Total download size: 306 k
Installed size: 917 k
Downloading packages:
net-tools-2.0-0.25.20131004git.el7.x86_64.rpm | 306 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : net-tools-2.0-0.25.20131004git.el7.x86_64 1/1
Verifying : net-tools-2.0-0.25.20131004git.el7.x86_64 1/1
Installed:
net-tools.x86_64 0:2.0-0.25.20131004git.el7
Complete!
安装完成,Repository里面显示,是从Aliyun_7_base内获取的,到此,yum源仓库(阿里源)部署完成
CentOS7搭建yum源仓库(阿里源)的更多相关文章
- 设置centos的yum仓库源为阿里源
前提 使我们的主机能够连接到外网 cd /etc/yum.repos.d/ #切换到yum仓库目录下 rm -rf * #删除默认配置仓库 wget -O /etc/yum.repos.d/CentO ...
- [转]centos7 修改yum源为阿里源
centos7 修改yum源为阿里源,某下网络下速度比较快 首先是到yum源设置文件夹里 cd /etc/yum.repos.d 接着备份旧的配置文件 sudo mv CentOS-Base.repo ...
- centos7 修改yum源为阿里源
centos7 修改yum源为阿里源,某下网络下速度比较快 首先是到yum源设置文件夹里 安装base reop源 cd /etc/yum.repos.d 接着备份旧的配置文件 sudo mv Cen ...
- Linux 用脚本编写搭建yum本地仓库
Linux 用脚本编写搭建yum本地仓库 源码如下: #!/bin/bash #该脚本用于自动化搭建本地yum仓库 #挂载光盘 #作者:雨中落叶 #博客:https://www.cnblogs.com ...
- CentOS6.8环境下搭建yum网络仓库
CentOS6.8环境下搭建yum网络仓库 本文利用ftp服务,在CentOS6.8系统下搭建一个yum仓库,然后用另一台虚拟机访问该仓库.并安装程序包 安装ftp服务 查询ftp服务是否安装 [ro ...
- linux远程搭建yum网络仓库《全面解析》
目录 一:远程版本需求 1.yum简介 2.yum安装解析 二:yum安装的生命周期 三:yum私有仓库作用与必要性 四:搭建yum私有仓库 本地版本 1.下载必须的软件包 2.创建软件仓库(就是创建 ...
- ubuntu16.04更改源为阿里源
一.通过系统更换源 第一步:备份原来的源文件cd /etc/apt/ 然后会显示下面的源文件sources.list输入命令sudo cp sources.list sources.list.bak ...
- 搭建YUM本地仓库
本文介绍如何利用CentOS 7 ISO光盘镜像搭建YUM本地仓库. 环境准备: (1)VMware15.5版本虚拟机 (2)CentOS-7-x86_64-DVD-1908光盘镜像文件 1. 搭建Y ...
- Centos7搭建Harbor私有仓库(二)
1 说明 前文Centos7搭建Harbor私有仓库(一)中成功搭建了Harbor,但,是以http方式搭建的,这里我们修改为https方式 以下基于镜像CentOS-7-x86_64-Minimal ...
随机推荐
- Centos7 文件权限理解(持续更新)
后期排版,边学边记边敲 用户详情分析 管理员用户 root 0 虚拟用户 nobody 1-999 普通用户 test001 1000+ 输入ll命令查看当前目录文件详情 根据这张图片可知,目录 ...
- [转]webpack配置本地服务器
亲测,webpack打包vue项目之后生成的dist文件可以部署到 express 服务器上运行. 我的vue项目结构如下: 1. 进入该vue项目目录,打开git bash,执行:npm run b ...
- Spring系列2:Spring容器基本概念和使用
本文内容 简单回顾IoC和DI概念 Spring容器的概念 的xml配置和初始化 容器的基本使用 bean的定义和初始化配置 简单理解IoC和DI概念 什么是IoC控制反转? 通俗地但不严谨地讲,以前 ...
- tmux安装配置与使用
tmux安装 sudo apt-get install tmux tmux配置 在家目录下操作 cd git clone https://github.com/gpakosz/.tmux.git ln ...
- JSP页面使用EL表达式不显示实际数据
今天在学习有关jsp的相关知识内容时,遇到了el表达式只是显示括号里面的内容 代码如下: <%@ page contentType="text/html;charset=UTF-8&q ...
- 个人作业2-Java代码实现数据检索并实现可视化
1.bean实体层 package bean; public class Bean { private String title; private String Abstract; private S ...
- Cesium中文网的朋友们
目前已开通知识星球-Cesium中文网的朋友们 注意:仔细思量好再进来,一旦付费,概不退费.下述内容均尽力而为. 1. 每月一次技术交流(Cesium为主),提供源码. 2. 每人5次/周免费提问(C ...
- openSUSE修改grub来修复对win8的引导
前言:继上一次安装试用各版本linux发行版后,由于做项目将机器纯windows了一把,现在又想安回centos,各种挫折折腾两天玩残一个u盘日,其中包括自己本本的原装系统也崩了,各种泪奔,下面记录一 ...
- golang中channel讲解
1. 无缓冲通道 2. 有缓冲通道 有缓冲通道特点:当channel已经满,在向里面写数据就会阻塞,当channel已经为空,在从里面读数据就会阻塞. 3. 关闭channel package mai ...
- MySQL数据库本地事务原理
在经典的数据库理论里,本地事务具备四大特征: 原子性 事务中的所有操作都是以原子的方式执行的,要么全部成功,要么全部失败: 一致性 事务执行前后,所有的数据都应该处于一致性状态---即要满足数据库表的 ...