1.新建目錄
# mkdir -p /content/rhel7/x86_64/{isos,dvd}/
2.上傳RedHat安裝光盤鏡像,上傳后的路徑為 /content/rhel7/x86_64/isos/rhel-server-7.2-x86_64-dvd.iso
3.搭建http服務器(nginx),用來網絡訪問這個yum源
# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# yum -y install nginx
4.創建yum源網站(http://content.example.com)配置文件
# vi /etc/nginx/conf.d/content.example.com.conf
server { listen 80; server_name content.example.com; access_log /var/log/nginx/content.example.com.access.log combined; location / { root /content; index index.html index.htm; autoindex on; autoindex_exact_size off; autoindex_localtime on; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
5.修改網站目錄SELinux類型
# chcon -t public_content_t -R /content/
6.添加DNS記錄到/etc/hosts文件
# echo "192.168.136.254 content.example.com" >> /etc/hosts
7.開通防火牆
# firewall-cmd --permanent --add-service=http
# firewall-cmd --reload
8.設置nginx服務開機自啟動,並啟動nginx服務
# systemctl enable nginx
# systemctl start nginx
9.設置開機自動掛載光盤鏡像到/content/rhel7/x86_64/dvd
# echo "/content/rhel7/x86_64/isos/rhel-server-7.2-x86_64-dvd.iso /content/rhel7/x86_64/dvd iso9660 loop,ro 0 0" >> /etc/fstab
# mount -a
10.創建repo文件
# vi /etc/yum.repos.d/rhel-dvd.repo
本機:
[rhel-dvd] name=rhel dvd baseurl=file:///content/rhel7/x86_64/dvd gpgcheck=0 enable=1
局域網內其他服務器:
[rhel-dvd] name=remote copy of dvd baseurl=http://content.example.com/rhel7/x86_64/dvd gpgcheck=0 enabled=1
11.生成repo cache,用來測試新yum源是否生效
# yum makecache