Google+ Followers

2015年10月30日 星期五

[Linux] 架設私有 Yum Server 服務 @ CentOS 6.6

經強者同事的經驗傳授,對於線上服務機器應追蹤限定軟體的使用版本,可降低環境複雜度,以便偵錯。因此,學一下架設 YUM Server 來提供服務吧!

原理就是挑一台機器留個 30GB 空間,把官方的 Packages 都下載回來,接著更新其他台機器的 repo 位置即可。此例以 CentOS 6.6 x86_64 為例。

$ yum install yum-arch createrepo nginx

其中 nginx 只是為了 web server 而已,這是 CentOS yum server 架構,透過 filesytem + sqlite + http server。

$ yum install nginx
$ service nginx start
$ mkdir -p /var/www
$ ln -s /usr/share/nginx/html/ /var/www/html


接著要將資料 Yum package 都下載下來,先確認來源是不是官方版,也可以將 /etc/yum.repos.d/ 清到只剩 CentOS-Base.repo 檔案即可:

$ vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
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://mirror.centos.org/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://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

$ mkdir -p /var/www/html/centos/6/sync
$ cd /var/www/html/centos/6/sync
$ time reposync --repoid=updates --repoid=extras --repoid=base --repoid=centosplus
...
$ createrepo /var/www/html/centos/6/sync/base/
$ createrepo /var/www/html/centos/6/sync/updates/
$ createrepo /var/www/html/centos/6/sync/extras/
$ createrepo /var/www/html/centos/6/sync/centosplus/
Spawning worker 0 with ### pkgs
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

$ mkdir -p /var/www/html/centos/6/updates /var/www/html/centos/6/extras/ /var/www/html/centos/6/os/ /var/www/html/centos/6/centosplus /var/www/html/centos/6/contrib
$ cd /var/www/html/centos/6/updates && ln -s ../sync/updates/ x86_64 && cd -
$ cd /var/www/html/centos/6/extras && ln -s ../sync/extras/ x86_64 && cd -
$ cd /var/www/html/centos/6/os && ln -s ../sync/base/ x86_64 && cd -
$ cd /var/www/html/centos/6/centosplus && ln -s ../sync/centosplus/ x86_64 && cd -


如此一來,搭配 web server 就可以存取這些位置:

http://public_ip/centos/6/updates
http://public_ip/centos/6/extras
http://public_ip/centos/6/os
http://public_ip/centos/6/centosplus


接著,其他 yum client 的 /etc/yum.repos.d/CentOS-Base.repo 位置更新為:

[base]
name=CentOS-$releasever - Base
baseurl=http://public_ip/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://public_ip/centos/$releasever/updates/$basearch/
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://public_ip/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://public_ip/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6


接著在做個 yum update 後,其 packages 即可被控管使用,而製作私有的 package 時,大概就多添加個區段,並把 gpgcheck 設定成 0:

$ cat /etc/yum.repos.d/self.repo
[self]
name=SelfYumServer-$releasever
baseurl=http://public_ip/centos/$releasever/self/$basearch/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6


此外,對於私有 Yum server 來說,每次變動 /var/www/html/centos/6/self/x64_86/Packages 後,都必須執行 createrepo /var/www/html/centos/6/self/x64_86/ 來更新狀態,如此一來別人就能找到。

最後,若 client 出現無法找到最新版的情況,請試試在 client server 清掉 cache,屆時重應該就會找到:

$ yum clean metadata dbcache 或 $ yum clean all

沒有留言:

張貼留言