由於IDC的一些伺服器沒有外網,不能對外訪問。所以打算部署一套內網的yum源環境,以供內網伺服器使用。以下簡單記錄下操作過程:
1)下載centos6.9和centos7.3的映象,並掛載 [root@dev ~]# wget http://mirrors.163.com/centos/6.9/isos/x86_64/CentOS-6.9-x86_64-bin-DVD1.iso [root@dev ~]# wget http://mirrors.163.com/centos/7.3.1611/isos/x86_64/CentOS-7-x86_64-DVD-1611.iso [root@dev ~]# mount -o loop -t iso9660 CentOS-6.9-x86_64-bin-DVD1.iso /mnt [root@dev ~]# mount -o loop -t iso9660 CentOS-7-x86_64-DVD-1611.iso /opt/aa [root@dev ~]# ls /mnt/ CentOS_BuildTag images repodata RPM-GPG-KEY-CentOS-Testing-6 EFI isolinux RPM-GPG-KEY-CentOS-6 TRANS.TBL EULA Packages RPM-GPG-KEY-CentOS-Debug-6 GPL RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Security-6 [root@dev ~]# ls /opt/aa/ CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7 EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL 2)部署nginx [root@dev ~]# yum install -y pcre pcre-devel openssl openssl-devel gcc [root@dev ~]# groupadd -r nginx [root@dev ~]# useradd -r -g nginx -s /bin/false -M nginx [root@dev ~]# cd /usr/loca/src [root@dev src]# wget http://nginx.org/download/nginx-1.8.0.tar.gz [root@dev src]# tar -zxvf nginx-1.8.0.tar.gz [root@dev src]# cd nginx-1.8.0 [root@dev nginx-1.8.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre [root@dev src]# make && make install [root@dev ~]# cat /data/nginx/conf/vhosts/yum.conf server { listen 80; server_name localhost; index index.html index.php index.htm; access_log /data/nginx/logs/access.log main; error_log /data/nginx/logs/error.log; location /{ root /data/centos; autoindex on; autoindex_exact_size off; autoindex_localtime on; } } [root@dev ~]# mkdir -p /data/centos/6/os/x86_64/6/ [root@dev ~]# mkdir -p /data/centos/7/os/x86_64/7/ [root@dev ~]# cp -r /mnt/* /data/centos/6/os/x86_64/6/ [root@dev ~]# cp -r /opt/aa/* /data/centos/7/os/x86_64/7/ [root@dev ~]# /data/nginx/sbin/nginx -t [root@dev ~]# /data/nginx/sbin/nginx -s reload
訪問http://192.168.1.240
然後就可以在客戶機上配置自己的本地yum源,如下(其中192.168.1.240是上面yum源部署機的ip) [root@dev ~]# cat centos6_yum.repo [base] name=kevin repo baseurl=http://192.168.1.240/6/os/x86_64/6/ gpgcheck=0 enabled=1 [updates] name=kevin update baseurl=http://192.168.1.240/6/os/x86_64/6/ gpgcheck=0 enabled=1 [root@dev ~]# cat centos7_yum.repo [base] name=kevin repo baseurl=http://192.168.1.240/7/os/x86_64/7/ gpgcheck=0 enabled=1 [updates] name=kevin update baseurl=http://192.168.1.240/7/os/x86_64/7/ gpgcheck=0 //不檢查key enabled=1 將上面的centos6或centos7的yum原始檔放到客戶機的/etc/yum.repos.d/目錄下,然後執行下面兩條命令即可: # mv CentOS-Base.repo CentOS-Base.repo.bak # yum clean all # yum makecache
後續發現yum源裡的包不全,有一些rpm的包不存在。發現是剛開始下載centos映象的時候,只下載了CentOS-6.9-x86_64-bin-DVD1.iso,應該將CentOS-6.9-x86_64-bin-DVD2.iso的映象也下載下來。然後掛載到本地,將裡面os/x86_64/Packages下的rpm包拷貝到/data/centos/6/os/x86_64/6的Packages下,最後yum makecache就行了。