CentOS 7 搭建本地YUM仓库,并定期同步阿里云源
目录导航:
5. 安装nginx开启目录权限保证本地机器可以直接本地yum源
1. 系统环境
# cat /etc/centos-release
CentOS Linux release 7.6. (Core) # uname -r
3.10.-.el7.x86_64 # ip a |awk 'NR==9{print $2}'|awk -F '/' '{print $1}'
10.0.0.100
2. 修改yum 源为阿里云源
2.1 备份系统自带的yum源
# tar -zcvf CentOS-bk.tar.gz /etc/yum.repos.d/CentOS-*
2.2 修改yum源
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo # wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
或者
# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo # curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
2.3 检验阿里云源是否正常
# yum repolist Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com #仓库标识仓库名称状态 repo id repo name status !base//x86_64 CentOS- - Base - mirrors.aliyun.com , !epel/x86_64 Extra Packages for Enterprise Linux - x86_64 , !extras//x86_64 CentOS- - Extras - mirrors.aliyun.com !updates//x86_64 CentOS- - Updates - mirrors.aliyun.com , repolist: ,
3. 安装yum相关的软件
# yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel createrepo yum-utils
yum-utils:reposync同步工具
createrepo:编辑yum库工具
plugin-priorities:控制yum源更新优先级工具,这个工具可以用来控制进行yum源检索的先后顺序,建议可以用在client端。
注:由于很多人喜欢最小化安装,上边软件是一些常用环境。
4. 根据源标识同步源到本地目录
4.1 创建本地目录
# mkdir /mirror
4.2 同步到本地目录
# reposync -p / mirror
注:不用担心没有创建相关目录,系统自动创建相关目录,并下载,时间较长请耐心等待。
可以用 repo -r --repoid=repoid 指定要查询的repo id,可以指定多个(# reposync -r base -p /mirror #这里同步base目录到本地)
更新新的rpm包
# reposync -np /mirror
注:时间同样较长,请耐心等待。
4.3 创建索引
# createrepo -po /mirror/base/ /mirror/base/
# createrepo -po /mirror/extras/ /mirror/extras/
# createrepo -po /mirror/updates/ /mirror/updates/
# createrepo -po /mirror/epel/ /mirror/epel/
4.4 更新源数据
# createrepo --update /mirror/base
# createrepo --update /mirror/extras
# createrepo --update /mirror/updates
# createrepo --update /mirror/epel
4.5 创建定时任务脚本
# vim /mirror/script/centos_yum_update.sh
#!/bin/bash
echo 'Updating Aliyum Source'
DATETIME=`date +%F_%T`
exec > /var/log/aliyumrepo_$DATETIME.log
reposync -np /mirror
if [ $? -eq ];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
4.6 将脚本加入到定时任务中
# crontab -e
# Updating Aliyum Source
* * [ $(date +%d) -eq $(cal | awk 'NR==3{print $NF}') ] && /bin/bash /mirror/script/centos_yum_update.sh
每月第一个周六的13点更新阿里云yum源
5. 安装nginx开启目录权限保证本地机器可以直接本地yum源
5.1 创建运行账户
# groupadd nginx
# useradd -r -g nginx -s /bin/false -M nginx
# yum install nginx -y
5.2 修改nginx 配置文件
# vim nginx.conf
worker_processes ;
events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout ;
server {
listen ;
server_name localhost;
root /mirror ; #这里是yum源存放目录
location / {
autoindex on; #打开目录浏览功能
autoindex_exact_size off; # off:以可读的方式显示文件大小
autoindex_localtime on; # on/off:是否以服务器的文件时间作为显示的时间
charset utf-,gbk; #展示中文文件名
index index.html;
}
error_page /50x.html;
location = /50x.html {
root html;
}
}
}
6. 客户端创建repo文件
注:搭建好后yum安装速度并没有想象中的那么快,安装时解决依赖速度也很慢。
# vim CentOS7.x-Base.repo
[base]
name=CentOS-$releasever - Base - mirror.template.com
baseurl=http://10.0.0.100/base/
path=/
enabled=
gpgcheck= [updates]
name=CentOS-$releasever - Updates - mirror.template.com
baseurl=http://10.0.0.100/updates/
path=/
enabled=
gpgcheck= [extras]
name=CentOS-$releasever - Extras - mirrors.template.com
baseurl=http://10.0.0.100/extras/
path=/
enabled=
gpgcheck= [epel]
name=CentOS-$releasever - epel - mirrors.template.com
baseurl=http://10.0.0.100/epel/
failovermethod=priority
enabled=
gpgcheck=
CentOS 7 搭建本地YUM仓库,并定期同步阿里云源的更多相关文章
- CentOS7搭建本地YUM仓库,并定期同步阿里云源
CentOS7同步阿里云镜像rpm包并自建本地yum仓库 系统环境 # cat /etc/centos-release CentOS Linux release 7.6.1810 (Core) # u ...
- centos 7 搭建本地yum仓库
首先需要创建一个目录 mkdir /1 #在根目录下创建一个名字为1的目录 将光盘挂载到创建的这个目录 mount /dev/cdrom /1 yum命令配置文件在/etc/yum.repos.d ...
- 其他综合-搭建本地yum仓库及自制rpm包
搭建本地yum仓库及自制rpm包 实验目的 为方便本地 yum 的管理,建本地 yum 仓库,实现局域网内部快速安装常用软件 实验环境 VMware:12版本 系统版本:CentOS Linux re ...
- 如何手工搭建本地Yum仓库
如何手工搭建本地Yum仓库(重点推荐) https://www.linuxidc.com/Linux/2016-09/135480.htm CentOS7.2 创建本地YUM源和局域网YUM源: h ...
- 搭建本地YUM仓库
YUM介绍 yum(yellow dog updater modified)为多个Linux发行版的软件包管理工具,Redhat RHEL CentOS Fedora YUM主要用于自动安装,升级rp ...
- CentOS 7搭建本地yum源和局域网yum源
这两天在部署公司的测试环境,在安装各种中间件的时候,发现各种依赖都没有:后来一检查,发现安装的操作系统是CentOS Mini版,好吧,我认了:为了完成测试环境的搭建,我就搭建了一个局域网的yum源. ...
- 使用3种协议搭建本地yum仓库
关闭防火墙和selinux [root@qls yum.repos.d]# systemctl stop firewalld (stop,start,disable,enable) [root@qls ...
- 搭建本地yum仓库(centos 7.5)
1. 保留下载的软件包 [root@zabbix-server01 ~]# vim /etc/yum.conf keepcache=1 #开启后下载的软件都会保存到本地 2.将软件进行下载,并将所有r ...
- 在VMware下通过挂载系统光盘搭建本地yum仓库的方法
一.虚拟机的安装 首先你要有一个VMware虚拟机,没有软件的朋友可以看我的前几篇博客 安装VMware虚拟机 二.进入虚拟机(在这里我们进入一个Linux虚拟机下的CentOS操作系统进行演示) 首 ...
随机推荐
- laravel nginx下 css 和js 加载 重写规则
server { listen 80; server_name test.hanwen.com; #charset koi8-r; #access_log logs/host.access.log m ...
- 包装类和toString和static关键字
包装类 针对八种基本数据类型定义的引用类型. 有类的特点,可以调用类中的方法. 基本数据类型 包装类 boolean Boolean byte Byte short Short int Integer ...
- kubernetes从入门到放弃(二)
kubernetes对象之pod 1.pod的认识 Pod直译是豆荚,可以把容器想像成豆荚里的豆子,把一个或多个关系紧密的豆子包在一起就是豆荚(一个Pod).在Kubernetes中我们不会直接操作容 ...
- python中:from * import 与 import 详解
在python 中导入模块是我们最常用的功能,基本每个.py 文件中都会有 import 或者是 from * import 语句,可是,这两种方法有什么不同,有该怎么用?今天就好好分析一下. 先上定 ...
- git 修改分支 删除分支 新增分支
一.修改分支名 1.本地分支重命名 git branch -m oldName newName 2.将重命名后的分支推送到远程 git push origin newName 3.重新更新所有分支 g ...
- java 依赖注入
https://blog.csdn.net/coderder/article/details/51897721 前言 在软件工程领域,依赖注入(Dependency Injection)是用于实现控制 ...
- String_Java
1.substring() 方法返回字符串的子字符串. 语法 public String substring(int beginIndex)//返回第beginIndex个字符以后的子字符串 或 pu ...
- C++中的随机数
事情的开始是这样的,在大二的时候,写了几种排序算法,为了测试,就要为数组(或者容器)赋予一些随机初值,自然就用到了C/C++中的随机函数. 当时为了调用简单,将随机数赋值的过程写到了一个单独的函数里, ...
- vs code 本地调试配置
{ "name": "使用本机 Chrome 调试", "type": "chrome", "request& ...
- Linux centosVMware Tomcat介绍、安装jdk、安装Tomcat
一.Tomcat介绍 Tomcat是Apache软件基金会(Apache Software Foundation)的Jakarta项目中的一个核心项目,由Apache.Sun和其他一些公司及个人共同开 ...