一. 環境 1.1 主機信息 |主機|OS|Storage|備註| | | | | | |100.64.140.101|centos 7.6|/dev/sdb 100GB|1.selinux disable; 2.放行tcp80埠| 1.2 掛載磁碟 二. 鏡像Yum源 三. Web伺服器 四. ...
一. 環境
1.1 主機信息
主機 | OS | Storage | 備註 |
---|---|---|---|
100.64.140.101 | centos 7.6 | /dev/sdb > 100GB | 1.selinux disable; 2.放行tcp80埠 |
1.2 掛載磁碟
# 通過fdisk創建linux或linux lvm分區;
# 格式化分區為ext4或xfs格式
mkfs.ext4 /dev/sdb1
# mount
mkdir -p /repo
echo "/dev/sdb1 /repo ext4 defaults 1 2" >> /etc/fstab
mount -a
二. 鏡像Yum源
# 使用rsync同步yum源,上游yum源需要支持rsync協議
yum install rsync -y
# 同步清華大學開源軟體鏡像站,實測阿裡雲鏡像站不支持rsync協議
# centos
mkdir -p /repo/centos/7.6.1810/os/x86_64/
rsync -av rsync://mirrors.tuna.tsinghua.edu.cn/centos/7.6.1810/os/x86_64/ /repo/centos/7.6.1810/os/x86_64/
rsync -av rsync://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-7 /repo/centos/RPM-GPG-KEY-CentOS-7
# 重要!建立/repo/centos/7.6.1810/目錄的軟鏈接
ln -s /repo/centos/7.6.1810/ /repo/centos/7
# epel
mkdir -p /repo/epel/7/x86_64/
rsync -av rsync://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/ /repo/epel/7/x86_64/
rsync -av rsync://mirrors.tuna.tsinghua.edu.cn/epel/RPM-GPG-KEY-EPEL-7 /repo/epel/RPM-GPG-KEY-EPEL-7
三. Web伺服器
# 安裝nginx
yum install nginx -y
# 編輯
vim /etc/nginx/nginx.conf
server {
client_max_body_size 4G;
listen 80 default_server;
server_name 100.64.140.101;
root /mirror;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# 測試
nginx -t
# 啟動
systemctl enable nginx
systemctl restart nginx
四. 客戶端repo文件
4.1 CentOS-Base.repo
# 備份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# 生成repo
cat << EOF >> /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://100.64.140.101/centos/$releasever/os/$basearch/
http://100.64.140.101/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://100.64.140.101/centos/RPM-GPG-KEY-CentOS-7
EOF
4.2 epel.repo
# centos預設沒有epel.repo
cat << EOF >> /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://100.64.140.101/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=http://100.64.140.101/epel/RPM-GPG-KEY-EPEL-7
EOF
五. (option範例)初始化repodata索引
# 如果通過rsync從公網同步鏡像,repodata也會同步,可直接使用;
# 如果不是從公網同步的鏡像庫,沒有repodata索引文件,可通過createrepo生成
# 安裝createrepo
yum install createrepo -y
# 在鏡像源目錄生成repodata索引文件
createrepo -pdo /repo/centos/7.6.1810/os/x86_64/
createrepo -pdo /repo/epel/7/x86_64/