搭建内网 Yum 源
温馨提醒
安装工具
CentOS/RHEL
配置本地 yum 源
同步官方 yum 源到本地 yum 服务器
查看可同步的仓库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16[root@localhost yum.repos.d]# yum repolist all Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com repo id repo name status base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com enabled: 10,072 centos6-base CentOS-6 Base enabled: 6,713 centos6-extras CentOS-6 Extras enabled: 47 centos6-updates CentOS-6 Updates enabled: 1,193 centosplus/7/x86_64 CentOS-7 - Plus - mirrors.aliyun.com disabled contrib/7/x86_64 CentOS-7 - Contrib - mirrors.aliyun.com disabled extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com enabled: 526 updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com enabled: 6,173 repolist: 24,724创建仓库存放目录
同步官方仓库到本地
1 2 3 4 5 6 7 8 9# 同步 CentOS6 源 mv /etc/yum.repos.d/CentOS-7.repo /etc/yum.repos.d/CentOS-7.repo.bak reposync -r centos6-base -r centos6-updates -r centos6-extras -p /data/repo/centos6 --download-metadata --newest-only mv /etc/yum.repos.d/CentOS-7.repo.bak /etc/yum.repos.d/CentOS-7.repo # 同步 CentOS7 源 mv /etc/yum.repos.d/CentOS-6.repo /etc/yum.repos.d/CentOS-6.repo.bak reposync -r base -r updates -r extras -p /data/repo/centos7 --download-metadata --newest-only mv /etc/yum.repos.d/CentOS-6.repo.bak /etc/yum.repos.d/CentOS-6.repo-r:指定 repo id(执行
yum repolist all输出内容的第一列)–download-metadata:同步 repodata
–newest-only:只保留最新版本,节省空间
如果没加
--download-metadata,则执行:createrepo /data/repo/centos7/base定时同步
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55cat > /usr/local/bin/yumrepo_sync.sh <<'EOF' #!/bin/bash set -e LOCK_FILE="/var/run/yumrepo_sync.lock" LOG_FILE="/var/log/yumrepo_sync.log" exec >> $LOG_FILE 2>&1 # 防止重复执行 if [ -f "$LOCK_FILE" ]; then echo "$(date '+%F %T') already running" exit 1 fi touch $LOCK_FILE echo "========== $(date '+%F %T') START ==========" # === 同步 CentOS 6 === if [ -f /etc/yum.repos.d/CentOS-7.repo ]; then mv /etc/yum.repos.d/CentOS-7.repo /etc/yum.repos.d/CentOS-7.repo.bak fi reposync \ -r centos6-base \ -r centos6-updates \ -r centos6-extras \ -p /data/repo/centos6 \ --download-metadata \ --newest-only if [ -f /etc/yum.repos.d/CentOS-7.repo.bak ]; then mv /etc/yum.repos.d/CentOS-7.repo.bak /etc/yum.repos.d/CentOS-7.repo fi # === 同步 CentOS 7 === if [ -f /etc/yum.repos.d/CentOS-6.repo ]; then mv /etc/yum.repos.d/CentOS-6.repo /etc/yum.repos.d/CentOS-6.repo.bak fi reposync \ -r base \ -r updates \ -r extras \ -p /data/repo/centos7 \ --download-metadata \ --newest-only if [ -f /etc/yum.repos.d/CentOS-6.repo.bak ]; then mv /etc/yum.repos.d/CentOS-6.repo.bak /etc/yum.repos.d/CentOS-6.repo fi echo "========== $(date '+%F %T') END ==========" rm -f $LOCK_FILE EOFchmod +x /usr/local/bin/yumrepo_sync.sh10 3 * * * /usr/local/bin/yumrepo_sync.sh
客户端配置
CentOS6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16[root@Yum-Repositories ~]# cat ncentos6.repo [base] name=centos6-base baseurl=http://192.168.1.125/centos6/centos6-base/Packages/ gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 [extras] name=centos6-extras baseurl=http://192.168.1.125/centos6/centos6-extras/Packages/ gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 [updates] name=centos6-updates baseurl=http://192.168.1.125/centos6/centos6-updates/Packages/ gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6CentOS7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16[root@Yum-Repositories ~]# cat ncentos7.repo [base] name=centos7-base baseurl=http://192.168.1.125/centos7/base/Packages/ gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [extras] name=centos7-extras baseurl=http://192.168.1.125/centos7/extras/Packages/ gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [updates] name=centos7-updates baseurl=http://192.168.1.125/centos7/updates/Packages/ gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
配置 Nginx
下载 Fancy Index
下载 Nginx-Fancyindex-Theme
下载 Nginx
安装 Nginx
1 2 3 4 5 6 7 8 9# 创建 nginx 用户 useradd -s /sbin/nologin nginx # 配置 cd nginx-1.26.3 ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-stream --with-pcre --with-http_gzip_static_module --with-http_realip_module --add-module=/usr/local/ngx-fancyindex # 编译安装 make && make install配置 Nginx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30vim /usr/local/nginx/conf/vhost/fancyindex.conf server { listen 80; server_name 192.168.1.125; location / { root /data/repo; # 使用 fancyindex fancyindex on; # 不显示精确大小 fancyindex_exact_size off; # 文件日期 fancyindex_time_format "%Y-%m-%d %H:%M"; # 使用用户本地时间 fancyindex_localtime on; fancyindex_header "/theme/header.html"; fancyindex_footer "/theme/footer.html"; } location /theme/ { alias /usr/local/nginx/theme/; } }拷贝主题
启动 Nginx