centos6.7搭建yum源服务器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos6.7搭建yum源服务器相关的知识,希望对你有一定的参考价值。

搭建自己的yum源服务器

概括:

第一步:安装apache服务器并启用

第二步:挂载镜像,并复制RPM包

第三步:创建repo数据

第四步:测试

 ++++++++++++++++++++概括完毕+++++++++++++++++++++++

 

安装yum源的电脑

 

1、安装apache服务器并启用(具体一点的参数,可以参考我之前搭建的apache服务器的内容)

 

cd /home /tools/

 

tar zxvf httpd-2.2.27.tar.gz

 

cd httpd-2.2.27/

 

./configure \

--prefix=/application/apache-2.2.27/ \

--enable-deflate \

--enable-expires \

--enable-so \

--with-mpm=worker \

--enable-modules=most \

--enable-rewrite

 

 

make && make install

 

#++++++++++++++编译安装Apache完毕+++++++++++++

 

#++++++++++++++更改apache服务器的配置文件+++++++++++++

cd /application/apache2.2.27/                                   #进入编译安装Apache的目录

 

vim conf/httpd.conf                                                   #编辑Apache的主配置文件

ServerAdmin [email protected]                              #这里是管理员邮箱

ServerName 127.0.0.1:80                                         #这里更改为回环地址,否则会有FQDN报错问题

 

vim /conf/extra/httpd-vhost.conf                           #编辑虚拟主机文件

NameVirtualHost *:80

<VirtualHost *:80>

ServerAdmin [email protected]

DocumentRoot "/application/apache2.2.27/htdocs"            #这是我们之前创建的目录文件

ServerName www.aa.test.org                                  #这是域名,之前我做Apache服务器的时候在Windows电脑上c:/windows/system32/drives/etc/hosts文件里面添加了 192.168.1.106  www.aa.test.org 如果出问题,可能这里需要添加一下

ServerAlias aa.test.org

ErrorLog "logs/repo-error_log"

CustomLog "logs/repo-access_log" common

</VirtualHost>

 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

mkdir  -p  /application/apache2.2.27/htdocs/centos6.8/{x86_64,extra,update}/

//这里创建三个目录,用来放yum源

 

/application/apache2.2.27/bin/apachectl –t                             #检查语法是否有问题

 

/application/apache2.2.27/bin/apachectl start                         #启动一次

 

iptables -t filter -I INPUT -p tcp --dport 80 -j ACCEPT             #添加80端口到防火墙

 

service iptables save                                                              #保存一下刚才添加的防火墙配置,否则重启防火墙或者重启服务,重启系统还需要重新添加80端口

 

mount /dev/cdrom /mnt/cdrom/                                               #挂载本地光盘

 

cd /mnt/cdrom/Packages/                                                       #进入光盘目录下

 

strace mv * /application/apache2.2.27/htdocs/centos6.8/x86_64/     #这里利用strace来跟踪剪切命令,就可以看到剪切的过程,否则看到一片空白

 

yum install createrepo –y                                              #安装createrepo工具

 

createrepo -pdo /application/apache2.2.27/htdocs/x86_64/ /application/apache2.2.27/htdocs/x86_64/

 

createrepo -pdo /application/apache2.2.27/htdocs/extra/ /application/apache2.2.27/htdocs/extra/

 

createrepo -pdo /application/apache2.2.27/htdocs/update/ /application/apache2.2.27/htdocs/update/

##-p输出完美的xml文件格式

##-d生成sqlite数据库,这个是默认的

##-o指定目录文件

 

createrepo --update /application/apache2.2.27/htdocs/centos6.8/x86_64/

#更新repo源的内容,每当加入新的rpm包时就需要更新一次

 

createrepo --update /application/apache2.2.27/htdocs/centos6.8/extra/

 

createrepo --update /application/apache2.2.27/htdocs/centos6.8/update

 

 

换一台电脑测试

yum-config-manager --add-repo=‘IP或者域名/centos6.8/x86_64/‘

 

vim /etc/yum.repo/FILENAME.repo

如:

[base]

name=added from: http://192.168.1.106                          #这是我做yum源的服务器ip

baseurl=http://192.168.1.106/centos6.8/x86_64/

enabled=1

gpgcheck=0

 

[extra]

name=added from: http:// 192.168.1.106

baseurl=http:// 192.168.1.106/centos6.8/extra/

enabled=1

gpgcheck=0

 

 

[update]

name=added from: http:// 192.168.1.106

baseurl=http:// 192.168.1.106/centos6.8/update

enabled=1

gpgcheck=0

 

yum clean all                  #清除缓存

 

yum makecache                #生成缓存

 

yum repolist

 

#++++++++++++查看源+++++++++++++++++++++++++++++++++++++++

[[email protected] ~]# yum repolist

Loaded plugins: fastestmirror, security

Repository ‘192.168.1.104_centos6.7_x86_64‘: Error parsing config: Error parsing "baseurl = ‘192.168.1.104/centos6.7/x86_64‘": URL must be http, ftp, file or https not ""

Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com

 * epel: mirrors.tuna.tsinghua.edu.cn

 * extras: mirrors.aliyun.com

 * updates: mirrors.aliyun.com

仓库标识                仓库名称                                                         状态

repo id           repo name                                                              status

base                    CentOS-6 - Base - mirrors.aliyun.com                                6,696

*epel                    Extra Packages for Enterprise Linux 6 - x86_64                    12,355

extra                    added from:http://192.168.1.104                                        3,204

extras            CentOS-6 - Extras - mirrors.aliyun.com                              64

my               added from:http://192.168.1.104                                       3204

update            added from:http://192.168.1.104                                      3204

updates           CentOS-6 - Updates - mirrors.aliyun.com                         959

repolist: 29,686

以上是关于centos6.7搭建yum源服务器的主要内容,如果未能解决你的问题,请参考以下文章

用系统为centos6的主机,搭建PXE服务器,实现批量安装centos6,7系统

本地局域网yum源搭建-centos/redhat

CentOS6 7 8更换阿里yum源

centos6.7配置本地yum源总结

centos6.7 本地yum源配置

CentOS6/7~配置多个yum源,并设置优先级