翻译来自:
本地仓库
http 仓库
测试
Steps:
1.把rpm包放在一个目录中。可以根据需要在该目录下建立多个子目录。
2.yum使用rpm包的特征信息,需要为包建立特征信息库。这个库通过命令“createrepo”完成。
createrepo /srv/my/repo
3.让yum知道这个目录需要一个“.repo”文件,位于“/etc/yum.repos.d/”。
一个“repo”文件只需要简单的内容就可以正常工作:
[myrepo] name=NAME baseurl=file:///srv/my/repo/ |
4.这时一个库就建立完毕;当需要为库修改、删除、添加包,就重复“第二步”操作即可。
________________________________________
1. 本地仓库
# yum localinstall -y createrepo
# mount -o loop CentOS-xx.x86-64.iso tmp/ && cd tmp
# mkdir -P /data/yum_sources/CentOS/6/x64/RPMS
# mv *.rpm /data/yum_sources/CentOS/6/x64/RPMS
# chown -R root.root /data/yum_sources/CentOS/6
①# createrepo -v /data/yum_sources/CentOS/6/x64
②# chmod -R o-w+r /data/yum_source/CentOS/6
* 当添加新包进去时,执行“①②”。
# vi local.repo
[local] name=CentOS-local baseurl=file:///data/yum_sources/CentOS/6/x64 enabled=1 gpgcheck=0 protect=0 |
上边的“gpgcheck”在不设定的情况下,默认是“1”。表示需要验证。有可能报错如下: |
# wget
# cat CentOS-Testing.repo
[c5-testing]name=CentOS-5 Testingbaseurl=http://dev.centos.org/centos/$releasever/testing/$basearch/enabled=0gpgcheck=1gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing
直接复制光盘内容就可以生成yum仓库
# mount -o loop CentOS-7.0-1406-x86_64-DVD.iso tmp/ && cd tmp# cp -r repodata /dinglicom/yum_sources/CentOS/7/x86_64/RPMS# cp -rv Packages /dinglicom/yum_sources/CentOS/7/x86_64/RPMS# cat /etc/yum.repos.d/CentOS-7.repo
[local-7]name=CentOS-7-localbaseurl=file:///dinglicom/yum_sources/CentOS/7/x86_64/RPMSenabled=1gpgcheck=0protect=0
2. http 仓库
* 新建个“http.repo”就可以了。根据上边的例子,适当修改路径即可。
# vi http.repo
[local]name=CentOS-local# baseurl=file:///data/yum_sources/CentOS/6/x64# baseurl=http://mirror.centos.org/centos/6/x64baseurl=http://10.97.57.2/centos/6/x64enabled=1gpgcheck=0protect=0
* 把 rpm 包放到 http 服务器的对应目录下即可。
启用 CentOS 在亚洲上海交通大学的网站 yum 源。例子如下:
[sjtu-7]name=sjtu-7baseurl=http://ftp.cuhk.edu.hk/pub/Linux/centos/7/os/x86_64/enabled=1gpgcheck=1protect=0gpgkey=http://ftp.cuhk.edu.hk/pub/Linux/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
3. 测试
# cat /etc/yum.repos.d/local.repo
[local]name=CentOS-localbaseurl=file:///data/yum_sources/CentOS/6/x64enabled=1gpgcheck=0protect=0
查看可用的“yum源”
# yum repolist enable
# yum repolist all
Loaded plugins: fastestmirror, protectbase, refresh- : packagekit, securityLoading mirror speeds from cached hostfile0 packages excluded due to repository protectionsrepo id repo name statuslocal CentOS-local enabled: 4,799repolist: 4,799
例子:
Here is your custom MariaDB YUM repository entry for CentOS. Copy and paste it into a file under /etc/yum.repos.d/ (we suggest naming the file MariaDB.repo or something similar). See "" for detailed information.
# MariaDB 10.1 CentOS repository list - created 2016-06-25 02:47 UTC# http://downloads.mariadb.org/mariadb/repositories/[mariadb]name = MariaDBbaseurl = http://yum.mariadb.org/10.1/centos6-amd64gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDBgpgcheck=1