前言:一直认为局域网环境,rpm包下载一直是一件很苦恼的事情,如果搭建内网yum仓库就很方便啦!
1. 关闭防护墙 selinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/SELINUX=permissive/SELINUX=disabled/' /etc/selinux/config
2.创建yum仓库存放的文件夹
mkdir /yum_local/x86/centos7
3.安装nginx服务并共享/yum_local/ 目录
yum -y install nginx
touch /etc/nginx/conf.d/yum_local.conf
vi /etc/nginx/conf.d/yum_local.conf
server {
listen 80;
root /yum_local/;
autoindex on;
}
4.安装createrepo 并初始化yum目录
yum -y install createrepo
createrepo /yum_local/x86
5.把相关rpm包下载到/yum_local/x86/centos目录
yum -y install --downloadonly --downloaddir=/yum_local/x86/centos7 ftp
createrepo --update /yum_local/x86/
6.客户端编写yum源文件
[root@node3 yum.repos.d]# cat yum_local.repo
[yum_local]
name=NeoShine Linux Desktop 5 nsmc repo - i386
baseurl=http://192.168.0.131/x86/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-neoshine-release
7. 清理yum缓存及列出可用的yum源
yum clean all
yum repolist
8.客户端下载ftp
yum -y install ftp
9.更新脚本
一键下载rpm包并更新仓库源
#!/bin/bash
if rpm -aq|grep $1 ;then
yum reinstall --downloadonly --downloaddir=/yum_local/x86/centos7 $1
createrepo --update /yum_local/x86/
else
yum install --downloadonly --downloaddir=/yum_local/x86/centos7 $1
createrepo --update /yum_local/x86/
fi