由於企業早期的包袱,許多系統都因各種不可抗拒的原因無法升級至新版本的作業系統而停留在了CentOS6,故以下針對已經停止維護的CentOS6 x86_64為範例進行案例說明
伺服器端
作為自建yum源的CentOS6主機安裝yum倉庫所需套件,由於系統舊有預設的yum源已無法使用,建議更換為可用yum源,同時也讓之後的自建yum源有可鏡像的目標,此處作法參照「因應官方停止維護,CentOS6更換yum源」,沒問題後操作以下步驟安裝自建倉庫所需套件
yum install yum-utils createrepo -y
建立本地存放rpm的資料夾
mkdir -p /tmp/test/centos/6.10/os/
mkdir -p /tmp/test/centos/6.10/updates/
mkdir -p /tmp/test/centos/6.10/extras/
因vault源太多人使用、過於緩慢,我在操作此篇時改用了美國加州大學的鏡像源。
[root@test ~]# vi /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-6.10 - Base - mirrors.oit.uci.edu
baseurl=http://mirrors.oit.uci.edu/centos/6.10/os/$basearch/
gpgkey=http://mirrors.oit.uci.edu/centos/RPM-GPG-KEY-CentOS-6
gpgcheck=1
#released updates
[updates]
name=CentOS-6.10 - Updates - mirrors.oit.uci.edu
baseurl=http://mirrors.oit.uci.edu/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.oit.uci.edu/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-6.10 - Extras - mirrors.oit.uci.edu
baseurl=http://mirrors.oit.uci.edu/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.oit.uci.edu/centos/RPM-GPG-KEY-CentOS-6
[root@test ~]# yum clean all && yum makecache
透過指令可以看到現有yum源的資源狀態
[root@test centos]# yum repolist
repo id repo name status
base CentOS-6.10 - Base - mirrors.oit.uci.edu 6,713
extras CentOS-6.10 - Extras - mirrors.oit.uci.edu 47
updates CentOS-6.10 - Updates - mirrors.oit.uci.edu 1,193
repolist: 7,953
網路同步base、extras、updates倉庫到本地存放rpm的資料夾,此動作約耗時100分鐘內,新增檔案共佔據23GB磁碟容量
reposync -r base -p /tmp/test/centos/6.10/os/
reposync -r extras -p /tmp/test/centos/6.10/extras/
reposync -r updates -p /tmp/test/centos/6.10/updates/
目錄更名以符合yum源下載的常見格式
mv /tmp/test/centos/6.10/os/base/ /tmp/test/centos/6.10/os/x86_64/
mv /tmp/test/centos/6.10/updates/updates/ /tmp/test/centos/6.10/updates/x86_64/
mv /tmp/test/centos/6.10/os/extras/extras/ /tmp/test/centos/6.10/extras/x86_64/
建立倉庫索引
createrepo /tmp/test/centos/6.10/os/x86_64/
createrepo /tmp/test/centos/6.10/updates/x86_64/
createrepo /tmp/test/centos/6.10/extras/x86_64/
複製gpgkey
wget -P /tmp/test/centos/ http://mirrors.oit.uci.edu/centos/RPM-GPG-KEY-CentOS-6
最終這些檔案還需透過http或ftp等協議讓其他要來更新套件的主機有檔案傳輸下載的方法,默認你已經安裝nginx網頁服務,於nginx.conf設定檔中增加以下yum源網站的設定。
tarball安裝路徑在/usr/loca/nginx/conf/nginx.conf,若yum安裝路徑為/etc/nginx/nginx.conf
server {
listen 8001 default_server;
server_name _;
root /tmp/test/; ##網站根目錄於主機上的路徑位置
location / {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
index index.html;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html
}
}
平滑重啟nginx
service nginx reload
如果懶得安裝apache或nginx,也可利用python的輕量級httpserver來建立網頁服務,指令如下
cd /tmp/test/
python -m SimpleHTTPServer 8001 &>/dev/null &
客戶端
針對區網數名嗷嗷待哺的CentOS6主機更改/etc/yum.repos.d/CentOS-Base.repo 的內容,將主機指向企業區網的自建yum源
# CentOS-Base.repo
[base]
name=CentOS-6.10 - Base - test
baseurl=http://192.168.100.100:8001/centos/6.10/os/$basearch/
gpgkey=http://192.168.100.100:8001/centos/RPM-GPG-KEY-CentOS-6
gpgcheck=1
#released updates
[updates]
name=CentOS-6.10 - Updates - test
baseurl=http://192.168.100.100:8001/centos/6.10/updates/$basearch/
gpgkey=http://192.168.100.100:8001/centos/RPM-GPG-KEY-CentOS-6
gpgcheck=1
#additional packages that may be useful
[extras]
name=CentOS-6.10 - Extras - test
baseurl=http://192.168.100.100:8001/centos/6.10/extras/$basearch/
gpgkey=http://192.168.100.100:8001/centos/RPM-GPG-KEY-CentOS-6
gpgcheck=1
清除緩存和更新套件資料庫並檢視目前的repo狀態
[root@client ~]# yum clean all && yum makecache && yum repolist
伺服器端加碼epel6源
建立本地存放rpm的資料夾
mkdir -p /tmp/test/centos/epel6/
鏡像的部分於/etc/yum.repos.d 目錄下新增一個epel.repo檔案
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
清除緩存和更新套件資料庫並網路同步epel倉庫到本地存放rpm的資料夾
[root@test ~]# yum clean all && yum makecache
[root@test ~]# reposync -r epel -p /tmp/test/centos/epel6/
目錄更名以符合yum源下載的通用格式並建立倉庫索引
mv /tmp/test/centos/epel6/epel/ /tmp/test/centos/epel6/x86_64/
createrepo /tmp/test/centos/epel6/x86_64/
客戶端加碼使用自建epel6源
針對區網數名嗷嗷待哺的CentOS6主機新增 /etc/yum.repos.d/epel.repo 的內容,將主機指向企業區網的自建epel源
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch - test
baseurl=http://192.168.100.100:8001/centos/epel6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
清除緩存和更新套件資料庫並檢視目前的repo狀態
[root@client ~]# yum clean all && yum makecache && yum repolist
0 Comments:
張貼留言