# 制作yum源

## 目标

* 主机M1：安装 httpd + createrepo
* 主机M2：使用M1的yum源

## 步骤

### 一、安装httpd

1、安装httpd

```
$ yum -y install httpd
```

2、配置httpd

2.1 修改httpd的数据根目录与绑定端口（可选）

httpd的数据根目录默认为`/var/www/html/`，默认监听`127.0.0.1:80`。如果需要修改，在配置文件 `/etc/httpd/conf/httpd.conf` 中修改如下两行

```
DocumentRoot "/home/pshizh/apps/httpd/DocumentRoot"
Listen 132.122.239.2:8050
```

备注：如果目录`/home/pshizh/apps/httpd/DocumentRoot`不存在，则须创建，否则会启动失败

2.2 为数据根目录添加访问权限规则

（如果使用默认路径`/var/www/html/`，则此步可省略，如果使用新的目录作为数据根目录，则添加如下内容） 在配置文件 `/etc/httpd/conf/httpd.conf` 中添加如下内容

```
<Directory "/home/pshizh/apps/httpd/DocumentRoot">
    Options Indexes FollowSymlinks
    AllowOverride None
    Require all granted
</Directory>
```

3、启动并验证

```
$ setenforce 0 
$ systemctl start httpd
```

此时，可以访问 132.122.239.2:8050验证启动是否成功

### 二、安装createrepo

4、安装createrepo

```
$ yum -y install createrepo
```

5、创建yum源的根目录

创建文件夹 `/home/pshizh/apps/httpd/DocumentRoot/centos`作为yum源的根目录

6、在`centos`目录下创建目录`packages`，并把rpm包拷贝到`packages`目录下

7、创建yum源

```
$ createrepo -d /home/pshizh/apps/httpd/DocumentRoot/centos
```

该步骤完成后，在centos目录下会出现一个repodata目录，里面保存了yum源的数据

8、访问132.122.239.2:8050/centos

8.1、更新yum源

如果packages中新增了rpm包，执行下列命令更新yum源

```
$ createrepo --update /home/pshizh/apps/httpd/DocumentRoot/centos
```

### 三、使用yum源（M2上）

9、在`/etc/yum.repo.d/`下创建 `qiiaojing.repo`文件，内容如下

```
[qiaojing]
name=qiaojing
baseurl=http://132.122.239.2:8050/centos
enabled=1
gpgcheck=0
```

10、更新cache

```
$ yum clean all & yum makecache
```

11、查看M1中可安装的软件

```
$ yum list | grep qiaojing
```

## 常见问题

1、`Permission denied: AH00072: make_sock: could not bind to address`

解决方法：`setenforce 0`

2、访问 132.122.239.2:8050/centos 时出现 403 forbidden

解决方法：按照2.2配置数据根目录的权限

## 参考文档

* <https://my.oschina.net/u/1461927/blog/372147>
* <http://linux.51yip.com/search/createrepo>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pshizhsysu.gitbook.io/linux/yum/zhi-zuo-yum-yuan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
