vim yum.sh ##建立腳本文件
*!/bin/bash
#################creat local yum source############
mkdir /westos ##建立掛載點
mount /iso/rhel-server-7.0-x86_64-dvd.iso /westos ##將鏡像文件掛哉在建立文件案目錄劇下
mkdir /backup
mv /etc/yum.repos.d/* /backup ##將干擾文件放在其他新建的目錄下
cat > /etc/yum.repos.d/yum.repo << end ## 編輯yum.repo
[test]
name=test
baseurl=file:///westos
gpgcheck=0
end
yum clean all ##刷新倉庫配置 ####################install share server##########
yum intall httpd -y ##安裝http
systemctl start httpd ##開啓http指令
systemctl enable httpd
systemctl disable firewalld ##表示開機就關閉防火牆
systemctl stop firewalld
###################mount iso to share directory##########
umount westos ##彈出westos掛載點
mkdir /var/www/html/rehl7.0 ##新建在共享文當下的目錄
mount /iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/rhel7.0 ##重新掛載
echo "/iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/rhel7.0 iso9660 ro 0 0" >>
/etc/fstab ##mount爲臨時掛載,要將掛載改爲永久則需要更改配置文件(>>表示添加附加內容)
################cofig local yum##############
rm -fr /etc/yum.repos.d/yum.repo
cat > /etc/yum.repos.d/yum.repo << end ##重新編輯yum.repo文件
[test]
name=test
baseurl=file:///var/www/html/rhel7.0 ##路徑改變
gpgcheck=0
end
一個建立yum共享目錄的腳本就寫好了,在瀏覽器上輸入地址就可以看到共享的目錄
在瀏覽器上輸入網址時應注意兩種寫法
: file:///var/www/html/rhel7.0 (第三個/號後面表示的是本機的根目錄)
: http://172.25.39.172(訪問主機的ip)/rhel7.0(ip後面/號表示apache的根目錄)