克隆阿里云yum源

目录

一.准备工作

二.给服务端配置阿里云yum源

三.在服务端nginx中克隆阿里云yum源

四.给客户端配置


应用场景

        在公司内网中,可能无法连接外部网络,这时需要我们将外部yum源中的包克隆到本地。

一.准备工作

实验服务器两台:

192.168.134.139(服务端)                        192.168.134.140(客户端)

测试两台主机的连通性  ping。

①在服务端上操作:测试连通性并关闭防火墙

[root@testhost ~]# ping 192.168.134.140        #测试连通性
PING 192.168.134.140 (192.168.134.140) 56(84) bytes of data.
64 bytes from 192.168.134.140: icmp_seq=1 ttl=64 time=0.337 ms
64 bytes from 192.168.134.140: icmp_seq=2 ttl=64 time=0.784 ms
^C
--- 192.168.134.140 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.337/0.560/0.784/0.224 ms
[root@testhost ~]# systemctl stop firewalld        #关闭防火墙
[root@testhost ~]# setenforce 0                    #临时关闭selinux
setenforce: SELinux is disabled

②在客户端上的操作:测试连通性并关闭防火墙。

[root@testhost ~]# ping 192.168.134.139
PING 192.168.134.139 (192.168.134.139) 56(84) bytes of data.
64 bytes from 192.168.134.139: icmp_seq=1 ttl=64 time=0.161 ms
64 bytes from 192.168.134.139: icmp_seq=2 ttl=64 time=0.198 ms
^C
--- 192.168.134.139 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.161/0.179/0.198/0.022 ms
[root@testhost ~]# systemctl  stop firewalld
[root@testhost ~]# setenforce  0
setenforce: SELinux is disabled

二.给服务端配置阿里云yum源

①进入yum配置文件并删除原有的yum源

[root@testhost ~]# cd /etc/yum.repos.d/
[root@testhost yum.repos.d]# rm -rf *

②配置阿里云yum源


#配置阿里云的base源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#配置阿里云epel源
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

③清除缓存并加载新的yum源

yum  clean all   &&  yum  makecache

三.在服务端nginx中克隆阿里云yum源

①安装nginx以及工具

[root@testhost yum.repos.d]# yum -y install nginx   yum-utils   createrepo

②清空/usr/share/nginx/html下的所有文件

[root@testhost yum.repos.d]# cd /usr/share/nginx/html/ 
[root@testhost html]# rm -rf *            #清空所有文件

③同步(克隆)阿里云yum源

[root@testhost html]# reposync  -r base  -r epel    #同步(克隆)

2d3cf3bff8534107b671658b032d2e64.png

base源和epel源已克隆。

④制作base源和epel源

单克隆base和epel文件还不能称为yum源,还需repodata文件作为支持。

[root@testhost html]# createrepo  base
Spawning worker 0 with 3 pkgs
Spawning worker 1 with 3 pkgs
Spawning worker 2 with 2 pkgs
Spawning worker 3 with 2 pkgs
Spawning worker 4 with 2 pkgs
Spawning worker 5 with 2 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@testhost html]# createrepo epel
Spawning worker 0 with 4 pkgs
Spawning worker 1 with 3 pkgs
Spawning worker 2 with 3 pkgs
Spawning worker 3 with 3 pkgs
Spawning worker 4 with 3 pkgs
Spawning worker 5 with 3 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

⑤配置nginx的配置文件

[root@testhost html]# vim /etc/nginx/nginx.conf

在server中添加

location / {
    root /usr/share/nginx/html;        #yum源存放位置
    autoindex on;                #打开目录浏览功能,自动索引
}

f3b351c87b2a460b9311380481812f27.png

⑥开启nginx

[root@testhost html]# systemctl  start nginx

四.给客户端配置

①删除原有的yum源

[root@testhost yum.repos.d]# cd /etc/yum.repos.d/
[root@testhost yum.repos.d]# rm -rf *

②配置新的yum源

[root@testhost yum.repos.d]# vim http.repo
[base]
name=base
baseurl=http://192.168.134.139/base
gpgcheck=0
enabled=1
[epel]
name=epel
baseurl=http://192.168.134.139/epel
gpgcheck=0
enabled=1 

③清除原有的yum源并加载新的元数据

[root@testhost yum.repos.d]# yum clean all  &&  yum  makecache  

④查看yum源信息

[root@testhost yum.repos.d]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识                            源名称                                      状态
base                              base                                       10072           
epel                              epel                                       13375
repolist: 23447

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值