思路:
有一个台可以上网的机器(可以使用虚拟机),将需要的rpm下载到固定目录。将固定目录拷贝到目标机(没有网络的机器),使用createrepo创建本地源。
1.网络机配置国内源
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \ -i.bak \ /etc/yum.repos.d/CentOS-*.repo sudo yum makecache
如果提示yum被占用,使用kill -9 xxx
2.网络机安装yum-utils,下载包createrepo和其他需要的包
1 yum install yum-utils 2 yumdownloader createrepo --resolve --destdir=/home/rpm
使用yumdownloader命令将需要的rpm和依赖的rpm下载destdir设置的目录
3.目标机设置本地源
将下载的rpm,包括createrepo拷贝目标机,安装creatrepo,设置本地源,修改配置
1 rpm -i /home/rpm/createrepo-0.9.9-28.el7.noarch.rpm 2 creatrepo /home/rpm 3 vi /etc/yum.repos.d/CentOS-Media.repo 4 # CentOS-Media.repo 5 # 6 # This repo can be used with mounted DVD media, verify the mount point for 7 # CentOS-7. You can use this repo and yum to install items directly off the 8 # DVD ISO that we release. 9 # 10 # To use this repo, put in your DVD and use it with the other repos too: 11 # yum --enablerepo=c7-media [command] 12 # 13 # or for ONLY the media repo, do this: 14 # 15 # yum --disablerepo=\* --enablerepo=c7-media [command] 16 17 [c7-media] 18 name=CentOS-$releasever - Media 19 #baseurl=file:///media/CentOS/ 20 # file:///media/cdrom/ 21 # file:///media/cdrecorder/ 22 baseurl=file:///home/rpm/ 23 gpgcheck=1 24 enabled=1 25 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
这时候下载的内容会通过c7-media这个仓,从/home/rpm下载
通过以上方法无法安装devtoolset-8,因为devtoolset-8来自其他源,需要单独配置仓。
1.网络机安装scl源
yum install centos-release-scl
2.网络机下载devtoolset-8包和依赖
yumdownloader devtoolset-8 --resolve --destdir=/home/rpm
3.将网络机devtoolset-8包和依赖拷贝至目标机/home/rpm
4.将网络机/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo拷贝至目标机/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
5.在目标及创建repo文件
# CentOS-SCL.repo # # This repo can be used with mounted DVD media, verify the mount point for # CentOS-7. You can use this repo and yum to install items directly off the # DVD ISO that we release. # # To use this repo, put in your DVD and use it with the other repos too: # yum --enablerepo=centos-sclo-sclo [command] # # or for ONLY the media repo, do this: # # yum --disablerepo=\* --enablerepo=centos-sclo-sclo [command] [centos-sclo-sclo] name=CentOS-7 - SCLo sclo #baseurl=file:///media/CentOS/ # file:///media/cdrom/ # file:///media/cdrecorder/ baseurl=file:///home/rpm/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
6.使用新建的仓安装devtoolset-8
yum --enablerepo=centos-sclo-sclo install devtoolset-8 --disablerepo=c7-media
7.激活devtoolset-8
[root@localhost yum.repos.d]# source /opt/rh/devtoolset-8/enable [root@localhost yum.repos.d]# gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-8/root/usr --mandir=/opt/rh/devtoolset-8/root/usr/share/man --infodir=/opt/rh/devtoolset-8/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-8.3.1-20190311/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)