linux企业内部源制作

安装http

# yum -y install httpd -y

安装软件包

# yum -y install rsync createrepo

创建目录

# mkdir -p /var/www/repos/centos/7/{os,updates,extras}/x86_64

设置权限

# chmod -R 755 /var/www/repos

从清华官方源同步

# rsync -avz --delete --exclude='repodata' \
rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/ \
/var/www/repos/centos/7/os/x86_64/
# rsync -avz --delete --exclude='repodata' \
rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/updates/x86_64/ \
/var/www/repos/centos/7/updates/x86_64/
# rsync -avz --delete --exclude='repodata' \
rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/extras/x86_64/ \
/var/www/repos/centos/7/extras/x86_64/

创建 metadata repositories

# createrepo /var/www/repos/centos/7/os/x86_64/ 
# createrepo /var/www/repos/centos/7/updates/x86_64/ 
# createrepo /var/www/repos/centos/7/extras/x86_64/

设置定时任务,每天同步

# vi /etc/cron.daily/update-repo
#!/bin/bash
VER='7'
ARCH='x86_64'
REPOS=(os updates extras)
for REPO in ${REPOS[@]}
do
    rsync -avz --delete --exclude='repodata' \
    rsync://mirrors.tuna.tsinghua.edu.cn/centos/${VER}/${REPO}/${ARCH}/ /var/www/repos/centos/${VER}/${REPO}/${ARCH}/
    createrepo /var/www/repos/centos/${VER}/${REPO}/${ARCH}/
done

赋予权限

# chmod 755 /etc/cron.daily/update-repo

配置httpd主机使其他客户端访问

# vi /etc/httpd/conf.d/repos.conf
Alias /repos /var/www/repos

    Options +Indexes
    Require all granted

重启服务

# systemctl restart httpd
  • 5

配置防火墙

# firewall-cmd --add-service=http --permanent 
# firewall-cmd --reload

客户端的配置文件,其中172.16.8.100是源服务器地址

# vi /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=http://172.16.8.100/repos/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=http://172.16.8.100/repos/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=http://172.16.8.100/repos/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

你可能感兴趣的:(l,l,u')