Use rsync to synchronize the Internet centos Yum source as the local Yum source server

Source: Internet
Author: User
Tags gpg

Use rsync to synchronize the Internet centos Yum source as the local Yum source server


1. Install httpd, rsync, and vsftpd.

Yum-y install httpd rsync vsftpd


Mkdir/var/www/html/centos


# Because vsftpd does not support changing directories through soft connections, the following operations are the same

Mount -- bind/var/www/html/centos/var/FTP/pub


Chkconfig httpd on

Chkconfig vsftpd on

Service httpd start

Service vsftpd start


2. The Rsync synchronization script is as follows:

#! /Bin/bash

# Base Value

# Source to be synchronized

Yum_site = "rsync: // mirrors.kernel.org/centos /"

# Local storage directory

Local_path = "/u01/mirrors/centos /"

# For the version to be synchronized, I only need a total of around GB for versions 5, 6, and 7. After removing ISO, there will be fewer

Local_ver = "5 5*6 6*7 7 *"

# Bandwidth limit during Synchronization

Bw_limit = 512

# Recording the script process number

Lock_file = "/var/log/yum_server.pid"

# If Rsync is empty by default.

# Fill in the complete path directly with the rsync tool installed by yourself

Rsync_path = ""

 

# Check update Yum server PID

My_pid =$ $

If [-F $ lock_file]; then

Get_pid = '/bin/CAT $ lock_file'

Get_system_pid = '/bin/PS-Ef | grep-V grep | grep $ get_pid | WC-l'

If [$ get_system_pid-EQ 0]; then

Echo $ my_pid> $ lock_file

Else

Echo "have update Yum server now! "

Exit 1

Fi

Else

Echo $ my_pid> $ lock_file

Fi

 

# Check rsync Tool

If [-Z $ rsync_path]; then

Rsync_path = '/usr/bin/whereis rsync | awk ''' {print $2 }''

If [-Z $ rsync_path]; then

Echo 'not find rsync tool .'

Echo 'use COMM: Yum install-y rsync'

Fi

Fi

 

# Sync Yum Source

For ver in $ local_ver;

Do

# Check whether there are local directory

If [! -D "$ local_path $ Ver"]; then

Echo "create dir $ local_path $ Ver"

'/Bin/mkdir-p $ local_path $ ver'

Fi

# Sync Yum Source

Echo "Start sync $ local_path $ Ver"

$ Rsync_path-avrth -- delete -- bwlimit = $ bw_limit -- exclude "ISOs" $ yum_site $ ver $ local_path

Done

 

# Clean lock file

'/Bin/Rm-RF $ lock_file'

 

Echo 'sync end .'

Exit 1


3. Schedule Tasks

Update every morning

23 59 ***/root/yumrsync


4. Client Configuration

Edit/etc/yum. Repos. d/CentOS-Base.repo

Find/etc/yum. Repos. d/-type F-name "*. Repo"-exec CP {}{}. Bak \;

Find/etc/yum. Repos. d/-name "*. Repo" | xargs sed-I's/# baseurl = http: \ // developer.centos.org/baseurl#http:#/#/192.168.0.100/g'

Run the preceding command to modify the settings. The result is as follows:


# Base

[Base]

Name = centos-$ releasever-Base

Baseurl = http: // 192.168.0.100/centos/$ releasever/OS/$ basearch/

Enabled = 1

Gpgcheck = 1

Gpgkey = file: // etc/pki/rpm-GPG/RPM-GPG-KEY-CentOS-6


# Released updates

[Updates]

Name = centos-$ releasever-Updates

Baseurl = http: // 192.168.0.100/centos/$ releasever/updates/$ basearch/

Enabled = 1

Gpgcheck = 1

Gpgkey = file: // etc/pki/rpm-GPG/RPM-GPG-KEY-CentOS-6


# Additional packages that may be useful

[Extras]

Name = centos-$ releasever-extras

Baseurl = http: // 192.168.0.100/centos/$ releasever/extras/$ basearch/

Gpgcheck = 1

Gpgkey = file: // etc/pki/rpm-GPG/RPM-GPG-KEY-CentOS-6


# Additional packages that extend functionality of existing packages

[Centosplus]

Name = centos-$ releasever-plus

Baseurl = http: // 192.168.0.100/centos/$ releasever/centosplus/$ basearch/

Gpgcheck = 1

Enabled = 0

Gpgkey = file: // etc/pki/rpm-GPG/RPM-GPG-KEY-CentOS-6


# Contrib-packages by centos users

[Contrib]

Name = centos-$ releasever-contrib

Baseurl = http: // 192.168.0.100/centos/$ releasever/contrib/$ basearch/

Gpgcheck = 1

Enabled = 0

Gpgkey = file: // etc/pki/rpm-GPG/RPM-GPG-KEY-CentOS-6


This article is from the "jerrymin" blog, please be sure to keep this source http://jerrymin.blog.51cto.com/3002256/1537141

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.