2/25/2016

架設公司私有的Yum repository for CentOS 7


開始之前先瞭解一下世界上的軟件庫, 以及注意事項:

$yum -y install yum-utils httpd createrepo rsync reposync wget

根據公司的需要, 我們要同步CentOS 7 以及EPEL的Repo, Architect是採用x86_64 因此不需要i386的部分.
硬碟規劃約保留300GB

httpd是為了架設網站, 開放port 80 給公司的辦公室網域 以及RD開發區, SAT測試區, BETA區以及上線區域
reposync - used to synchronize remote yum repositories to a local directory, using yum to retrieve the packages
createrepo - Create repomd (xml-rpm-metadata) repository

0. 在/var/www/html/ 創建好規劃的目錄結構

在開始之前可以找一個離自己最快的yum repo, 因為我的mirror是架設在東京的AWS, 可能找日本的mirror會快很多.
找速度較快而且支援rsync的mirror site, 以我的例子是找到 mirror.fairway.ne.jp
$vi /etc/yum/pluginconf.d/fastestmirror.conf
修改成為這行: exclude=.gov, facebook, mirror.slowmirror.com

1. 對於centos,使用命令:

建立結構
$mkdir -p /var/www/html/yum/centos/7/os/x86_64
$mkdir -p /var/www/html/yum/centos/7/updates/x86_64
$mkdir -p /var/www/html/yum/centos/7/extras/x86_64

開始同步CentOS
$rsync -avrt rsync://mirror.fairway.ne.jp/centos/7/os/x86_64/ /var/www/html/yum/centos/7/os/x86_64/ &

結束之後安裝yum-arch進行RPM分析,並在目錄下產生headers資料夾
$wget ftp://rpmfind.net/linux/epel/6/ppc64/yum-arch-2.2.2-9.el6.noarch.rpm
$rpm -ivh yum-arch-2.2.2-9.el6.noarch.rpm
$yum-arch /var/www/html/yum/centos/7/os/x86_64
$yum-arch /var/www/html/yum/centos/7/updates/x86_64
$yum-arch /var/www/html/yum/centos/7/extras/x86_64

對64-bit packages目錄產生repodata資料夾
$createrepo /var/www/html/yum/centos/7/os/x86_64
$createrepo /var/www/html/yum/centos/7/updates/x86_64
$createrepo /var/www/html/yum/centos/7/extras/x86_64

2. 對於RHEL部分:

我使用reposync 這個工具, 先執行指令確認自己所屬的repo
$yum repolist

reposync 在執行的時候如果要用背景 & , 記得要用 nohup, 避免人離開去休息的時候, 一旦關閉terminal 就停止了
$reposync --repoid=epel --arch=x86_64 --gpgcheck -l --download_path=/var/www/html/
$reposync --repoid=base --arch=x86_64 --gpgcheck -l --download_path=/var/www/html/
$reposync --repoid=extras --arch=x86_64 --gpgcheck -l --download_path=/var/www/html/
$reposync --repoid=updates --arch=x86_64 --gpgcheck -l --download_path=/var/www/html/

The above command will download the packages in the mentioned download path. You then need to run following command to create the repository:
$cd /var/www/html/
$createrepo -v /var/www/html/

3.針對webstatic 的部分 Webtatic EL7 for CentOS/RHEL 7:


之後輸入
$yum repolist
會看到多了webtatic 這個repoid (我們就放寬不檢查GPG key了, 以免沒抓到)
$reposync --repoid=webtatic --arch=x86_64 --download_path=/var/www/html/

再做一次createrepo
$createrepo -v /var/www/html/

4. 開放firewall 給 80 port
$firewall-cmd --zone=public --add-port=80/tcp --permanent
$firewall-cmd --reload
$systemctl enable httpd

參考文獻:

-  How to create a local mirror of the latest update for Red Hat Enterprise Linux 5, 6, 7 without using Satellite server? https://access.redhat.com/solutions/23016