8

###Centos7同步阿里yum仓库 搭建yum私有仓库

 1 year ago
source link: https://blog.51cto.com/u_15397018/5429206
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

###Centos7同步阿里yum仓库 搭建yum私有仓库

原创

韦建国 2022-06-30 08:38:44 博主文章分类:Linux ©著作权

文章标签 html nginx centos 文章分类 Linux 系统/运维 私藏项目实操分享 阅读数204

确认在预拉取yum包的机子关于网络的各项服务正常,拉取的过程对网路的要求挺高,今天用50M宽带拉取大概5个多小时。

另在拉取的机子上配置好阿里的base源和epel源。

1.修改yum源仓库

[root@mini2 /]# rm -rf /etc/yum.repos.d/*
[root@mini2 /]# wget -O /etc/yum.repos.d/base.repo http://mirrors.aliyun.com/repo/Centos-7.repo //base源
[root@mini2 /]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo //扩展源
[root@mini2 /]# yum clean all
[root@mini2 /]# yum makecache

以上为阿里开放的基本源和扩展源,根据需求程度自己拉取

2.用yum repolist检查本机连接的源库是否正常,若是正常会出现每个源的明细信息

3.安装软件(若安装直接进行下一步)

[root@mini2 /]# yum install -y yum-utils createrepo wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel

二、拉取

1.创建源拉取之后存放的目录

[root@mini2 /]# mkdir -p /var/www/html/mirrors

2.拉取远端至本地

[root@mini2 /]# reposync -p /var/www/html/mirrors

3.更新最新的yum仓库中的rpm包(此步可省略,因为上步已经拉取到了最新的)

[root@mini2 /]# reposync -np /var/www/html/mirrors

三、创建元数据索引

[root@mini2 /]# createrepo -po /var/www/html/mirrors/base/ /var/www/html/mirrors/base/
[root@mini2 /]# createrepo -po /var/www/html/mirrors/extras/ /var/www/html/mirrors/extras/
[root@mini2 /]# createrepo -po /var/www/html/mirrors/updates/ /var/www/html/mirrors/updates/
[root@mini2 /]# createrepo -po /var/www/html/mirrors/epel/ /var/www/html/mirrors/epel/

四、更新元数据索引(此步是增量更新rpm包之后执行更新元数据索引的,重复执行上步也可只不过全量数据较大,考验处理

器计算能力)

[root@mini2 /]# createrepo --update /var/www/html/mirrors/base
[root@mini2 /]# createrepo --update /var/www/html/mirrors/extras
[root@mini2 /]# createrepo --update /var/www/html/mirrors/updates
[root@mini2 /]# createrepo --update /var/www/html/mirrors/epel

五、发布  

推荐使用nginx,阿里用的Tengine,nginx相对于apache的性能你懂

[root@mini2 /]# yum install nginx -y

编辑其中的根目录定位至 /var/www/html/mirrors #若是找不到nginx的安装目录使用rpm -ql nginx 查找nginx安装文件的目录文件

[root@mini2 /]# vim /etc/nginx/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root /mirror ; #这里是yum源存放目录,实际填写路径按照仓库路径填写
location / {
autoindex on; #打开目录浏览功能
autoindex_exact_size off; # off:以可读的方式显示文件大小
autoindex_localtime on; # on、off:是否以服务器的文件时间作为显示的时间
charset utf-8,gbk; #展示中文文件名
index index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

六、编写repo文件发布给客户端

[root@mini2 /]# vim /etc/yum.repos.d/Centos7-Base.repo
[base]
name=CentOS-$releasever - Base - mirror.template.com
baseurl=http://10.0.0.100/base/
path=/
enabled=1
gpgcheck=0

[updates]
name=CentOS-$releasever - Updates - mirror.template.com
baseurl=http://10.0.0.100/updates/
path=/
enabled=1
gpgcheck=0

[extras]
name=CentOS-$releasever - Extras - mirrors.template.com
baseurl=http://10.0.0.100/extras/
path=/
enabled=1
gpgcheck=0

[epel]
name=CentOS-$releasever - epel - mirrors.template.com
baseurl=http://10.0.0.100/epel/
failovermethod=priority
enabled=1
gpgcheck=0

七、定时同步

将下面更新语句按照自己的需求进行crontab -e

原理还是前边的reposync -np /var/www/html/mirrors先更新 再update元数据索引

[root@mini2 /]# createrepo --update /var/www/html/mirrors/base
[root@mini2 /]# createrepo --update /var/www/html/mirrors/extras
[root@mini2 /]# createrepo --update /var/www/html/mirrors/updates
[root@mini2 /]# createrepo --update /var/www/html/mirrors/epel

八、过程中的错误

PS:你家网速要不错,不然很多包失败等一次拉完之后需要第二次重新拉取,第二次拉去不会重复拉取

一直心心念的清空iptables规则,关闭firewalld,别忘了还有非常重要的一个内核防火墙setenforce 0一下.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK