YUM 仓库搭建

要搭建本地yum仓库首先需要明确的是都有哪些必备的步骤:

服务端

1. 需要将需要制作成仓库的软件的rpm包保存在本地
2. 需要通过createrepo软件制作仓库索引菜单
3. 需要通过ftp或http协议进行传输

1. 制作本地yum仓库的yum源文件

本地保存rpm包
有两种办法

其一:开启yum本地缓存
开启yum本地缓存后,所有通过yum安装的软件包,yum都会把rpm包保存到本地相应目录下

[root@yumcangku etc]# vim /etc/yum.conf 
[main]
cachedir=/warehouse          #这里是代表创建仓库的名字
keepcache=1             #这里的参数是设置是否开启本地缓存,0代表不开启,1代表开启
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

这里是yum本地缓存rpm包的路径
mkdir /warehouse

其二:通过yum命令只下载不安装
yum install  --downloadonly --downloaddir=/warehouse mysql-server.server

--downloadonly  只下载不安装
--downloaddir   指定rpm包的下载路径

安装createrepo

createrepo用于生成repomd.xml。repomd.cml简单来说就是存放本地仓库rpm包的索引信息,我们的yum源就是根据这个文件来知道具体包的存放位置的

yum install createrepo -y

生成Rpm仓库索引

[root@yumcangku /]# createrepo /warehouse/
Spawning worker 0 with 95 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

每次加入新的rpm包,更新yum仓库

createrepo --update /warehouse/

服务端配置仓库局域网访问路径

通过http协议访问

[root@yumcangku /]# yum install nginx -y
[root@yumcangku /]# cd /etc/nginx/conf.d/
[root@yumcangku /]# vim local-basic.conf
server {
        listen 12345;
        server_name 10.0.0.61;
        root /warehouse;
        index index.html;

        location / {
            root /warehouse;
            autoindex on;
            autoindex_localtime on;
            autoindex_exact_size off;
    }
}

访问网址:   http://10.0.0.61:12345/

通过ftp协议访问

[root@yumcangku /]# yum install vsftpd -y

[root@yumcangku conf.d]# systemctl start vsftpd

访问网址:  ftp://10.0.0.61/pub/

客户端配置

yum客户端配置文件
http协议文件

cat warehouse.repo 

[warehouse]
name=Server
baseurl=http://10.0.0.61:12345/
enable=1
gpgcheck=0
priority=1

ftp协议yum源配置文件

cat local-base-ftp.repo 
[local-base]
name=Server
baseurl=ftp://10.0.0.61/pub/
enable=1
gpgcheck=0
priority=1

清yum缓存

yum clean all

查看yum源

[root@yumcangku /]# yum repolist
已加载插件:fastestmirror, security
Loading mirror speeds from cached hostfile
仓库标识                                                                 仓库名称                                                               状态
local-base                             

yum源优先级

1.下载

yum install yum-plugin-priorities.noarch

2.启用插件

cat /etc/yum/pluginconf.d/priorities.conf

[main]
enabled = 1

3.修改本地Yum源优先使用

cat CentOS-Media.repo

[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///media/cdrom/
gpgcheck=0
enabled=1
priority=1        #yum源优先级参数

CentOS-Base.repo

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=2           #yum源优先级参数
#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=2           #yum源优先级参数
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=2           #yum源优先级参数
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=2           #yum源优先级参数
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=2             #yum源优先级参数

priority 数字越小优先级越高

你可能感兴趣的:(YUM 仓库搭建)