扩大
缩小

yum仓库的创建

这篇博客是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提供出去了。

 

posted on 2017-11-29 20:32  LinuxPanda  阅读(6014)  评论(0编辑  收藏  举报

导航