系统相关
首页 > 系统相关> > 构建局域网YUM仓库

构建局域网YUM仓库

作者:互联网

[root@yum ~]# yum repolist

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
[root@yum ~]# yum install  wget gcc* createrepo yum-utils -y
- yum-utils           reposync同步工具
- createrepo            编辑yum库工具
- plugin-priorities   控制yum源更新优先级工具
[root@yum ~]# mkdir -p /mirror/7
同步到本地目录
[root@yum ~]# reposync -p /mirror/7         # 同步整个源使用这个
[root@yum ~]# reposync -r base -p /mirror/7 # 这里同步base目录到本地
注:系统自动创建相关目录,并下载,时间较长请耐心等待。可以用  repo -r --repoid=repoid指定要查询的repo id,可以指定多个
更新新的rpm包
[root@yum ~]# reposync -np /mirror/7
创建索引
createrepo -po /mirror/7/base/ /mirror/7/base/
createrepo -po /mirror/7/extras/ /mirror/7/extras/
createrepo -po /mirror/7/updates/ /mirror/7/updates/
更新源数据
createrepo --update /mirror/7/base
createrepo --update /mirror/7/extras
createrepo --update /mirror/7/updates
[root@yum ~]#vim /mirror/7/script/centos_yum_update.sh
#!/bin/bash
DATE=$(date +%F)
LogFile=/var/log/aliyumrepo_${DATE}.log
function log_error() {
    echo -e "\033[31m [ERROR] $@ \033[0m"
    echo "ERROR $@"  >> $LogFile
}
function log_info() {
    echo -e "\033[32m [INFO] $@ \033[0m"
    echo "INFO $@"  >> $LogFile
}
function log_warn() {
    echo -e "\033[33m [WARN] $@ \033[0m"
    echo "WARN $@"  >> $LogFile
}
log_info "${DATE} 正在同步..."
reposync -np /mirror/7 &>/dev/null
if [ $? -eq 0 ];then
    createrepo --update /mirror/7/base
    createrepo --update /mirror/7/extras
    createrepo --update /mirror/7/updates
    log_info "${DATE} aliyum_yum update successful"
else
    log_error "${DATE} aliyum_yum update failed"
fi 
[root@yum ~]# yum install nginx -y
找到nginx配置文件,并修改nginx配置文件:
[root@yum ~]# vim nginx.conf
    server {
        listen       80;
        server_name  localhost;
        root         /mirror/7;         # 这里是yum源存放目录      
        location / {
            autoindex on;                   # 打开目录浏览功能
            autoindex_exact_size off;   # on、off:以可读的方式显示文件大小
            autoindex_localtime on;         # on、off:是否以服务器的文件时间作为显示的时间
            charset utf-8,gbk;          # 展示中文文件名
            index index.html;
        }
}
[root@clean ~]# vim ftp.repo
[base]
name=CentOS-$releasever - Base - mirror.template.com
baseurl=ftp://10.10.10.1/yum-mirror/7/base/
enabled=1
gpgkey=ftp://10.10.10.1/yum-mirror/7/rpm-gpg/RPM-GPG-KEY-CentOS-7
gpgcheck=0

[updates]
name=CentOS-$releasever - Updates - mirror.template.com
baseurl=ftp://10.10.10.1/yum-mirror/7/updates/
enabled=1
gpgkey=ftp://10.10.10.1/yum-mirror/7/rpm-gpg/RPM-GPG-KEY-CentOS-7
gpgcheck=0

[extras]
name=CentOS-$releasever - Extras - mirrors.template.com
baseurl=ftp://10.10.10.1/yum-mirror/7/extras/
enabled=1
gpgkey=ftp://10.10.10.1/yum-mirror/7/rpm-gpg/RPM-GPG-KEY-CentOS-7
gpgcheck=0

标签:仓库,createrepo,update,局域网,base,yum,mirror,YUM,root
来源: https://www.cnblogs.com/outsrkem/p/11486757.html