企業需求,需要在不對外開放的網絡中,部署內部yum源,可以讓內部的服務器通過這臺鏡像yum源,安裝日常所需軟件。
一、準備:
1).安裝http服務器
使用Nginx服務器提供http服務
安裝所需軟件
yum install rsync createrepo httpd -y
createrepo這個軟件,如果是把公網的鏡像repodata所有相關文件夾已經copy過來的話,是不需要操作第四步,直接跳過。
2).Nginx配置
#vi/usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name local_yum;
root /var/repos/;
location / {
autoindexon;
autoindex_exact_size off;
autoindex_localtime on;
}
}
#service nginx reload
三、部分公共yum 鏡像,支持rsync,以mirrors.ustc.edu.cn爲例,編寫腳本vim copy_yum.sh,
內容如下:
localpath="/mirrors/CentOS"
mirror="mirrors.ustc.edu.cn/centos"
rsync="rsync -avzH"
verlist="7 6"
baselist="extras os updates"
archlist="x86_64 i386"
for ver in $verlist
do
for base in $baselist
do
for arch in $archlist
do
remote=rsync://rsync.$mirror/$ver/$base/$arch/
mkdir -pv $localpath/$ver/$base/$arch/
$rsync $remote $localpath/$ver/$base/$arch/
done
done
done
三、執行腳本,sh copy_yum.sh,同步相關文件
四、針對鏡像文件,刪除原有repodata文件
find /mirrors -type d -name repodata -exec rm -rf {} \;
生成自己的repodata索引文件,注意:是兩個版本的文件,其他方式,親測不行
createrepo -pdo /mirrors/CentOS/6/ /mirrors/CentOS/6/
createrepo -pdo /mirrors/CentOS/7/ /mirrors/CentOS/7/
五、客戶端配置(Centos 6、7通用)
vim /etc/yum.repos.d/CentOS-Base.repo
清空裏面內容,粘貼如下內容:
[local_Centos_base] name=local_Centos_base baseurl=http://[替換爲yum源服務器IP]/CentOS/$releasever/os/$basearch/ gpgcheck=0 enabled=1 [local_Centos_extras] name=local_Centos_extras baseurl=http://[替換爲yum源服務器IP]/CentOS/$releasever/extras/$basearch/ gpgcheck=0 enabled=1 [local_Centos_updates] name=local_Centos_updates baseurl=http://[替換爲yum源服務器IP]/CentOS/$releasever/updates/$basearch/ gpgcheck=0 enabled=1
六、測試:
#yum clean all
列出yum源中可用的軟件包 #yum repolist Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile repo id repo name status local_Centos_7_base/7/x86_64 local_Centos_7_base 9,363 local_Centos_7_extras/7/x86_64 local_Centos_7_extras 264 local_Centos_7_updates/7/x86_64 local_Centos_7_updates 856 repolist: 10,483
#yum install telnet -y
參考鏈接:
http://www.centoscn.com/CentOS/config/2014/1225/4368.html
http://blog.csdn.net/cy309173854/article/details/52621192