一.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源的配置文件

# 1.安装创建仓库的命令
[root@localhost <sub>]# yum install -y createrepo
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: ftp.sjtu.edu.cn
* updates: ftp.sjtu.edu.cn
Package createrepo-0.9.9-28.el7.noarch already installed and latest version
Nothing to do

# 2.通过镜像,获取rpm包
## 挂载镜像
[root@localhost </sub>]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost <sub>]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 19G 1.2G 18G 7% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 497M 120M 378M 25% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /mnt

## 创建一个仓库目录
[root@localhost </sub>]# mkdir /quanyi_yum_repo
[root@localhost <sub>]# ll /
drwxr-xr-x. 2 root root 6 Apr 25 20:56 quanyi_yum_repo

# 3.拷贝所有rpm包到仓库目录中
[root@localhost </sub>]# cp /mnt/Packages/zip-3.0-11.el7.x86_64.rpm /quanyi_yum_repo/
[root@localhost <sub>]# cp /mnt/Packages/unzip-6.0-19.el7.x86_64.rpm /quanyi_yum_repo/
[root@localhost </sub>]# cp /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm /quanyi_yum_repo/
[root@localhost <sub>]# cp /mnt/Packages/wget-1.14-18.el7.x86_64.rpm /quanyi_yum_repo/

[root@localhost </sub>]# ll /quanyi_yum_repo
total 1028
-rw-r--r--. 1 root root 47508 Apr 25 20:59 tree-1.6.0-10.el7.x86_64.rpm
-rw-r--r--. 1 root root 173704 Apr 25 20:59 unzip-6.0-19.el7.x86_64.rpm
-rw-r--r--. 1 root root 560152 Apr 25 21:00 wget-1.14-18.el7.x86_64.rpm
-rw-r--r--. 1 root root 266160 Apr 25 20:59 zip-3.0-11.el7.x86_64.rpm

# 4.先把目录变成仓库
[root@localhost <sub>]# createrepo /quanyi_yum_repo
Spawning worker 0 with 4 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

# 5.检查是否把目录变成了仓库
[root@localhost </sub>]# ll -d /quanyi_yum_repo/repodata/
drwxr-xr-x. 2 root root 4096 Apr 25 21:03 /quanyi_yum_repo/repodata/

# 6.压缩其他yum源
[root@localhost <sub>]# gzip -r /etc/yum.repos.d
[root@localhost </sub>]# ll /etc/yum.repos.d
total 28
-rw-r--r--. 1 root root 549 Nov 23 2018 CentOS-Base.repo.gz
-rw-r--r--. 1 root root 735 Nov 23 2018 CentOS-CR.repo.gz
-rw-r--r--. 1 root root 426 Nov 23 2018 CentOS-Debuginfo.repo.gz
-rw-r--r--. 1 root root 232 Nov 23 2018 CentOS-fasttrack.repo.gz
-rw-r--r--. 1 root root 381 Nov 23 2018 CentOS-Media.repo.gz
-rw-r--r--. 1 root root 506 Nov 23 2018 CentOS-Sources.repo.gz
-rw-r--r--. 1 root root 633 Nov 23 2018 CentOS-Vault.repo.gz

# 7.手写yum源配置文件(必须以repo结尾)
[root@localhost <sub>]# vi /etc/yum.repos.d/quanyi_yum.repo
[lqy_local] #仓库名称
name=Local Repository By lqy #仓库描述
baseurl=file:///quanyi_yum_repo #仓库的地址
gpgcheck=0 #关闭签名检测机制
enabled=1 #开启仓库

# 8.使用yum源
[root@localhost </sub>]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repolist: 0
[root@localhost <sub>]# vi /etc/yum.repos.d/quanyi_yum_repo
[root@localhost </sub>]# vi /etc/yum.repos.d/quanyi_yum.repo
[root@localhost <sub>]# vi /etc/yum.repos.d/quanyi_yum_repo
[root@localhost </sub>]# vi /etc/yum.repos.d/quanyi_yum.repo
[root@localhost ~]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
lqy | 2.9 kB 00:00:00
lqy/primary_db | 4.1 kB 00:00:00
repo id repo name status
lqy quanyiyuan enabled: 4
repolist: 4

四.远程ftp服务YUM仓库

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

# 1.安装创建仓库的命令
[root@localhost <sub>]# yum install -y createrepo
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: ftp.sjtu.edu.cn
* updates: ftp.sjtu.edu.cn
Package createrepo-0.9.9-28.el7.noarch already installed and latest version
Nothing to do

# 2.通过镜像,获取rpm包
## 挂载镜像
[root@localhost </sub>]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost <sub>]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 19G 1.2G 18G 7% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 497M 120M 378M 25% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /mnt

# 3.安装vsftpd服务
[root@localhost </sub>]# yum install -y vsftpd

# 4.启动服务
[root@localhost <sub>]# systemctl start vsftpd

# 5.检查端口
如果没有netstat 命令,则需要安装
[root@localhost </sub>]# yum install -y net-tools
[root@localhost ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6859/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7016/master
tcp6 0 0 :::21 :::* LISTEN 7619/vsftpd
tcp6 0 0 :::22 :::* LISTEN 6859/sshd
tcp6 0 0 ::1:25 :::* LISTEN 7016/master

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

自制YUM仓库_centos

# 7.关闭防火墙和selinux
[root@localhost <sub>]# systemctl stop firewalld
[root@localhost </sub>]# setenforce 0

# 8.创建仓库目录
[root@localhost <sub>]# mkdir /var/ftp/pub/{base,epel}
[root@localhost </sub>]# ll /var/ftp/pub/
total 0
drwxr-xr-x. 2 root root 6 Apr 25 20:58 base
drwxr-xr-x. 2 root root 6 Apr 25 20:58 epel

# 9.拷贝rpm包到base目录下
[root@localhost <sub>]# cp /mnt/Packages/zip-3.0-11.el7.x86_64.rpm /var/ftp/pub/base/
[root@localhost </sub>]# cp /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm /var/ftp/pub/base/
[root@localhost <sub>]# cp /mnt/Packages/wget-1.14-18.el7.x86_64.rpm /var/ftp/pub/base/

# 10.下载rpm包到epel源
[root@localhost epel]# wget https://mirrors.aliyun.com/epel/7/x86_64/Packages/n/nagios-plugins-breeze-2.3.3-2.el7.x86_64.rpm

# 11.把base,epel分别做成仓库
[root@localhost pub]# createrepo /var/ftp/pub/base/
Spawning worker 0 with 3 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

[root@localhost pub]# createrepo /var/ftp/pub/epel/
Spawning worker 0 with 2 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

# 12.检查 base,epel是否成功变成仓库
[root@localhost pub]# ll base
total 860
drwxr-xr-x. 2 root root 4096 Apr 25 21:54 repodata
-rw-r--r--. 1 root root 47508 Apr 25 21:01 tree-1.6.0-10.el7.x86_64.rpm
-rw-r--r--. 1 root root 560152 Apr 25 21:02 wget-1.14-18.el7.x86_64.rpm
-rw-r--r--. 1 root root 266160 Apr 25 21:01 zip-3.0-11.el7.x86_64.rpm

[root@localhost pub]# ll epel
total 200
-rw-r--r--. 1 root root 21966 Apr 10 2020 nagios-plugins-breeze-2.3.3-2.el7.x86_64.rpm
drwxr-xr-x. 2 root root 4096 Apr 25 21:54 repodata
-rw-r--r--. 1 root root 173704 Apr 25 21:13 unzip-6.0-19.el7.x86_64.rpm

# 13.压缩其他yum源
[root@localhost </sub>]# gzip -r /etc/yum.repos.d/
[root@localhost <sub>]# ll /etc/yum.repos.d/
total 28
-rw-r--r--. 1 root root 549 Nov 23 2018 CentOS-Base.repo.gz
-rw-r--r--. 1 root root 735 Nov 23 2018 CentOS-CR.repo.gz
-rw-r--r--. 1 root root 426 Nov 23 2018 CentOS-Debuginfo.repo.gz
-rw-r--r--. 1 root root 232 Nov 23 2018 CentOS-fasttrack.repo.gz
-rw-r--r--. 1 root root 381 Nov 23 2018 CentOS-Media.repo.gz
-rw-r--r--. 1 root root 506 Nov 23 2018 CentOS-Sources.repo.gz
-rw-r--r--. 1 root root 633 Nov 23 2018 CentOS-Vault.repo.gz

# 14.编辑base,epel仓库内容
[root@localhost </sub>]# vi /etc/yum.repos.d/base.repo
[quanyiyuan]
name=Local Repository By lqy
baseurl=ftp://10.0.0.100/pub/base
gpgcheck=0
enabled=1

[root@localhost <sub>]# vi /etc/yum.repos.d/epel.repo
[lqy_local]
name=Local Repository By Quanyi
baseurl=ftp://10.0.0.100/pub/epel
gpgcheck=0
enabled=1

# 15.检查yum仓库
[root@localhost </sub>]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
lqy_local | 2.9 kB 00:00:00
quanyiyuan | 2.9 kB 00:00:00
lqy_local/primary_db | 2.7 kB 00:00:00
repo id repo name status
lqy_local Local Repository By Quanyi 2
quanyiyuan Local Repository By lqy 3
repolist: 5

自制YUM仓库_centos_02

自制YUM仓库_centos_03