離線化yum源的方法
首先準備一個excludes.list
文件,作爲排除的列表,如果不想排除,可以不用這個文件,並且將離線化腳本中的參數--exclude-from=exclude.list
刪除。
exclude.list文件內容:
SRPMS
aarch64
ppc64
ppc64le
debug
repodata
EFI
LiveOS
images
isolinux
CentOS_BuildTag
EULA
GPL
RPM-GPG-KEY-CentOS-7
RPM-GPG-KEY-CentOS-Testing-7
drpms
離線化腳本rsync.sh,會在當前目錄下創建一個centos
的目錄,並將源內容同步到這個目錄,通過createrepo
命令創建yum倉庫。離線文件總計27G左右,執行前確認空間足夠。如果不使用exclude.list
,佔用空間只會更多。腳本內容:
#!/bin/bash
#epel
rsync -avz --exclude-from=exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/epel/7/ epel/7/
createrepo epel/7/
#centos7-base
rsync -avz --exclude-from=exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/ centos/7/os/x86_64/
createrepo centos/7/os/x86_64/
#centos7-updates
rsync -avz --exclude-from=exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/updates/x86_64/ centos/7/updates/x86_64/
createrepo centos/7/updates/x86_64/
#centos7-extras
rsync -avz --exclude-from=exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/extras/x86_64/ centos/7/extras/x86_64/
createrepo centos/7/extras/x86_64/
#centos7-centosplus
rsync -avz --exclude-from=exclude.list rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/centosplus/x86_64/ centos/7/centosplus/x86_64/
createrepo centos/7/centosplus/x86_64/
在執行腳本之前,需要確定系統上已經安裝命令rsync
和createrepo
。
yum install rsync createrepo -y
搭建本地文件源
現在,可以使用local.repo
使用當前目錄爲yum源,文件內容如下:
[base]
name=Local Repository
baseurl=file:///centos/7/os/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=Local Repository
baseurl=file:///centos/7/updates/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[extras]
name=Local Repository
baseurl=file:///centos/7/extras/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[centosplus]
name=Local Repository
baseurl=file:///centos/7/centosplus/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
上邊是開啓gpgcheck
了,如果不想啓用,把它設置成0
。
搭建http源
如果想要搭建http服務訪問源
,使用apache
或者nginx
搭建一個http服務,將文件放到web目錄裏面即可。然後把repo文件中的每一個repo的baseurl
改爲對應的url就行了。