博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
企业实际应用之同步远程yum源到本地
阅读量:6092 次
发布时间:2019-06-20

本文共 13119 字,大约阅读时间需要 43 分钟。

最近在弄平台化工作,目前公网dns已经弄完,这样解析工作就很方便了,同时作为公网dns,就不需要每台主机添加nameserver来执行ip,下一步需要弄本地yum源,如果不弄的话,如果机房服务器过多,多个同时yum安装软件的话,很浪费带宽,而且yum源还不容易控制,比如有的软件安装需要epel源,有的需要rpmforge源,所以为了方便管理与控制,在机房内网搭建了一个本地yum源,同步远程的base、epel与rpmforge源(主要是centos 5与6系统的32位于64位的源),内网的主机都通过dns解析后的域名来进行访问。

一、同步远程yum源到本地

下面是我的同步脚本

#!/bin/bash#Script name:rsync_yumrepo.shRsyncBin="/usr/local/rsync-3.1.0/bin/rsync"RsyncPerm='-avrt --delete --no-iconv --bwlimit=1000'Centos_5_base='/data/yum_repo/Centos-5/Base/'Centos_5_epel='/data/yum_repo/Centos-5/Epel/'Centos_5_rpmforge='/data/yum_repo/Centos-5/Rpmforge/'Centos_6_base='/data/yum_repo/Centos-6/Base/'Centos_6_epel='/data/yum_repo/Centos-6/Epel/'Centos_6_rpmforge='/data/yum_repo/Centos-6/Rpmforge/'LogFile='/data/yum_repo/rsync_yum_log'Date=`date +%Y-%m-%d`#checkfunction check {if [ $? -eq 0 ];then    echo -e "\033[1;32mRsync is success!\033[0m" >>$LogFile/$Date.logelse    echo -e "\033[1;31mRsync is fail!\033[0m" >>$LogFile/$Date.logfi}if [ ! -d "$LogFile" ];then    mkdir $LogFilefi#rsync centos 5 baseecho 'Now start to rsync centos 5 base!' >>$LogFile/$Date.log$RsyncBin $RsyncPerm rsync://mirrors.yun-idc.com/centos/5/os/ $Centos_5_base >>$LogFile/$Date.logcheck#rsync centos 5 epelecho 'Now start to rsync centos 5 epel!' >>$LogFile/$Date.log$RsyncBin $RsyncPerm --exclude=SRPMS/ --exclude=ppc/ rsync://mirrors.yun-idc.com/epel/5/ $Centos_5_epel >>$LogFile/$Date.logcheck#rsync centos 5 rpmforgeecho 'Now start to rsync centos 5 i386 rpmforge!' >>$LogFile/$Date.log$RsyncBin $RsyncPerm rsync://ftp-stud.fht-esslingen.de/dag/redhat/el5/en/i386/rpmforge/ $Centos_5_rpmforge/i386/ >>$LogFile/$Date.logcheckecho 'Now start to rsync centos 5 x86_64 rpmforge!' >>$LogFile/$Date.log$RsyncBin $RsyncPerm rsync://ftp-stud.fht-esslingen.de/dag/redhat/el5/en/x86_64/rpmforge/ $Centos_5_rpmforge/x86_64/ >>$LogFile/$Date.logcheck#rsync centos 6 baseecho 'Now start to rsync centos 6 base!' >>$LogFile/$Date.log$RsyncBin $RsyncPerm rsync://mirrors.yun-idc.com/centos/6/os/ $Centos_6_base >>$LogFile/$Date.logcheck#rsync centos 6 epelecho 'Now start to rsync centos 6 epel!' >>$LogFile/$Date.log$RsyncBin  $RsyncPerm --exclude=SRPMS/ --exclude=ppc64/ rsync://mirrors.yun-idc.com/epel/6/ $Centos_6_epel  >>$LogFile/$Date.logcheck#rsync centos 6 rpmforgeecho 'Now start to rsync centos 6 i386 rpmforge!' >>$LogFile/$Date.log$RsyncBin $RsyncPerm rsync://ftp-stud.fht-esslingen.de/dag/redhat/el6/en/i386/rpmforge/ $Centos_6_rpmforge/i386/ >>$LogFile/$Date.logcheckecho 'Now start to rsync centos 6 x86_64 rpmforge!' >>$LogFile/$Date.log$RsyncBin $RsyncPerm rsync://ftp-stud.fht-esslingen.de/dag/redhat/el6/en/x86_64/rpmforge/ $Centos_6_rpmforge/x86_64/ >>$LogFile/$Date.logcheck

主要是使用rsync(最新的3.1.0版本),然后然后tcp模式来进行连接,同步mirrors.yun-idc.com的base与epel源到本地,同步ftp-stud.fht-esslingen.de的rpmforge源到本地。然后文件目录与rsync参数自己根据需求修改。

把这个脚本放到crontab里,让它每天凌晨同步

00 02 * * * /bin/bash /data/yum_repo/rsync_yum_shell/rsync_yumrepo.sh

同步后会有一个日子记录,下面是我的日志

Now start to rsync centos 5 base!*****************************************************Welcome to CDS(yun-idc.com) Mirror Site Rsync Server!*****************************************************receiving incremental file listsent 42 bytes  received 305,322 bytes  55,520.73 bytes/sectotal size is 10,349,249,542  speedup is 33,891.52Rsync is success!Now start to rsync centos 5 epel!*****************************************************Welcome to CDS(yun-idc.com) Mirror Site Rsync Server!*****************************************************receiving incremental file listsent 64 bytes  received 1,284,809 bytes  856,582.00 bytes/sectotal size is 17,669,250,363  speedup is 13,751.75Rsync is success!Now start to rsync centos 5 i386 rpmforge!Welcome to the ftp-stud.hs-esslingen.de archives.If have any unusual problems, please report them via e-mail torsync@ftp-stud.hs-esslingen.de.  All transfers are logged.  If you don't like this policy, then disconnect now.  This server does not support --checksum (-c)  This server does not support --compress (-z)receiving incremental file list./RPMS/sent 33 bytes  received 548,502 bytes  84,390.00 bytes/sectotal size is 6,891,180,123  speedup is 12,562.88Rsync is success!Now start to rsync centos 5 x86_64 rpmforge!Welcome to the ftp-stud.hs-esslingen.de archives.If have any unusual problems, please report them via e-mail torsync@ftp-stud.hs-esslingen.de.  All transfers are logged.  If you don't like this policy, then disconnect now.  This server does not support --checksum (-c)  This server does not support --compress (-z)receiving incremental file list./RPMS/sent 33 bytes  received 551,172 bytes  100,219.09 bytes/sectotal size is 6,500,184,928  speedup is 11,792.68Rsync is success!Now start to rsync centos 6 base!*****************************************************Welcome to CDS(yun-idc.com) Mirror Site Rsync Server!*****************************************************receiving incremental file listsent 42 bytes  received 546,204 bytes  364,164.00 bytes/sectotal size is 11,109,838,945  speedup is 20,338.53Rsync is success!Now start to rsync centos 6 epel!*****************************************************Welcome to CDS(yun-idc.com) Mirror Site Rsync Server!*****************************************************receiving incremental file listsent 66 bytes  received 1,749,197 bytes  233,235.07 bytes/sectotal size is 30,814,156,298  speedup is 17,615.51Rsync is success!Now start to rsync centos 6 i386 rpmforge!Welcome to the ftp-stud.hs-esslingen.de archives.If have any unusual problems, please report them via e-mail torsync@ftp-stud.hs-esslingen.de.  All transfers are logged.  If you don't like this policy, then disconnect now.  This server does not support --checksum (-c)  This server does not support --compress (-z)receiving incremental file list./RPMS/sent 33 bytes  received 225,253 bytes  50,063.56 bytes/sectotal size is 2,342,484,019  speedup is 10,397.82Rsync is success!Now start to rsync centos 6 x86_64 rpmforge!Welcome to the ftp-stud.hs-esslingen.de archives.If have any unusual problems, please report them via e-mail torsync@ftp-stud.hs-esslingen.de.  All transfers are logged.  If you don't like this policy, then disconnect now.  This server does not support --checksum (-c)  This server does not support --compress (-z)receiving incremental file list./RPMS/sent 33 bytes  received 226,542 bytes  50,350.00 bytes/sectotal size is 2,180,556,413  speedup is 9,623.99Rsync is success!

上面日志都是没有新的同步情况,是因为我之前已经同步完成,远程源没有变化所以我本地也没有变更,下面是我同步的网卡流量监控情况

可以看到传输的最大速度是8.65Mbs

二、客户端的repo文件

1、配置web服务器,我选择nginx

我的vhost配置为

server {        listen       80;    server_name yum-server.****.net;    index index.html index.htm index.php;    root  /data/yum_repo/;    error_page 502 = /502.html;    location ~ .*\.(php|php5)?$ {                #fastcgi_pass  unix:/tmp/php-cgi.sock;        fastcgi_pass  127.0.0.1:9000;        fastcgi_index index.php;        include fastcgi.conf;    }    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|mp3)$ {        expires      30d;    }    location ~ .*\.(js|css)?$ {        expires      12h;    }}    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '        '$status $body_bytes_sent "$http_referer" '        '"$http_user_agent" $http_x_forwarded_for';   access_log  /data/logs/access.log  access;

这个servername是你在dns里设置的名称,为了保密我没有写我真实的dns,大家可以根据自己的需求修改。

2、repo文件

Centos-Base-5.repo

[Base]name=CentOS-Base5 $basearchbaseurl=http://yum-server.****.net/Centos-5/Base/$basearchenable=1gpgcheck=1gpgkey=http://yum-server.****.net/Centos-5/Base/$basearch/RPM-GPG-KEY-CentOS-5[Epel]name=CentOS-Base5 $basearchbaseurl=http://yum-server.****.net/Centos-5/Epel/$basearchenable=1gpgcheck=0[Rpmforge]name=CentOS-Base5 $basearchbaseurl=http://yum-server.****.net/Centos-5/Rpmforge/$basearchenable=1gpgcheck=0

Centos-Base-6.repo

[Base]name=CentOS-Base6 $basearchbaseurl=http://yum-server.****.net/Centos-6/Base/$basearchenable=1gpgcheck=1gpgkey=http://yum-server.****.net/Centos-6/Base/$basearch/RPM-GPG-KEY-CentOS-6[Epel]name=CentOS-Base6 $basearchbaseurl=http://yum-server.****.net/Centos-6/Epel/$basearchenable=1gpgcheck=0[Rpmforge]name=CentOS-Base6 $basearchbaseurl=http://yum-server.****.net/Centos-6/Rpmforge/$basearchenable=1gpgcheck=0

然后进行下面操作:

1、按照不同的系统选择不同的repo文件,放到服务器的/etc/yum.repos.d里;

2、删除之前/etc/yum.repos.d里的repo;

3、清理缓存yum clean all;

4、将服务器上的软件包信息现在本地缓存,以提高搜索安装软件的速度 yum makecache.

[root@ip-10-10-13-8 bin]# cd /etc/yum.repos.d[root@ip-10-10-13-8 yum.repos.d]# ll总用量 4-rw-r--r-- 1 root root 453 12月 16 10:04 Centos-Base-6.repo[root@ip-10-10-13-8 yum.repos.d]# yum clean allLoaded plugins: aliases, changelog, downloadonly, fastestmirror, kabi, presto, security, tmprepo, verify, versionlockLoading support for CentOS kernel ABICleaning repos: Base Epel RpmforgeCleaning up EverythingCleaning up list of fastest mirrors0 delta-package files removed, by presto[root@ip-10-10-13-8 yum.repos.d]# yum makecacheLoaded plugins: aliases, changelog, downloadonly, fastestmirror, kabi, presto, security, tmprepo, verify, versionlockLoading support for CentOS kernel ABIDetermining fastest mirrorsBase                                                                                                                                                                    | 3.7 kB     00:00   Base/group_gz                                                                                                                                                           | 220 kB     00:00   Base/filelists_db                                                                                                                                                       | 5.9 MB     00:00   Base/primary_db                                                                                                                                                         | 4.4 MB     00:00   Base/other_db                                                                                                                                                           | 2.8 MB     00:00   Epel                                                                                                                                                                    | 4.2 kB     00:00   Epel/group_gz                                                                                                                                                           | 237 kB     00:00   Epel/filelists_db                                                                                                                                                       | 7.9 MB     00:00   Epel/primary_db                                                                                                                                                         | 5.7 MB     00:00   Epel/other_db                                                                                                                                                           | 3.3 MB     00:00   Epel/updateinfo                                                                                                                                                         | 678 kB     00:00   Rpmforge                                                                                                                                                                | 1.9 kB     00:00   Rpmforge/filelists_db                                                                                                                                                   | 2.3 MB     00:00   Rpmforge/primary_db                                                                                                                                                     | 2.7 MB     00:00   Rpmforge/other_db                                                                                                                                                       | 564 kB     00:00   Metadata Cache Created[root@ip-10-10-13-8 yum.repos.d]# yum repolistLoaded plugins: aliases, changelog, downloadonly, fastestmirror, kabi, presto, security, tmprepo, verify, versionlockLoading support for CentOS kernel ABILoading mirror speeds from cached hostfilerepo id                                                                                repo name                                                                                         statusBase                                                                                   CentOS-Base6 x86_64                                                                                6,367Epel                                                                                   CentOS-Base6 x86_64                                                                               10,138Rpmforge                                                                               CentOS-Base6 x86_64                                                                                4,650repolist: 21,155[root@ip-10-10-13-8 yum.repos.d]# yum list|grep echopingechoping.x86_64                          5.2.0-1.2.el6.rf               @Rpmforge

现在本地yum源就已经完成,可以控制软件源,并且由于走内网所有不浪费机房公网网络流量。

转载地址:http://fgrwa.baihongyu.com/

你可能感兴趣的文章
vue swiper中的大坑
查看>>
Template Metaprogramming with Modern C++: Introduction
查看>>
二进制、八进制、十进制、十六进制之间的转换
查看>>
洛谷——P1596 [USACO10OCT]湖计数Lake Counting
查看>>
智力大冲浪
查看>>
算法思想(一)理解复杂度
查看>>
JSONP实现跨域
查看>>
Python基础班---第一部分(基础)---Python基础知识---计算机组成原理
查看>>
虚拟机VMware 9安装苹果MAC OSX 10.8图文教程
查看>>
POJ3694 Network
查看>>
Matconvnet环境配置一些坑
查看>>
微信小程序开发-框架
查看>>
redo、undo、binlog的区别
查看>>
DropDownList 控制日期控件显示格式
查看>>
RecycleView设置顶部分割线(记录一个坑)
查看>>
【设计模式系列】单例模式的7种写法
查看>>
汉字转拼音 (转)
查看>>
Machine Learning Techniques -6-Support Vector Regression
查看>>
会计基础_001
查看>>
C/C++——#和##操作符
查看>>