配置apache

1.安装apache

yum -y install httpd

2.配置apache配置文件

[root@yum-server ~]# tail -n 14 /etc/httpd/conf/httpd.conf 
NameVirtualHost 192.168.40.135:80
<VirtualHost 192.168.40.135:80>
    DocumentRoot /yum/data
    ServerName yum-server.com
    ErrorLog /yum/log/yum-server-error_log
    CustomLog /yum/log/yum-server-access_log common
</VirtualHost>
Alias /data "/yum/data"
<Directory "/yum/data">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

3.创建根目录及日志文件

 mkdir /yum/data -p
 mkdir /yum/log
 touch /yum/log/yum-server-error_log
 touch /yum/log/yum-server-access_log
 chown apache. /yum -R

4.重启apache服务

/etc/init.d/httpd restart

配置yum源

1.安装createrepo

yum -y install createrepo

2.安装yum插件"yum-downloadonly" 后期做测试

yum install yum-downloadonly -y

3.下载一些软件做测试

yum install --downloadonly --downloaddir=/yum/data/ gcc gcc-c++ openssl openssl-devel pcre-devel pcre

4.重建缓存及yum索引

createrepo -v /yum/data/
yum clean all
yum makecache

5.查看自建yum源

[root@yum-server ~]# yum repolist
Loaded plugins: downloadonly, fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
repo id                                                                 repo name                                                                     status
womai-test                                                              CentOS-6 - womai                                                              25
repolist: 25

6.测试

在第二台虚拟机中使用该yum源

[womai-test]
name=CentOS-$releasever - womai
baseurl=http://192.168.40.135/data
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
scp CentOS-test.repo root@192.168.40.172:/etc/yum.repos.d/

[root@localhost ~]# yum install pcre-devel
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package pcre-devel.x86_64 0:7.8-6.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================================================
 Package                                     Arch                                    Version                                     Repository                                   Size
===================================================================================================================================================================================
Installing:
 pcre-devel                                  x86_64                                  7.8-6.el6                                   womai-test                                  318 k

Transaction Summary
===================================================================================================================================================================================
Install       1 Package(s)

Total download size: 318 k

centos下$releasever和$basesearch的取值

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

我们看出来里面包含大量的变量:

$releasever和$basearch

$releasever的值,这个表示当前系统的发行版本,可以通过如下命令查看:

rpm -qi centos-release

[root@localhost yum.repos.d]# rpm -qi centos-release
Name        : centos-release               Relocations: (not relocatable)
Version     : 6                                 Vendor: CentOS
Release     : 5.el6.centos.11.1             Build Date: Wed 27 Nov 2013 03:53:33 AM PST
Install Date: Wed 12 Nov 2014 03:45:21 AM PST      Build Host: c6b9.bsys.dev.centos.org
Group       : System Environment/Base       Source RPM: centos-release-6-5.el6.centos.11.1.src.rpm
Size        : 32670                            License: GPLv2
Signature   : RSA/SHA1, Wed 27 Nov 2013 05:26:58 AM PST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Summary     : CentOS release file
Description :
CentOS release files

其中的Version:6就是我们系统的版本号


$basearch是我们的系统硬件架构(CPU指令集),就是我们常说的i386\i486\i586\i686\...

使用如下命令即可:

arch

[root@localhost yum.repos.d]# arch 
x86_64