定制YUM本地源

  • A+
所属分类:Linux

因客户环境要求服务器都无法连接外网,每次都挂载ISO都很麻烦,所以我们需要部署一台局域网YUM源。

  1. 把iso镜像上传到服务器上,然后挂载

# mkdir -p /opt/{test,iso}

# mount CentOS-7-x86_64-DVD-1708.iso /opt/test

# cp -r /opt/test/* /opt/iso/

# umount /opt/test

2.编辑repo文件

# cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

# vi /etc/yum.repos.d/CentOS-Base.repo

[base]
name=CentOS-$releasever - Base
baseurl=file:///opt/iso
gpgcheck=0
enabled=1

:wq保存退出

3.清除缓存

# yum clean all

4.安装一些常用软件

# yum install vim wget lsof -y

5.安装httpd服务

# yum install httpd curl -y

6.修改httpd配置文件,修改端口

sed -i 's/80/3021/g' /etc/httpd/conf/httpd.conf

sed -i 's@/var/www/html@/opt/iso@g' /etc/httpd/conf/httpd.conf

 

7.关闭selinux

vim /etc/selinux/config

SELINUX=disabled

:wq 保存退出

# setenforce 0

7.重启服务并添加防火墙

#systemctl restart httpd

# systemctl enable httpd

# firewall-cmd --zone=public --add-port=3021/tcp --permanent

# firewall-cmd --reload

8.测试

# curl -i http://127.0.0.1:3021

HTTP/1.1 200 OK
Date: Mon, 09 Apr 2018 17:20:11 GMT
Server: Apache/2.4.6 (CentOS)
Content-Length: 721
Content-Type: text/html;charset=ISO-8859-1

9. 另一台主机测试repo

# cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

# vi /etc/yum.repos.d/CentOS-Base.repo

[base]
name=CentOS-$releasever - Base
baseurl=http://172.20.21.15:3021
gpgcheck=0
enabled=1

安装软件
yum install vim wget -y

OK,安装软件没问题

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: