通过 rsync 搭建 CentOS 本地 yum 源服务器

说明:

操作系统:CentOS 6.x

主机名:yum.base.com

IP 地址:192.168.27.233(生产区服务器)

实现目的:由于生产区服务器无法上外网,为了方便生产区安装软件,同步 yum 镜像站点的内容到此服务器,向生产区提供 yum服务。

RSYNC 代理上网:

[root@yum ~]# vim /etc/profile

export RSYNC_PROXY="repo.base.com:3128"

[root@yum ~]# source /etc/profile

准备篇:

一、安装 HTTP 服务

这里使用 NGINX 提供 HTTP 服务。

NGINX 的安装

[root@yum ~]# cd /opt/nginx-1.12.1

[root@yum nginx-1.12.1]# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre

[root@yum nginx-1.12.1]# make

[root@yum nginx-1.12.1]# make install

 二、系统约定

NGINX 系统根目录:/opt/yum_data/

三、开启 NGINX 目录浏览功能

[root@yum conf]# vim nginx.conf
user root;
server {
listen 80;
server_name yum.base.bjebc.com;
#charset koi8-r;
#access_log logs/host.access.log main;
root /opt/yum_data;
location / {
autoindex on;                              #<--开启nginx目录浏览功能
autoindex_exact_size off;                        #<--文件大小从KB开始显示
autoindex_localtime on;                         #<--显示文件修改时间为服务器本地时间
   }
}
[root@yum ~]# cd /usr/local/nginx/sbin/
[root@yum sbin]# nginx

安装篇:

一、创建镜像文件存放目录

[root@yum ~]# mkdir /opt/yum_data/centos/6/{extras,os,updates}/x86_64 -p
[root@yum ~]# mkdir /opt/yum_data/centos/7/{extras,os,updates}/x86_64 -p
[root@yum ~]# mkdir /opt/yum_data/epel/{6,7}/x86_64/ -p
[root@yum ~]# mkdir /opt/yum_data/repoforge/rhel/el{6,7}/en/x86_64/{extras,rpmforge}/RPMS/ -p
[root@yum ~]# mkdir /opt/yum_data/remi/6/remi/x86_64/ -p
[root@yum ~]# mkdir /opt/yum_data/elasticstack/elastic-{5.x,6.x}/ -p
[root@yum ~]# mkdir /opt/yum_data/foreman/{plugins,releases}/1.12/el6/x86_64/ -p
[root@yum ~]# mkdir /opt/yum_data/nginx/{6,7}/x86_64/RPMS/ -p
[root@yum ~]# mkdir /opt/yum_data/zabbix/ -p
[root@yum ~]# mkdir /opt/yum_data/puppet/el/{6,7}/{dependencies,devel,products}/{i386,x86_64} -p
[root@yum  ~]#  mkdir /opt/yum_data/puppet/puppet/el/{6,7}/x86_64 -p
[root@yum  ~]#  mkdir /opt/yum_data/puppet/puppet/el/6/i386 -p
[root@yum opt]# tree -L 3 yum_data/centos/
yum_data/centos/
├── 6
│   ├── extras
│   │   └── x86_64
│   ├── os
│   │   └── x86_64
│   └── updates
│       └── x86_64
└── 7
    ├── extras
    │   └── x86_64
    ├── os
    │   └── x86_64
    └── updates
        └── x86_64
[root@yum opt]# tree -L 3 yum_data/epel/
yum_data/epel/
├── 6
│   └── x86_64
│       ├── drpms
│       ├── epel-release-6-8.noarch.rpm
│       ├── Packages
│       └── repodata
└── 7
    └── x86_64
        ├── drpms
        ├── Packages
        └── repodata
10 directories, 1 file
[root@yum opt]# tree -L 3 yum_data/remi/
yum_data/remi/
└── 6
    ├── foo
    ├── php54
    │   ├── httpsmirror
    │   ├── mirror
    │   └── x86_64
    ├── php55
    │   ├── httpsmirror
    │   ├── mirror
    │   └── x86_64
    ├── php56
    │   ├── httpsmirror
    │   ├── mirror
    │   └── x86_64
    ├── php70
    │   ├── httpsmirror
    │   ├── mirror
    │   └── x86_64
    ├── php71
    │   ├── httpsmirror
    │   ├── mirror
    │   └── x86_64
    ├── php72
    │   ├── httpsmirror
    │   ├── mirror
    │   └── x86_64
    ├── remi
    │   ├── httpsmirror
    │   ├── mirror
    │   └── x86_64
    ├── safe
    │   ├── httpsmirror
    │   ├── mirror
    │   └── x86_64
    └── x86_64
        ├── foo
        ├── php54
        ├── php55
        ├── php56
        ├── php70
        ├── php71
        ├── php72
        ├── remi
        └── safe
26 directories, 18 files
[root@yum opt]# tree -L 4 yum_data/repoforge/
yum_data/repoforge/
└── rhel
    ├── el6
    │   └── en
    │       └── x86_64
    └── el7
        └── en
            └── x86_64
7 directories, 0 files
[root@yum opt]# tree -L 3 yum_data/nginx/
yum_data/nginx/
├── 6
│   └── x86_64
│       ├── repodata
│       └── RPMS
└── 7
    └── x86_64
        ├── repodata
        └── RPMS
[root@yum opt]# tree -L 4 yum_data/foreman/
yum_data/foreman/
├── plugins
│   └── 1.12
│       └── el6
│           └── x86_64
└── releases
    └── 1.12
        └── el6
            └── x86_64
8 directories, 0 files
[root@yum opt]# tree -L 2 yum_data/zabbix/
yum_data/zabbix/
├── non-supported
│   └── rhel
├── RPM-GPG-KEY-ZABBIX -> RPM-GPG-KEY-ZABBIX-79EA5ED4
├── RPM-GPG-KEY-ZABBIX-79EA5ED4
├── RPM-GPG-KEY-ZABBIX-A14FE591
├── RPM-GPG-KEY-ZABBIX-A14FE591-EL5
├── zabbix
│   ├── 1.8
│   ├── 2.0
│   ├── 2.2
│   ├── 2.4
│   ├── 2.5
│   ├── 3.0
│   ├── 3.1
│   ├── 3.2
│   ├── 3.4
│   └── 3.5
└── zabbix-official-repo.key
13 directories, 5 files
[root@yum opt]# tree -L 2 yum_data/elasticstack/
yum_data/elasticstack/
├── elastic-5.x
│   ├── 5.0.0
│   ├── 5.0.1
│   ├── 5.0.2
│   ├── 5.1.1
│   ├── 5.1.2
│   ├── 5.2.0
│   ├── 5.2.1
│   ├── 5.2.2
│   ├── 5.3.0
│   ├── 5.3.1
│   ├── 5.3.2
│   ├── 5.3.3
│   ├── 5.4.0
│   ├── 5.4.1
│   ├── 5.4.2
│   ├── 5.4.3
│   ├── 5.5.0
│   ├── 5.5.1
│   ├── 5.5.2
│   ├── 5.5.3
│   ├── 5.6.0
│   ├── 5.6.1
│   ├── 5.6.2
│   ├── 5.6.3
│   ├── 5.6.4
│   ├── 5.6.5
│   └── repodata
└── elastic-6.x
    ├── 6.0.0
    ├── 6.0.1
    ├── 6.1.0
    ├── 6.1.1
    └── repodata
34 directories, 0 files
[root@yum opt]# tree -L 4 yum_data/puppet/
yum_data/puppet/
└── el
    ├── 6
    │   ├── dependencies
    │   │   ├── i386
    │   │   └── x86_64
    │   ├── devel
    │   │   ├── i386
    │   │   └── x86_64
    │   └── products
    │       ├── i386
    │       └── x86_64
    └── 7
        ├── dependencies
        │   └── x86_64
        ├── devel
        │   ├── i386
        │   └── x86_64
        └── products
            ├── i386
            └── x86_64

20 directories, 0 files

二、确定 yum 同步镜像地址

 

CentOS6源:
rsync://mirrors.ustc.edu.cn/centos/6/os/x86_64/
rsync://mirrors.ustc.edu.cn/centos/6/extras/x86_64/
rsync://mirrors.ustc.edu.cn/centos/6/updates/x86_64/
EPEL6/7源:
rsync://mirrors.ustc.edu.cn/epel/6/x86_64/
rsync://mirrors.ustc.edu.cn/epel/7/x86_64/
Zabbix源:
rsync://mirror.tuna.tsinghua.edu.cn/zabbix/
Nginx源:
rsync://mirrors.ustc.edu.cn/repo/nginx/centos/6/x86_64/
rsync://mirrors.ustc.edu.cn/repo/nginx/centos/7/x86_64/
Foreman源:
rsync://rsync.theforeman.org/yum/releases/1.12/el6/x86_64/
rsync://rsync.theforeman.org/yum/plugins/1.12/el6/x86_64/
Remi源:
rsync://mirror.tuna.tsinghua.edu.cn/remi/enterprise/6/remi/x86_64/
Repoforge源:
rsync://mirror.tuna.tsinghua.edu.cn/repoforge/redhat/el6/en/x86_64/rpmforge/
rsync://mirror.tuna.tsinghua.edu.cn/repoforge/redhat/el7/en/x86_64/rpmforge/
rsync://mirror.tuna.tsinghua.edu.cn/repoforge/redhat/el6/en/x86_64/extras/
rsync://mirror.tuna.tsinghua.edu.cn/repoforge/redhat/el7/en/x86_64/extras/
Elasticstack源:
rsync://mirror.tuna.tsinghua.edu.cn/elasticstack/yum/elastic-5.x/
rsync://mirror.tuna.tsinghua.edu.cn/elasticstack/yum/elastic-6.x/
Puppet源:
rsync://rsync.puppet.com/packages/yum/el/6/dependencies/x86_64/
rsync://rsync.puppet.com/packages/yum/el/7/dependencies/x86_64/
rsync://rsync.puppet.com/packages/yum/el/6/dependencies/i386/
rsync://rsync.puppet.com/packages/yum/el/6/devel/x86_64/
rsync://rsync.puppet.com/packages/yum/el/7/devel/x86_64/
rsync://rsync.puppet.com/packages/yum/el/6/devel/i386/
rsync://rsync.puppet.com/packages/yum/el/7/devel/i386/
rsync://rsync.puppet.com/packages/yum/el/6/products/x86_64/
rsync://rsync.puppet.com/packages/yum/el/7/products/x86_64/
rsync://rsync.puppet.com/packages/yum/el/6/products/i386/
rsync://rsync.puppet.com/packages/yum/el/7/products/i386/

三、同步 yum 源:

Centos6源:
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://mirrors.ustc.edu.cn/centos/6/os/x86_64/ /opt/yum_data/centos/6/os/x86_64/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://mirrors.ustc.edu.cn/centos/6/extras/x86_64/ /opt/yum_data/centos/6/extras/x86_64/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://mirrors.ustc.edu.cn/centos/6/updates/x86_64/ /opt/yum_data/centos/6/updates/x86_64/
Centos7源:
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://mirrors.ustc.edu.cn/centos/7/os/x86_64/ /opt/yum_data/centos/7/os/x86_64/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://mirrors.ustc.edu.cn/centos/7/extras/x86_64/ /opt/yum_data/centos/7/extras/x86_64/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://mirrors.ustc.edu.cn/centos/7/updates/x86_64/ /opt/yum_data/centos/7/updates/x86_64/
EPEL6/7源:
[root@yum ~]# /usr/bin/rsync -avz --progress --exclude=debug --no-motd rsync://mirrors.ustc.edu.cn/epel/6/x86_64/ /opt/yum_data/epel/6/x86_64/
[root@yum ~]# /usr/bin/rsync -avz --progress --exclude=debug --no-motd rsync://mirrors.ustc.edu.cn/epel/7/x86_64/ /opt/yum_data/epel/7/x86_64/
Zabbix源:
[root@yum ~]# /usr/bin/rsync -avz --progress --exclude=debian --exclude=ubuntu --exclude=rhel/5 --exclude=rhel/6/i386  --exclude=rhel/6/SRPMS  --exclude=rhel/7/SRPMS --no-motd rsync://mirror.tuna.tsinghua.edu.cn/zabbix/ /opt/yum_data/zabbix/
NGINX源:
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://mirrors.ustc.edu.cn/repo/nginx/centos/6/x86_64/ /opt/yum_data/nginx/6/x86_64/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://mirrors.ustc.edu.cn/repo/nginx/centos/7/x86_64/ /opt/yum_data/nginx/6/x86_64/
Foreman源:
[root@yum ~]# rsync --list-only rsync://rsync.theforeman.org/yum/releases/1.12/
[root@yum ~]# rsync --list-only rsync://rsync.theforeman.org/yum/plugins/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://rsync.theforeman.org/yum/releases/1.12/el6/x86_64/ /opt/yum_data/foreman/releases/1.12/el6/x86_64/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://rsync.theforeman.org/yum/plugins/1.12/el6/x86_64/ /opt/yum_data/foreman/plugins/1.12/el6/x86_64/
Remi源:
[root@yum ~]# rsync --list-only rsync://mirror.tuna.tsinghua.edu.cn/remi/enterprise/6/
[root@yum ~]# /usr/bin/rsync -avz --progress --exclude=debug-*  --exclude=test* --exclude=php*/i386/ --exclude=remi/i386/ --exclude=safe/i386/ --exclude=index.html --no-motd rsync://mirror.tuna.tsinghua.edu.cn/remi/enterprise/6/remi/x86_64/ /opt/yum_data/remi/6/x86_64/remi/x86_64/
Repoforge源:
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://mirror.tuna.tsinghua.edu.cn/repoforge/redhat/el6/en/x86_64/rpmforge/ /opt/yum_data/repoforge/rhel/el6/en/x86_64/rpmforge/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://mirror.tuna.tsinghua.edu.cn/repoforge/redhat/el7/en/x86_64/rpmforge/ /opt/yum_data/repoforge/rhel/el7/en/x86_64/rpmforge/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://mirror.tuna.tsinghua.edu.cn/repoforge/redhat/el6/en/x86_64/extras/ /opt/yum_data/repoforge/rhel/el6/en/x86_64/extras/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://mirror.tuna.tsinghua.edu.cn/repoforge/redhat/el7/en/x86_64/extras/ /opt/yum_data/repoforge/rhel/el7/en/x86_64/extras/
Elasticstack源:
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://mirror.tuna.tsinghua.edu.cn/elasticstack/yum/elastic-5.x/ /opt/yum_data/elasticstack/elastic-5.x/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://mirror.tuna.tsinghua.edu.cn/elasticstack/yum/elastic-6.x/ /opt/yum_data/elasticstack/elastic-6.x/
Puppet源:
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://rsync.puppet.com/packages/yum/el/6/dependencies/x86_64/ /opt/yum_data/puppet/el/6/dependencies/x86_64/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://rsync.puppet.com/packages/yum/el/7/dependencies/x86_64/ /opt/yum_data/puppet/el/7/dependencies/x86_64/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://rsync.puppet.com/packages/yum/el/6/dependencies/i386/ /opt/yum_data/puppet/el/6/dependencies/i386/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://rsync.puppet.com/packages/yum/el/6/devel/x86_64/ /opt/yum_data/puppet/el/6/devel/x86_64/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://rsync.puppet.com/packages/yum/el/7/devel/x86_64/ /opt/yum_data/puppet/el/7/devel/x86_64/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://rsync.puppet.com/packages/yum/el/6/devel/i386/ /opt/yum_data/puppet/el/6/devel/i386/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://rsync.puppet.com/packages/yum/el/7/devel/i386/ /opt/yum_data/puppet/el/7/devel/i386/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://rsync.puppet.com/packages/yum/el/6/products/x86_64/ /opt/yum_data/puppet/el/6/products/x86_64/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motdrsync://rsync.puppet.com/packages/yum/el/7/products/x86_64/ /opt/yum_data/puppet/el/7/products/x86_64/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motd rsync://rsync.puppet.com/packages/yum/el/6/products/i386/ /opt/yum_data/puppet/el/6/products/i386/
[root@yum ~]# /usr/bin/rsync -avz --progress --no-motdrsync://rsync.puppet.com/packages/yum/el/7/products/i386/ /opt/yum_data/puppet/el/7/products/i386/

测试篇:

一、创建 yum 源的 repo 文件

[root@yum ~]# cd /etc/yum.repos.d/
[root@yum yum.repos.d]# more base.repo
[base]
enabled=1
baseurl=http://yum.base.com/centos/$releasever/os/$basearch/
path=/
gpgcheck=1
name=CentOS-$releasever - Base - yum.base.com
gpgkey=http://yum.base.com/centos/6/os/x86_64/RPM-GPG-KEY-CentOS-6

 

二、测试 yum 源是否正确

[root@yum ~]# yum clean all             #<--清除缓存中的RPM包和头文件
Loaded plugins: fastestmirror, security
Cleaning repos: base elastic-5.x elastic-6.x epel extras foreman foreman-plugins nginx remi rpmforge rpmforge-extras updates
: zabbix-client
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@yum yum.repos.d]# yum makecache 
Loaded plugins: fastestmirror, security
Determining fastest mirrors
base                                                                                                          | 3.7 kB     00:00     
base/group_gz                                                                                                 | 226 kB     00:00     
base/filelists_db                                                                                             | 6.4 MB     00:00     
base/primary_db                                                                                               | 4.7 MB     00:00     
base/other_db                                                                                                 | 2.8 MB     00:00     
elastic-5.x                                                                                                   | 2.9 kB     00:00     
elastic-5.x/filelists_db                                                                                      | 7.5 MB     00:00     
elastic-5.x/primary_db                                                                                        | 261 kB     00:00     
elastic-5.x/other_db                                                                                          |  18 kB     00:00     
elastic-6.x                                                                                                   | 2.9 kB     00:00     
elastic-6.x/filelists_db                                                                                      | 1.0 MB     00:00     
elastic-6.x/primary_db                                                                                        |  47 kB     00:00     
elastic-6.x/other_db                                                                                          | 4.2 kB     00:00     
epel                                                                                                          | 4.7 kB     00:00     
epel/group_gz                                                                                                 | 255 kB     00:00     
epel/filelists_db                                                                                             | 7.8 MB     00:00     
epel/prestodelta                                                                                              |  321 B     00:00     
epel/primary_db                                                                                               | 6.0 MB     00:00     
epel/other_db                                                                                                 | 3.0 MB     00:00     
extras                                                                                                        | 3.4 kB     00:00     
extras/filelists_db                                                                                           |  26 kB     00:00     
extras/prestodelta                                                                                            | 1.3 kB     00:00     
extras/primary_db                                                                                             |  29 kB     00:00     
extras/other_db                                                                                               |  30 kB     00:00     
foreman                                                                                                       | 2.9 kB     00:00     
foreman/filelists_db                                                                                          | 759 kB     00:00     
foreman/primary_db                                                                                            | 148 kB     00:00     
foreman/other_db                                                                                              |  84 kB     00:00     
foreman-plugins                                                                                               | 2.9 kB     00:00     
foreman-plugins/filelists_db                                                                                  | 289 kB     00:00     
foreman-plugins/primary_db                                                                                    |  68 kB     00:00     
foreman-plugins/other_db                                                                                      |  43 kB     00:00     
nginx                                                                                                         | 2.9 kB     00:00     
nginx/filelists_db                                                                                            |  36 kB     00:00     
nginx/primary_db                                                                                              |  32 kB     00:00     
nginx/other_db                                                                                                |  16 kB     00:00     
puppetlabs-deps                                                                                               | 2.5 kB     00:00     
puppetlabs-deps/filelists_db                                                                                  | 198 kB     00:00     
puppetlabs-deps/primary_db                                                                                    |  27 kB     00:00     
puppetlabs-deps/other_db                                                                                      |  21 kB     00:00     
puppetlabs-products                                                                                           | 2.5 kB     00:00     
puppetlabs-products/filelists_db                                                                              | 1.0 MB     00:00     
puppetlabs-products/primary_db                                                                                | 170 kB     00:00     
puppetlabs-products/other_db                                                                                  | 194 kB     00:00     
remi                                                                                                          | 2.9 kB     00:00     
remi/filelists_db                                                                                             | 2.4 MB     00:00     
remi/primary_db                                                                                               | 2.0 MB     00:00     
remi/other_db                                                                                                 | 976 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                                                                                             | 575 kB     00:00     
rpmforge-extras                                                                                               | 1.9 kB     00:00     
rpmforge-extras/filelists_db                                                                                  | 335 kB     00:00     
rpmforge-extras/primary_db                                                                                    | 472 kB     00:00     
rpmforge-extras/other_db                                                                                      |  92 kB     00:00     
updates                                                                                                       | 3.4 kB     00:00     
updates/filelists_db                                                                                          | 3.5 MB     00:00     
updates/prestodelta                                                                                           | 171 kB     00:00     
updates/primary_db                                                                                            | 5.8 MB     00:00     
updates/other_db                                                                                              |  83 MB     00:01     
zabbix-client                                                                                                 | 2.9 kB     00:00     
zabbix-client/filelists_db                                                                                    |  64 kB     00:00     
zabbix-client/primary_db                                                                                      |  86 kB     00:00     
zabbix-client/other_db                                                                                        |  60 kB     00:00     
Metadata Cache Created
[root@yum ~]# yum repolist               #<--列出yum源中可用的软件包
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
repo id                                          repo name                                                                     status
base                                             CentOS-6 - Base - yum.base.com                                                 6,706
elastic-5.x                                      Elastic repository for 5.x packages                                              302
elastic-6.x                                      Elastic repository for 6.x packages                                               60
epel                                             Extra Packages for Enterprise Linux 6 - x86_64                                12,448
extras                                           CentOS-6 - Extras - yum.base.com                                                  47
foreman                                          Foreman 1.12                                                                     460
foreman-plugins                                  Foreman 1.12                                                                     240
nginx                                            nginx-6 - yum.base.com                                                            90
puppetlabs-deps                                  Puppet Labs Dependencies El 6 - x86_64                                            77
puppetlabs-products                              Puppet Labs Products El 6 - x86_64                                               564
remi                                             Les RPM de remi pour Enterprise Linux 6 - x86_64                               4,890
rpmforge                                         RHEL 6 - yum.base/rpmforge - dag                                               4,718
rpmforge-extras                                  RHEL 6 - yum.base/extras - dag                                                   711
updates                                          CentOS-6 - Updates - yum.base.com                                                858
zabbix-client                                    zabbix client repo for yum.base.com                                              170
repolist: 32,341
[root@yum ~]# yum install htop                      #<--测试rpmforge源
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
base                                                                                                          | 3.7 kB     00:00     
elastic-5.x                                                                                                   | 2.9 kB     00:00     
elastic-6.x                                                                                                   | 2.9 kB     00:00     
epel                                                                                                          | 4.7 kB     00:00     
extras                                                                                                        | 3.4 kB     00:00     
foreman                                                                                                       | 2.9 kB     00:00     
foreman-plugins                                                                                               | 2.9 kB     00:00     
nginx                                                                                                         | 2.9 kB     00:00     
remi                                                                                                          | 2.9 kB     00:00     
rpmforge                                                                                                      | 1.9 kB     00:00     
rpmforge-extras                                                                                               | 1.9 kB     00:00     
updates                                                                                                       | 3.4 kB     00:00     
zabbix-client                                                                                                 | 2.9 kB     00:00     
Resolving Dependencies
--> Running transaction check
---> Package htop.x86_64 0:1.0.3-1.el6.rf will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================
Package                    Arch                         Version                                Repository                      Size
=====================================================================================================================================
Installing:
htop                       x86_64                       1.0.3-1.el6.rf                         rpmforge                        87 k
Transaction Summary
=====================================================================================================================================
Install       1 Package(s)
Total download size: 87 k
Installed size: 209 k
[root@yum ~]# yum install php
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:5.4.45-13.el6.remi will be installed
--> Processing Dependency: php-common(x86-64) = 5.4.45-13.el6.remi for package: php-5.4.45-13.el6.remi.x86_64
--> Processing Dependency: php-cli(x86-64) = 5.4.45-13.el6.remi for package: php-5.4.45-13.el6.remi.x86_64
--> Processing Dependency: httpd-mmn = 20051115 for package: php-5.4.45-13.el6.remi.x86_64
--> Processing Dependency: httpd for package: php-5.4.45-13.el6.remi.x86_64
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-60.el6.centos.6 will be installed
--> Processing Dependency: httpd-tools = 2.2.15-60.el6.centos.6 for package: httpd-2.2.15-60.el6.centos.6.x86_64
--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-60.el6.centos.6.x86_64
---> Package php-cli.x86_64 0:5.4.45-13.el6.remi will be installed
---> Package php-common.x86_64 0:5.4.45-13.el6.remi will be installed
--> Running transaction check
---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be installed
---> Package httpd-tools.x86_64 0:2.2.15-60.el6.centos.6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================
Package                         Arch                     Version                                    Repository                 Size
=====================================================================================================================================
Installing:
php                             x86_64                   5.4.45-13.el6.remi                         remi                      2.8 M
Installing for dependencies:
apr-util-ldap                   x86_64                   1.3.9-3.el6_0.1                            base                       15 k
httpd                           x86_64                   2.2.15-60.el6.centos.6                     updates                   836 k
httpd-tools                     x86_64                   2.2.15-60.el6.centos.6                     updates                    80 k
php-cli                         x86_64                   5.4.45-13.el6.remi                         remi                      4.1 M
php-common                      x86_64                   5.4.45-13.el6.remi                         remi                      968 k
Transaction Summary
=====================================================================================================================================
Install       6 Package(s)
Total download size: 8.8 M
Installed size: 32 M

参数篇:

--progress:可以显示同步的进度,包括文件传输完成进度、传输速率信息

--no-motd:此选项会影响客户端在守护程序传输开始时输出的信息。它会禁止 motd 信息,但是也会影响 daemon 对 "rsync host::" 请求显示模块列表的回应信息,因此如果想要请求 daemon 的模块列表,应该忽略该选项。

--list-only:该选项强制 rsync 仅列出源路径的文件列表而不是进行文件传输。如果 rsync 命令行中只给出了一个地址,将隐含该选项。注意通配符会被 shell 解析并扩展为 rsync 的参数。

-z:传输前进行压缩

-a:归档模式,表示以递归方式传输文件,并保持所有文件属性,等于 -rlptgoD

-v:显示命令执行详细信息

计划任务脚本:

#!/bin/bash
#同步本地YUM源

#YUM存储路径
Data=/opt/yum_data
#YUM源rsync地址
Ustc=mirrors.ustc.edu.cn/centos
Epel=mirrors.ustc.edu.cn/epel
Repo=mirrors.ustc.edu.cn/repo
Tsinghua=mirror.tuna.tsinghua.edu.cn
Forman=rsync.theforeman.org
Puppet=rsync.puppet.com/packages/yum

source /etc/profile
datetime=`date +"%Y-%m-%d"`
exec > /var/log/synchronous.log
#同步Centos 6/7 的OS、Extras、Updates
for i in {1..3}
do
  for version in 6 7
  do
    /usr/bin/rsync -az --no-motd rsync://$Ustc/$version/os/x86_64/ $Data/centos/$version/os/x86_64/ > /dev/null
    if [ $? -eq 0 ];then
       echo -e "SUCESS: $datetime \033[32m Centos $version os update successful \033[0m"
    else
       echo -e "ERROR: $datetime \033[31m Centos $version os update failed \033[0m"
    fi
    /usr/bin/rsync -az --no-motd rsync://$Ustc/$version/extras/x86_64/ $Data/centos/$version/extras/x86_64/ > /dev/null
    if [ $? -eq 0 ];then
       echo -e "SUCESS: $datetime \033[32m Centos $version extras  successful \033[0m"
    else
       echo -e "ERROR: $datetime \033[31m Centos $version extras failed \033[0m"
    fi
    /usr/bin/rsync -az --no-motd rsync://$Ustc/$version/updates/x86_64/ $Data/centos/$version/updates/x86_64/ > /dev/null
    if [ $? -eq 0 ];then
       echo -e "SUCESS: $datetime \033[32m Centos $version update successful \033[0m"
    else
       echo -e "ERROR: $datetime \033[31m Centos $version update failed \033[0m"
    fi
  done
  sleep 10
done

#同步EPEL 6/7
for i in {1..3}
do
  for version in 6 7
  do
    /usr/bin/rsync -az --exclude=debug --no-motd rsync://$Epel/$version/x86_64/ $Data/epel/$version/x86_64/ > /dev/null
    if [ $? -eq 0 ];then
       echo -e "SUCESS: $datetime \033[32m EPEL $version update successful \033[0m"
    else
       echo -e "ERROR: $datetime \033[31m EPEL $version update failed \033[0m"
    fi
  done
 sleep 10
done

#同步ZABBIX
/usr/bin/rsync -az --exclude=debian --exclude=ubuntu --exclude=rhel/5 --exclude=rhel/6/i386  --exclude=rhel/6/SRPMS  --exclude=rhel/7/SRPMS --no-motd rsync://$Tsinghua/zabbix/ $Data/zabbix/ > /dev/null
if [ $? -eq 0 ];then
    echo -e "SUCESS: $datetime \033[32m ZABBIX update successful \033[0m"
else
    echo -e "ERROR: $datetime \033[31m ZABBIX update failed \033[0m"
fi

#同步Nginx
for i in {1..3}
do
   for version in 6 7
   do
     /usr/bin/rsync -az --no-motd rsync://$Repo/nginx/centos/$version/x86_64/ $Data/nginx/$version/x86_64/ > /dev/null
    if [ $? -eq 0 ];then
       echo -e "SUCESS: $datetime \033[32m Centos $version Nginx update successful \033[0m"
    else
       echo -e "ERROR: $datetime \033[31m Centos $version Nginx update failed \033[0m"
    fi
   done
 sleep 10
done

#同步Foreman
/usr/bin/rsync -az --no-motd rsync://$Forman/yum/releases/1.12/el6/x86_64/ $Data/foreman/releases/1.12/el6/x86_64/ > /dev/null
/usr/bin/rsync -az --no-motd rsync://$Forman/yum/releases/1.17/el7/x86_64/ $Data/foreman/releases/1.17/el7/x86_64/ > /dev/null
if [ $? -eq 0 ];then
    echo -e "SUCESS: $datetime \033[32m Foreman update successful \033[0m"
else
    echo -e "ERROR: $datetime \033[31m Foreman update failed \033[0m"
fi

#同步Foreman-plugins
/usr/bin/rsync -az --no-motd rsync://$Forman/yum/plugins/1.12/el6/x86_64/ $Data/foreman/plugins/1.12/el6/x86_64/ > /dev/null
/usr/bin/rsync -az --no-motd rsync://$Forman/yum/plugins/1.17/el7/x86_64/ $Data/foreman/plugins/1.17/el7/x86_64/ > /dev/null
if [ $? -eq 0 ];then
    echo -e "SUCESS: $datetime \033[32m Foreman-plugins update successful \033[0m"
else
    echo -e "ERROR: $datetime \033[31m Foreman-plugins update failed \033[0m"
fi

#同步Remi
/usr/bin/rsync -az --exclude=debug-*  --exclude=test* --exclude=php*/i386/ --exclude=remi/i386/ --exclude=safe/i386/  --no-motd rsync://$Tsinghua/remi/enterprise/6/remi/x86_64/ $Data/remi/6/x86_64/remi/x86_64/ > /dev/null
if [ $? -eq 0 ];then
    echo -e "SUCESS: $datetime \033[32m Remi update successful \033[0m"
else
    echo -e "ERROR: $datetime \033[31m Remi update failed \033[0m"
fi

#同步Repoforge-rpmforge
for version in 6 7
do
   /usr/bin/rsync -az --no-motd rsync://$Tsinghua/repoforge/redhat/el$version/en/x86_64/rpmforge/ $Data/repoforge/rhel/el$version/en/x86_64/rpmforge/ > /dev/null
  if [ $? -eq 0 ];then
     echo -e "SUCESS: $datetime \033[32m Centos $version Repoforge-rpmforge update successful \033[0m"
  else
     echo -e "ERROR: $datetime \033[31m Centos $version Repoforge-rpmforge update failed"
  fi
done

#同步Repoforge-extras
for version in 6 7
do
   /usr/bin/rsync -az --no-motd rsync://$Tsinghua/repoforge/redhat/el$version/en/x86_64/extras/ $Data/repoforge/rhel/el$version/en/x86_64/extras/ > /dev/null
   if [ $? -eq 0 ];then
      echo -e "SUCESS: $datetime \033[32m Centos $version Repoforge-extras update successful \033[0m"
   else
      echo -e "ERROR: $datetime \033[31m Centos $version Repoforge-extras update failed \033[0m"
   fi
done

#同步Elasticstack
for version in elastic-5.x elastic-6.x
do
  /usr/bin/rsync -az --no-motd rsync://$Tsinghua/elasticstack/yum/$version/ $Data/elasticstack/$version/ > /dev/null
  if [ $? -eq 0 ];then
     echo -e "SUCESS: $datetime \033[32m $version update successful \033[0m"
  else
     echo -e "ERROR: $datetime \033[31m $version update failed \033[0m"
  fi
done

#同步Puppet
for version in 6 7
do
   for architecture in x86_64 i386
   do
     /usr/bin/rsync -az --no-motd rsync://$Puppet/el/$version/dependencies/$architecture/ $Data/puppet/el/$version/dependencies/$architecture/ > /dev/null
   if [ $? -eq 0 ];then
      echo -e "SUCESS: $datetime \033[32m puppet $version dependencies($architecture) successful \033[0m"
   else
      echo -e "ERROR: $datetime \033[31m puppet $version dependencies($architecture) failed \033[0m"
   fi
     /usr/bin/rsync -az --no-motd rsync://$Puppet/el/$version/devel/$architecture/ $Data/puppet/el/$version/devel/$architecture/ > /dev/null
  if [ $? -eq 0 ];then
     echo -e "SUCESS: $datetime \033[32m puppet devel($architecture) successful \033[0m"
  else
    echo -e "ERROR: $datetime \033[31m puppet devel($architecture) failed \033[0m"
  fi
    /usr/bin/rsync -az --no-motd rsync://$Puppet/el/$version/products/$architecture/ $Data/puppet/el/$version/products/$architecture/ > /dev/null
  if [ $? -eq 0 ];then
     echo -e "SUCESS: $datetime \033[32m puppet products($architecture) successful \033[0m"
  else
     echo -e "ERROR: $datetime \033[31m puppet products($architecture) failed \033[0m"
  fi
    /usr/bin/rsync -az --no-motd rsync://$Puppet/puppet/el/$version/x86_64/ $Data/puppet/puppet/el/$version/x86_64/ > /dev/null
  if [ $? -eq 0 ];then
     echo -e "SUCESS: $datetime \033[32m puppet $version x86_64 successful \033[0m"
  else
     echo -e "ERROR: $datetime \033[31m puppet $version x86_64 failed \033[0m"
  fi
    /usr/bin/rsync -az --no-motd rsync://$Puppet/puppet/el/6/i386/ $Data/puppet/puppet/el/6/i386/ > /dev/null
  if [ $? -eq 0 ];then
     echo -e "SUCESS: $datetime \033[32m puppet 6 i386 successful \033[0m"
  else
     echo -e "ERROR: $datetime \033[31m puppet 6 i386 failed \033[0m"
  fi
  done
done
chown -R root.root $Data/
yum clean all
yum makecache
mail -s "yum-update" -a /var/log/synchronous.log test@abc.com

 

转载至http://blog.51cto.com/stuart/2061869

 

 

### 在CentOS 7中配置和搭建Yum源服务器 #### 1. 准备工作 为了成功搭建Yum源服务器,需要准备以下内容: - 安装有CentOS 7操作系统的主机。 - 提前准备好CentOS 7的ISO镜像文件。 #### 2. 搭建本地Yum源 ##### 2.1 挂载ISO镜像 首先,创建一个用于挂载ISO镜像的目录,并将ISO镜像挂载至该目录。具体命令如下: ```bash mkdir /mnt/centos mount /dev/cdrom /mnt/centos/ ``` 确认挂载是否成功可以通过`df -hT`查看挂载情况[^3]。 ##### 2.2 备份原有Yum配置文件 进入`/etc/yum.repos.d/`目录,备份原有的`.repo`文件以防止误删重要数据: ```bash cd /etc/yum.repos.d/ mv *.repo ./backup/ ``` ##### 2.3 创建新的本地Yum源配置文件 复制一份原始的`CentOS-Media.repo`文件并修改其内容为适配本地环境的新配置文件: ```bash cp backup/CentOS-Media.repo . vim CentOS-Media.repo ``` 编辑后的文件应类似于以下内容: ```ini [local] name=Local Repository baseurl=file:///mnt/centos/AppStream enabled=1 gpgcheck=0 ``` 注意:这里的路径需与实际挂载位置一致[^3]。 ##### 2.4 更新Yum缓存 清除旧有的Yum缓存并生成新缓存以便于后续使用: ```bash yum clean all yum makecache ``` 验证本地Yum源是否正常运行可通过尝试安装某个软件包来进行测试,例如Apache HTTP Server (`httpd`): ```bash yum install httpd -y ``` #### 3. 将本地Yum源发布成网络可访问的形式 为了让其他机器能够通过网络连接到此Yum源服务器,可以选择HTTP协议进行发布。这里介绍两种常见的Web服务器——`httpd` 和 `nginx` 的设置方法。 ##### 3.1 使用Httpd服务发布Yum源 ###### (1) 安装Httpd服务端程序 如果没有预先安装,则先执行安装命令: ```bash yum install httpd -y ``` ###### (2) 配置Httpd服务 将之前挂载好的ISO中的资料拷贝到默认网站根目录下(通常是`/var/www/html/`): ```bash rsync -av --progress /mnt/centos/* /var/www/html/ ``` 启动Httpd服务并将开机自启设定好: ```bash systemctl start httpd.service systemctl enable httpd.service ``` 最后,在防火墙允许外部访问80端口: ```bash firewall-cmd --permanent --add-service=http firewall-cmd --reload ``` 此时,远程客户端即可通过URL形式访问这个Yum源了,形如`http://<server-ip>/AppStream`[^2]。 ##### 3.2 使用Nginx服务发布Yum源 对于希望利用更高性能轻量级Web服务器场景下的用户来说,也可以考虑选用Nginx替代传统Apache Httpd方案: ###### (1) 安装Nginx服务端程序 同样地,如果尚未安装过Nginx的话,请先行完成安装过程: ```bash yum install nginx -y ``` ###### (2) 修改Nginx配置文件 调整Nginx的主要配置文档使其指向存储Yum资源的位置,通常位于`/etc/nginx/nginx.conf`内增加类似下面的内容片段: ```nginx location / { root /var/www/html/; autoindex on; } ``` 重启Nginx使更改生效: ```bash systemctl restart nginx ``` 同理开放必要的防火墙规则让外界得以顺利请求这些公开的数据集[^4]。 至此,整个基于CentOS 7平台上的Yum源服务器已经构建完毕! --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值