這篇博客是yum倉庫的配置過程,如果是yum客戶端配置請參考 http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_002.html
1 環境介紹
這里我有2個環境,一個centos7,一個centos6環境, 打算使用centos6作為yum倉庫,然后使用centos7作為客戶端。
2 環境准備
我們知道配置yum的時候我們需要指定baseurl的,只有三種協議支持的,分別是http,ftp,file。這里我們我們選擇ftp方式,在centos6機器上安裝ftp軟件並提供服務。
2.1 安裝ftp服務端軟件
[root@centos6 ~]# yum install vsftpd -y #安裝vsftpd軟件,沒有yum配置的話,可以使用rpm安裝 [root@centos6 ~]# chkconfig vsftpd on #開機啟動 [root@centos6 ~]# service vsftpd start #啟動ftp服務 Starting vsftpd for vsftpd: [ OK ]
2.2 禁用selinux
[root@centos6 ~]# getenforce #查看當前的selinux狀態 Enforcing [root@centos6 ~]# setenforce 0 #禁用 [root@centos6 ~]# sed -i 's@SELINUX=enforcing@SELINUX=permissive@' /etc/sysconfig/selinux #修改配置文件
2.3 關閉防火牆
[root@centos6 ~]# service iptables status #查看當前的防火牆設置 Table: filter Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 5 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) num target prot opt source destination 1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) num target prot opt source destination [root@centos6 ~]# service iptables stop #關閉防火牆 iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ] [root@centos6 ~]# chkconfig iptables off #開機不啟動ftp
2 提供yum倉庫文件
2.1 把centos7的包復制到centos6的機器上
[root@centos6 os]# mkdir -pv /var/ftp/pub/yum/centos/7/os/x86_64 #創建對應目錄, 這個目錄是仿照aliyun的那個目錄組織的,清晰,這樣客戶端可以使用$basearch,$releasevel變量
[root@centos6 os]# mount /dev/sr1 -r /var/ftp/pub/yum/centos/7/os/x86_64 #我這里就直接掛載個光盤,建議使用硬盤文件,而不是光盤 [root@centos6 os]# ll /var/ftp/pub/yum/centos/7/os/x86_64
3 測試ftp服務是否正常
由於我們的centos7沒有ftp的軟件,所以這里使用wget測試下
[root@centos7 yum.repos.d]$wget ftp://172.18.1.159/ #下載下ftp頁面 [root@centos7 yum.repos.d]$ cat index.html |grep pub #查看是否有pub,如果有那就是ftp服務是正常的了 2017 Nov 21 07:20 Directory <a href="ftp://172.18.1.159:21/pub/">pub/</a>
測試發現,我們的centos6提供的ftp一切正常, 可以供centos7使用的。
4 centos7配置測試yum
4.1 配置yum配置文件
[root@centos7 yum.repos.d]$ vim network.repo #編寫repo文件 [root@centos7 yum.repos.d]$ cat network.repo [network] name=network baseurl=ftp://172.18.1.159/pub/yum/centos/$releasever/os/$basearch/ gpgcheck=0
4.2測試yum配置
[root@centos7 yum.repos.d]$ yum clean all #清空緩存 Loaded plugins: fastestmirror, langpacks Cleaning repos: network Cleaning up everything Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos Cleaning up list of fastest mirrors [root@centos7 yum.repos.d]$ yum -y install lftp #測試安裝軟件
5 如何給特定的rpm包生成倉庫
[root@centos6 test]# yum install createrepo -y #創建倉庫需要createrepo命令,有createrepo這個包提供
#copy一些rpm包到test目錄中。 [root@centos6 test]# createrepo . #在rpm文件里面執行,就可以創建一個倉庫
剩下的工作就是把這個目錄作為baseurl提供出去了。