写本文的时候并没有实际的服务器供我使用,所以只能用虚拟机了,造成的不便请读者见谅,不过这篇文章完全可以用在实际工作中的YUM服务器,按本文配置YUM服务器的好处是你可以把一些软件放在服务器的Apache服务的根目录下,用网页打开可以直接下载。所以很方便。如果内网不会,或者不清楚,可以给我留言,我会给你详解的。谢谢大家的支持^ ^

实验环境

1)Oracle VM VirtualBox虚拟机

2)CentOS-6.5-x86_64-bin-DVD1.ISO光盘

3)Apache Web服务器

1.创建虚拟机YUM(前写篇文章介绍过怎么创建,这里不多做解释);进入下一步

注:如果是实际公司需要,就直接在服务器上安装CentOS6.5系统然后配置。

2.配置网卡eth0,直至网络ping通为止;进入下一步

[root@YUM ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0                   网卡名字ONBOOT=yes                    是否自动启动BOOTPROTO=dhcp                获取IP地址方式,这里是动态获取~~:wq                           保存并退出[root@YUM ~]# ping www.baidu.comPING www.a.shifen.com (61.135.169.125) 56(84) bytes of data.64 bytes from 61.135.169.125: icmp_seq=1 ttl=54 time=4.19 ms64 bytes from 61.135.169.125: icmp_seq=2 ttl=54 time=3.79 ms64 bytes from 61.135.169.125: icmp_seq=3 ttl=54 time=6.93 ms^C--- www.a.shifen.com ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2124msrtt min/avg/max/mdev = 3.797/4.975/6.931/1.394 ms

3.安装Apache Web服务;进入下一步

注:如果是内网则可以将Apache服务考入服务器中,用rpm -ivh安装;或者编译安装;或者先挂载光盘,再从挂载中的Packages文件夹中找到httpd.rpm安装包,进行安装。

[root@YUM ~]# yum -y install httpd*Complete!                     安装完成

4.挂载CentOS-6.5-x86_64-bin-DVD1至/mnt文件夹下;进入下一步

[root@YUM ~]# mount /dev/cdrom2 /mnt[root@YUM ~]# cd /mnt/[root@YUM mnt]# lsCentOS_BuildTag  isolinux                  RPM-GPG-KEY-CentOS-Debug-6EFI              Packages                  RPM-GPG-KEY-CentOS-Security-6EULA             RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Testing-6GPL              repodata                  TRANS.TBLp_w_picpaths           RPM-GPG-KEY-CentOS-6[root@YUM mnt]#

5.在根目录下新建文件夹/data;进入下一步

[root@YUM mnt]# cd ../..[root@YUM /]# mkdir data[root@YUM /]# lsbin   data  etc   lib    lost+found  mnt  proc  sbin     srv  tmp  varboot  dev   home  lib64  media       opt  root  selinux  sys  usr

6.将挂载下的文件拷贝到/data/YUM中;进入下一步

[root@YUM /]# cp -rv /mnt/ /data/YUM[root@YUM /]# cd /data/YUM/[root@YUM YUM]# lsCentOS_BuildTag  isolinux                  RPM-GPG-KEY-CentOS-Debug-6EFI              Packages                  RPM-GPG-KEY-CentOS-Security-6EULA             RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Testing-6GPL              repodata                  TRANS.TBLp_w_picpaths           RPM-GPG-KEY-CentOS-6

7.修改Apache服务的配置文件;进入下一步

[root@YUM ~]# vi /etc/httpd/conf/httpd.conf# ServerName gives the name and port that the server uses to identify itself.# This can often be determined automatically, but we recommend you specify# it explicitly to prevent problems during startup.## If this is not set to valid DNS name for your host, server-generated# redirections will not work.  See also the UseCanonicalName directive.## If your host doesn't have a registered DNS name, enter its IP address here.# You will have to access it by its address anyway, and this will make# redirections work in a sensible way.##ServerName www.example.com:80把ServerName www.example.com:80前的注释去掉即可# DocumentRoot: The directory out of which you will serve your# documents. By default, all requests are taken from this directory, but# symbolic links and aliases may be used to point to other locations.#DocumentRoot "/data"把/var/www/html改成/data即可# This should be changed to whatever you set DocumentRoot to.#
把/var/www/html改成/data即可

8.打开防火墙(iptables)配置文件,加入80端口,进入下一步

[root@YUM ~]# vi /etc/sysconfig/iptables:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]                  在这行下边-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPTCOMMIT                                在这行上边从新起一行添加就行

9.关闭SELinux;进入下一步

[root@YUM ~]# vi /etc/selinux/configSELINUX=disabled将enforcing改成disabled

10.重启Apache服务和iptables防火墙,并且把Apache服务设置成开机启动;进入下一步

[root@YUM ~]# service httpd restartStopping httpd:                                            [  OK  ]Starting httpd:                                            [  OK  ][root@YUM ~]# chkconfig httpd on[root@YUM ~]# service iptables restartiptables: Setting chains to policy ACCEPT: filter          [  OK  ]iptables: Flushing firewall rules:                         [  OK  ]iptables: Unloading modules:                               [  OK  ]iptables: Applying firewall rules:                         [  OK  ]

11.用IE浏览器打开服务器中的YUM源;创建完成。

出现这界面就可以了。。。

附:如果是公司用的YUM服务器,那是一定要禁掉root登陆的,在这里给大家写下来,希望对大家有帮助。。。。

禁掉root登录

[root@YUM ~]# vi /etc/passwdroot:x:0:0:root:/root:/sbin/nologin将/bin/bash改成/sbin/nologin

前提是你必须有个用户,否则的话就不能登陆了。