【原创】运维基础之yum离线环境安装软件

时间:2022-08-03 15:26:58

首先查看系统版本号,然后根据版本号从 CentOS-7-x86_64-DVD-1708.iso 和 CentOS-7-x86_64-Everything-1708.iso 根据需要选择一个下载,我这里是7.4.1708

# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

# wget http://vault.centos.org/7.4.1708/isos/x86_64/CentOS-7-x86_64-DVD-1708.iso
# mkdir /mnt/centos7
# mount -o loop,ro CentOS-7-x86_64-DVD-1708.iso /mnt/centos7

将之前的repo备份

# mkdir /etc/yum.repo.d/bak
# mv /etc/yum.repo.d/*.repo /etc/yum.repo.d/bak/

以下任选其一

1 直接使用iso作为源

# vi /etc/yum.repos.d/centos7_iso.repo
[centos7-Server]
name=ServerFault Answer
baseurl=file:///mnt/centos7
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1
gpgcheck=1

2 将iso拷贝到本地文件夹作为源

# cp -a /mnt/centos7/ /yum/

# vi /etc/yum.repos.d/centos7_localhost.repo
[centos7-Server]
name=ServerFault Answer
baseurl=file:///yum/centos7
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1
gpgcheck=1

3 搭建nginx或httpd或ftpd服务作为局域网源

# vi /etc/yum.repos.d/centos7_localnetwork.repo
[centos7-Server]
name=ServerFault Answer
baseurl=http://192.168.0.1/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1
gpgcheck=1

其中nginx配置如下(增加一个location)

location / {
root /yum/centos7;
autoindex on;
}

测试

# yum repolist
# yum install $anything