自制YUM仓库

YUM仓库配置文件

# 仓库名称
[base]
# 仓库描述
name=CentOS-$releasever - Base - mirrors.aliyun.com
# 仓库地址
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
# 检测签名机制(1:开启检测 0:关闭检测)
gpgcheck=1
# 签名机制秘钥地址
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

YUM仓库类型

# 1.远程仓库
http://       端口:80
https://      端口:443
ftp://        端口:21

# 2.本地仓库
file://       没有端口(本地协议)

## 协议:http://     https://     ftp://      file://
http://       端口:80
https://      端口:443
ftp://        端口:21
file://       没有端口(本地协议)

本地YUM仓库(file://)

## 先决条件
1:创建仓库的命令
    - createrepo
2:还要有rpm包
    - 网站获取
    - 镜像获取
    - yum源获取
3:yum源的配置文件

[root@web01 ~]# yum install -y vim
[root@web01 ~]# yum install -y createrepo

# 2:挂载镜像 获取rpm包
[root@web01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only

# 3:创建一个仓库目录 必须以.repo结尾
[root@web01 ~]# mkdir /yumck.repo

# 4:拷贝镜像所有rpm包到仓库目录中
[root@web01 ~]# cp /mnt/Packages/*.rpm /yumck.repo/

# 5:先把目录变成仓库
[root@web01 ~]# createrepo /yumck.repo/
Spawning worker 0 with 4070 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

# 6:检查是否把目录变成了仓库
[root@web01 ~]# ll -d /yumck.repo/
drwxr-xr-x 3 root root 225280 Jul 10 17:17 /yumck.repo/

# 7:压缩其他yum源
[root@web01 ~]# gzip -r /etc/yum.repos.d/

# 8:手写yum源配置文件(必须以repo结尾)
[yumck_local]                     # 仓库名称
name=海哥的仓库                   # 仓库描述
baseurl=file:///yumck.repo        # 仓库的地址 # ///因为系统盘前面是有一个/的
gpgcheck=0                        # 关闭签名检测机制 
enabled=1                         # 开启仓库 默认开启 可写可不写

# 9:使用yum源
[root@web01 ~]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
yumck_local                                                                           | 2.9 kB  00:00:00     
yumck_local/primary_db                                                                | 3.2 MB  00:00:00     
repo id                                         repo name                                      status
yumck_local                                     海哥的仓库                                     enabled: 4,070

# 10:安装yum测试
[root@web01 ~]# yum install -y tree
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================
 Package              Arch                   Version                       Repository                   Size
=============================================================================================================
Installing:
 tree                 x86_64                 1.6.0-10.el7                  yumck_local                  46 k

Transaction Summary
=============================================================================================================
Install  1 Package

Total download size: 46 k
Installed size: 87 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : tree-1.6.0-10.el7.x86_64                                                                  1/1 
  Verifying  : tree-1.6.0-10.el7.x86_64                                                                  1/1 

Installed:
  tree.x86_64 0:1.6.0-10.el7                                                                                 

Complete!

img

远程yum仓库

## 先决条件
1:创建仓库的命令
    - createrepo
2:还要有rpm包
    - 网站获取
    - 镜像获取
    - yum源获取
3:yum源的配置文件

# 1:换一台新的虚拟机 安装创建仓库的命令
[root@web01 ~]# yum install -y vim
[root@web01 ~]# yum install -y createrepo

# 2:挂载镜像 获取rpm包
[root@web01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only

# 3:安装vsftpd服务
[root@web01 ~]# yum install -y vsftpd

# 4:启动服务
[root@web01 ~]# systemctl start vsftpd

# 5:检查端口
如果没有netstat 命令,则需要安装
[root@web01 ~]# yum install -y net-tools
[root@web01 ~]# netstat -lntup
[root@web01 ~]# netstat -lntup|grep vsftpd
tcp6       0      0 :::21                   :::*                    LISTEN      1305/vsftpd

# 6:打开浏览器访问:ftp://10.0.0.100/
ftp://IP

# 7:关闭防火墙和selinux
[root@web01 ~]# systemctl stop firewalld
[root@web01 ~]# setenforce 0

# 8:创建仓库目录
[root@web01 ~]# mkdir /var/ftp/pub/{base,epel}
[root@web01 ~]# ll /var/ftp/pub/
drwxr-xr-x 2 root root 6 Apr 25 11:13 base
drwxr-xr-x 2 root root 6 Apr 25 11:13 epel

# 9:拷贝rpm包到base目录下
[root@web01 ~]# cp /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm /var/ftp/pub/base/
[root@web01 ~]# cp /mnt/Packages/net-tools-2.0-0.25.20131004git.el7.x86_64.rpm /var/ftp/pub/base/
[root@web01 ~]# cp /mnt/Packages/zip-3.0-11.el7.x86_64.rpm /var/ftp/pub/base/

# 10:启动仓库pub 生成repodata文件夹 代表仓库完成
[root@web01 ~]# createrepo /var/ftp/pub
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@web01 ~]# ll /var/ftp/pub/
total 4
drwxr-xr-x. 2 root root   92 Apr 26 00:09 base
drwxr-xr-x. 2 root root    6 Apr 25 19:13 epel
drwxr-xr-x. 2 root root 4096 Apr 26 00:05 repodata
### 注意:先生成仓库后拷贝包的的情况下
### 虽然包已存到仓库并在浏览器上可以找到 但远程接受不到 需要删除repodata文件 重新createrepo该仓库

## 在其他机器上手写yum仓库配置文件方法如下
# 1:换一个服务器 打包压缩原来的源仓库
[root@web01 ~]# gzip -r /etc/yum.repos.d/
[root@web01 ~]# yum repolist
Loaded plugins: fastestmirror
repolist: 0
# 2:vim一个文件 必须以.repo结尾
[root@web01 ~]# vim /etc/yum.repos.d/cssd.repo
# 3:写入内容如下
[yumck_base]                       # 仓库名字
name=海哥的仓库                     # 仓库描述
baseurl=ftp://10.0.0.33/pub/    # 源网站地址
gpgcheck=0                       # 关闭签名检测机制
enabled=1                        # 开启仓库 默认开启 可写可不写

# 4:检查yum仓库是否加载成功
[root@web02 ~]# yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
yumck_base                                                            | 2.9 kB  00:00:00     
yumck_base/primary_db                                                 | 3.3 kB  00:00:00     
repo id                              repo name                                       status
yumck_base                             海哥的仓库                              3
repolist: 3

# 5:使用yum安装测试
[root@web01 ~]# yum install -y tree
yumck_base_epel                                  | 2.9 kB     00:00     
yumck_base_epel/primary_db                         | 3.3 kB   00:00     

Installing:
 zip              x86_64              3.0-11.el7               yumck_base              260 k
                                                             # ↑看看是不是走的你自己的仓库
Installed:
  tree.x86_64 0:1.6.0-10.el7                                          

Complete! # 完成