分享一下自制yum仓库

导读今天来给大家介绍一下linux制作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源的配置文件

# 1.安装创建仓库的命令

[root@localhost ]# yum install -y createrepo

# 2.通过镜像,获取rpm包
# 1)挂载镜像

[root@localhost ]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only

# 2)创建一个仓库目录

[root@localhost ]# mkdir /local_yum_repo

# 3)拷贝rpm包到仓库目录中

[root@localhost ]# cp /mnt/Packages/*.rpm /local_yum_repo/

# 4)先把仓库变成目录

[root@localhost ]# createrepo /local_yum_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

# 5)检查是否把目录变成了仓库

[root@localhost ]# ll -d /local_yum_repo/
drwxr-xr-x. 3 root root 225280 Apr 25 17:28 /local_yum_repo/

# 6)压缩其他yum源

[root@localhost ]# gzip -r /etc/yum.repos.d/

# 7)手写yum源配置文件(必须以repo结尾)

# 仓库名
[zxw_local]

# 仓库描述
name=Local Pepository By zxw

# 仓库地址
baseurl=file:///local_yum_repo

#关闭签名检测机制
gpgcheck=0

#开启仓库
enabled=1

# 8)使用yum源

[root@localhost ]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                                                          repo name                                                                                       status
zxw_local                                                                        Local Pepository By zxw                                                                         enabled: 4,070
repolist: 4,070

远程yum仓库

# 1.先决条件

1)创建仓库的命令

 - createrepo

2)还要有rpm包

  - 网站获取
 - 镜像获取
 - yum源获取

3)yum源的配置文件
# 1.安装创建仓库的命令

[root@localhost ]# yum install -y createrepo

# 2.通过镜像,获取rpm包

## 1)挂载镜像

[root@localhost ]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only

## 2)安装安装vsftpd服务

[root@localhost ]# yum install -y vsftpd

## 3)启动服务

[root@localhost ]# systemctl start vsftpd

## 4)检查端口
如果没有命令net-tools就安装一个

[root@localhost ]# 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      941/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1107/master         
tcp6       0      0 :::21                   :::*                    LISTEN      11416/vsftpd        
tcp6       0      0 :::22                   :::*                    LISTEN      941/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1107/master         
[root@localhost ]# netstat -lntup|grep vsftpd
tcp6       0      0 :::21                   :::*                    LISTEN      11416/vsftpd   

## 5)打开浏览器访问:ftp://10.0.0.105

ftp://ID

## 6)关闭防火墙

[root@localhost ]# systemctl stop firewalld
[root@localhost ]# setenforce 0

## 7)创建仓库目录

[root@localhost ]# mkdir /var/ftp/pub/{base,epel}
[root@localhost ]# ll /var/ftp/pub/
total 0
drwxr-xr-x. 2 root root 6 Apr 25 18:27 base
drwxr-xr-x. 2 root root 6 Apr 25 18:27 epel

## 8)拷贝rpm包到base目录下(我就随便弄了俩,这里只是示范)

[root@localhost pub]# cp /mnt/Packages/zip-3.0-11.el7.x86_64.rpm ./base/
[root@localhost pub]# cp /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm ./base/
[root@localhost pub]# ll base/
total 308
-rw-r--r--. 1 root root  47508 Apr 25 18:42 tree-1.6.0-10.el7.x86_64.rpm
-rw-r--r--. 1 root root 266160 Apr 25 18:38 zip-3.0-11.el7.x86_64.rpm

## 9)下载rpm包到epel源

[root@localhost pub]# cd epel/
[root@localhost epel]# wget https://mirrors.aliyun.com/epel/7/x86_64/Packages/h/hdf5-1.8.12-13.el7.x86_64.rpm
[root@localhost epel]# ll
total 1644
-rw-r--r--. 1 root root 1682124 Sep 16  2021 hdf5-1.8.12-13.el7.x86_64.rpm

## 10)分别把这两个目录做成仓库

[root@localhost ]# createrepo /var/ftp/pub/base/
Spawning worker 0 with 2 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@localhost ]# createrepo /var/ftp/pub/epel/
Spawning worker 0 with 1 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@localhost ]# ll /var/ftp/pub/base/
total 312
drwxr-xr-x. 2 root root   4096 Apr 25 19:16 repodata
-rw-r--r--. 1 root root  47508 Apr 25 18:42 tree-1.6.0-10.el7.x86_64.rpm
-rw-r--r--. 1 root root 266160 Apr 25 18:38 zip-3.0-11.el7.x86_64.rpm
[root@localhost ]# ll /var/ftp/pub/epel/
total 1648
-rw-r--r--. 1 root root 1682124 Sep 16  2021 hdf5-1.8.12-13.el7.x86_64.rpm
drwxr-xr-x. 2 root root    4096 Apr 25 19:17 repodata

## 11)在其他机器上手写repo配置文件

[root@zxw ]# vim /etc/yum.repos.d/base_epel.repo
[zxw_base]
name=wode base cangku
baseurl=ftp://10.0.0.105/pub/base/
gpgcheck=0
enabled=1


[zxw_epel]
name=wode epel cangku
baseurl=ftp://10.0.0.105/pub/epel
gpgcheck=0
enabled=1

# 12)检查yum仓库
[root@zxw ]# yum repolist 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                              repo name                                    status
zxw_base                             wode base cangku                             2
zxw_epel                             wode epel cangku                             1
repolist: 3

# 13)使用yum安装
[root@zxw ]# 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               zxw_base             46 k

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

Total download size: 46 k
Installed size: 87 k
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm                                     |  46 kB  00:00:00     
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!
[root@zxw ~]# tree
.
├── 1.TXT
└── 2.TXT

0 directories, 2 files

 www.linuxprobe.com

### 麒麟服务器添加 Yum 源并配置 TLS/SSL 协议 #### 1. ### 添加 Yum 源 如果当前麒麟服务器缺少默认的 Yum 源,可以通过手动方式为其添加合适的软件仓库。以下是具体的操作方法: - **下载对应版本的 Yum 源配置文件** 访问官方或其他可信第三方资源网站获取适用于银河麒麟系统的 Yum 源地址列表。例如阿里云提供了针对不同 Linux 发行版定制化的开源镜像服务[^4]。 ```bash wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo ``` 此命令将 CentOS Vault 中适合特定时间点发布的 epel 存储库定义复制到本地机器上作为新的可用源之一[^5]。 - **更新现有缓存数据** 执行刷新动作让系统识别新增加的内容项。 ```bash yum clean all && yum makecache fast ``` 此时应该可以看到更多可供选择安装程序包的信息展示出来。 --- #### 2. ### 安装 OpenSSL 和其他必要组件 一旦解决了依赖关系问题,则继续按照常规流程来准备环境条件以支持后续步骤中的 SSL 功能实现。 ```bash yum install openssl openssl-devel mod_ssl -y ``` 这些模块对于构建安全通信链路至关重要[^6]。 --- #### 3. ### 创建自签名证书 (可选) 当正式购买 CA 认证机构签发的产品不可行时,可以考虑临时采用自制方案满足内部测试用途。 ```bash openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ -keyout /etc/pki/tls/private/nginx-selfsigned.key \ -out /etc/pki/tls/certs/nginx-selfsigned.crt ``` 这里生成了一对有效期一年的标准 RSA 密钥对连同关联 X.509 v3 格式的电子凭证一并保存至指定目录下供 Nginx 使用[^7]。 随后参照先前描述过的做法调整相应部分参数设定即可达成目标效果[^8]。 --- #### 4. ### 测试与验证 最后记得检验整个链条是否运作正常无误: ```bash systemctl restart nginx.service curl --insecure https://your-domain-or-ip/ ``` 利用 curl 工具模拟发起 HTTPS 请求查看返回结果是否符合预期表现形式[^9]。 --- ### 注意事项 在整个过程中务必保持谨慎态度对待任何涉及密码学运算方面的操作行为,尤其是生产环境中更应严格遵循行业规范指南行事以免造成不必要的安全隐患风险增加情况发生。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值