赞
踩
如果我们是实施工程师,需要给客户部署服务,但是客户环境无法连接网络,这时通过搭建本地YUM仓库将会很好的解决这个问题。
要想搭建本地YUM仓库,首先数安装包(RPM包),没有安装包,搭建仓库又有何用呢?那RPM包怎样获取呢?同步阿里云镜像源或腾讯云镜像到本地即可。
下载创建仓库的工具
[root@prometheus ~]# yum install createrepo reposync yum-utils -y
移除其他镜像源
[root@prometheus ~]# cd /etc/yum.repos.d/
[root@prometheus yum.repos.d]# mv *.repo old/
腾讯云
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo
下载阿里云repo、epel文件
[root@prometheus yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@repo yum.repos.d]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
生成缓存
[root@prometheus yum.repos.d]# yum clean all #清除之前的yum源缓存
[root@prometheus yum.repos.d]# yum makecache #创建缓存
[root@prometheus yum.repos.d]# yum repolist #查看当前可用的YUM源
同步镜像到本地
大概30G
[root@prometheus ~]# reposync -r base #reposync将根据刚下载的repo下载rpm包到指定文件夹
[root@prometheus ~]# reposync -r extras
[root@prometheus ~]# reposync -r updates
[root@prometheus ~]# reposync -r epel
创建YUM仓库
[root@prometheus ~]# cd /root/base
[root@prometheus ~]# createrepo ./
[root@prometheus ~]# cd /root/extras
[root@prometheus ~]# createrepo ./
[root@prometheus ~]# cd /root/updates
[root@prometheus ~]# createrepo ./
[root@prometheus ~]# cd /root/epel
[root@prometheus ~]# createrepo ./
然后把这几个文件放到一个目录,然后拉到本地硬盘,建议
yum
├── base
├── epel
├── extras
└── updates
这样源数据就获取了,之后可以把这些包通过winscp或SecureFX传输到移动硬盘,到客户现场搭建YUM源了,下边讲一下怎样怎样搭建本地YUM源
比如现在到客户现场了,主机无网络,但是需要安装相关服务,怎么办呢?拿出刚才的硬盘(此种办法是针对一台机器进行操作的,如果局域网内其他机器也需要YUM源,最好使用下边的基于nginx的YUM源)
移除之前的YUM源
[root@node1 ~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/old/
拉取硬盘数据(yum[epel,base,updates,extra])到要操作的机器
配置YUM源
[root@node1 ~]# vim /etc/yum.repos.d/base.repo [base] name=CentOS-Base baseurl=file:///root/yum/base path=/ enabled=1 #是否将该仓库做为软件包提供源 gpgcheck=0 #是否进行gpg校验 [updates] name=CentOS-Updates baseurl=file:///root/yum/updates path=/ enabled=1 gpgcheck=0 [extras] name=CentOS-Extras baseurl=file:///root/yum/extras path=/ enabled=1 gpgcheck=0 [root@node1 ~]# vim /etc/yum.repos.d/epel.repo [epel] name=CentOS-Epel baseurl=file:///root/yum/epel path=/ enabled=1 gpgcheck=0
清除之前的yum源缓存
[root@node1 ~]# yum clean all
建立缓存
[root@node1 ~]# yum makecache
列出当前yum源信息,并生成元数据
[root@node1 ~]# yum repolist
到此本地YUM仓库搭建完成,如果在对应的仓库中加入软件包时,需要更新仓库
更新仓库
[root@node1 ~]# createrepo --update /root/yum/epel
在一台无网络机器上配置基于nginx的YUM源,本台机器和其他机器都可以使用
也是将yum[epel…]拉到对应机器
修改nginx配置文件
[root@node1 ~]# vim /etc/nginx/nginx.conf #主要修改有注释的两个地方
server {
listen 80;
server_name localhost;
location / {
root /root/yum/; #修改成yum仓库所在的目录
index index.html index.htm;
autoindex on; #开启目录
}
重启nginx
[root@node1 ~]# nginx -t 验证无误进行下一步
[root@node1 ~]# systemctl restart nginx
移除其他镜像源
[root@node1 ~]# cd /etc/yum.repos.d/
[root@node1 yum.repos.d]# mv *.repo old/
本台机器配置yum源
[root@node1 ~]# vim /etc/yum.repos.d/base.repo [base] name=CentOS-Base baseurl=http://192.168.1.10/base path=/ enabled=1 #是否将该仓库做为软件包提供源 gpgcheck=0 #是否进行gpg校验 [updates] name=CentOS-Updates baseurl=http://192.168.1.10/updates path=/ enabled=1 gpgcheck=0 [extras] name=CentOS-Extras baseurl=http://192.168.1.10/extras path=/ enabled=1 gpgcheck=0 [root@node1 ~]# vim /etc/yum.repos.d/epel.repo [epel] name=CentOS-Epel baseurl=http://192.168.1.10/epel path=/ enabled=1 gpgcheck=0
做缓存
[root@node1 ~]# yum clean all
[root@node1 ~]# yum makecache
查看源列表
[root@node1 ~]# yum repolist
其他机器操作
只需配置repo即可,repo相同
如果不想不想把30多G的数据在拷贝到客户机器上,可以直接在win10本地搭建nginx,让客户机器以本地机器为YUM仓库,前提是本地机器和客户机器能相互ping通。
下载nginx-win版
http://nginx.org/en/download.html 下载网址
http://nginx.org/download/nginx-1.18.0.zip
下载后解
修改nginx配置文件
启动nginx
PowerShell查看nginx进程是否已启动(后台运行)
tasklist
杀掉nginx进程
kill -ProcessName nginx
查看本地IP
ipconfig
客户机配置YUM源
同上操作
[root@node1 ~]# vim /etc/yum.repos.d/base.repo [base] name=CentOS-Base baseurl=http://192.168.1.3/base path=/ enabled=1 #是否将该仓库做为软件包提供源 gpgcheck=0 #是否进行gpg校验 [updates] name=CentOS-Updates baseurl=http://192.168.1.3/updates path=/ enabled=1 gpgcheck=0 [extras] name=CentOS-Extras baseurl=http://192.168.1.3/extras path=/ enabled=1 gpgcheck=0 [root@node1 ~]# vim /etc/yum.repos.d/epel.repo [epel] name=CentOS-Epel baseurl=http://192.168.1.3/epel path=/ enabled=1 gpgcheck=0
清理缓存,创建缓存
yum clean all
yum makecache
yum repolist 查看
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。