天天看點

centos7配置yum本地源(iso鏡像)及區域網路使用

2、測試環境:

伺服器1:44.135.8.19(yum源)

伺服器2:44.135.8.1(區域網路機器)

系統:centos7.4

上傳iso鏡像到伺服器,并挂載iso鏡像

mount -t iso9660 CentOS-7-x86_64-Everything-1511.iso /mnt/cdrom/      
centos7配置yum本地源(iso鏡像)及區域網路使用

備份本地repo檔案,并建立自己的repo

[root@HikvisionOS yum.repos.d]# mkdir /opt/repobak
[root@HikvisionOS yum.repos.d]# mv /etc/yum.repos.d/* /opt/repobak      

建立新的repo

[root@HikvisionOS yum.repos.d]# vi myiso.repo      
[c7-media]
name=CentOS-$releasever - Media
#這裡的IP根據現場的yum源決定
#baseurl=http://44.135.8.19/centos7
baseurl=file:///mnt/cdrom
gpgcheck=1
#enabled=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7      

清除緩存并建立緩存

[root@HikvisionOS yum.repos.d]# yum clean all
[root@HikvisionOS yum.repos.d]# yum makecache      

OK啦,測試下!

[root@HikvisionOS yum.repos.d]# yum list      

安裝并啟動httpd服務

[root@HikvisionOS yum.repos.d]# yum -y install httpd      
centos7配置yum本地源(iso鏡像)及區域網路使用
[root@HikvisionOS yum.repos.d]# systemctl start httpd.service      

建立centos軟連接配接

[root@HikvisionOS var]# ln -s /mnt/cdrom /var/www/html/centos7      

浏覽器試下http://44.135.8.19/centos7能否打開,如果可以,即已成功

centos7配置yum本地源(iso鏡像)及區域網路使用

修改repo檔案,将baseurl改成以上浏覽器打開的位址,見上repo代碼,注釋一下就好了

重新清除緩存建立緩存

區域網路内其他機器也一樣,修改一下baseurl即可,yum測試下吧

[root@HikvisionOS yum.repos.d]# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 44.135.8.1  netmask 255.255.255.0  broadcast 44.135.8.255
        inet6 fe80::2a6e:d4ff:fe88:c62d  prefixlen 64  scopeid 0x20<link>
        ether 28:6e:d4:88:c6:2d  txqueuelen 1000  (Ethernet)
        RX packets 193899509  bytes 33451794784 (31.1 GiB)
        RX errors 0  dropped 5574671  overruns 0  frame 0
        TX packets 112575924  bytes 42120101103 (39.2 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 225833801  bytes 26370004359 (24.5 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 225833801  bytes 26370004359 (24.5 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@HikvisionOS yum.repos.d]# yum repolist
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
源辨別                                                  源名稱                                                         狀态
!c7-media                                               CentOS-7 - Media                                               9,007
repolist: 9,007
[root@HikvisionOS yum.repos.d]# cat 
bak/               CentOS-Media.repo  
[root@HikvisionOS yum.repos.d]# cat CentOS-Media.repo 
# CentOS-Media.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=c7-media [command]
#  
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c7-media [command]

[c7-media]
name=CentOS-$releasever - Media
#baseurl=file:///media/CentOS/
#        file:///media/cdrom/
#        file:///media/cdrecorder/
baseurl=http://44.135.8.19/centos7
gpgcheck=1
#enabled=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@HikvisionOS yum.repos.d]#       

PS:也可以用ftp的方式,我這裡采用了http方式,本文為備忘記錄一下