实验拓扑:
----------------------------- ----------------------------
|server ip: 192.168.1.100| < -------bridge--------> |client ip: 192.168.1.101|
----------------------------- ----------------------------
思路:
1. [server端]确认安装httpd
rpm -q httpd httpd-2.2.15-29.el6.centos.i686
若没有安装, 进行安装
2. [server端]复制包文件到网页文件目录
cp /media/cdrom/Packages/* /var/www/html/Packages/
这里我在网页文件目录下面建立了一个Packages文件来存放rpm包文件
是从光盘镜像中拷贝来的
3. [server端]创建仓库文件 createrepo /path
createrepo /var/www/html/Packages/ #在该文件建立包文件的源数据文件
这样我们的rmp包服务器就准备完毕了, 下面可以开始下载测试了
4. [client端]修改yum配置文件
打开另一台虚拟机, 当然两台机器首先要联网的, 让我ping一下先
ping 192.168.1.100 PING 192.168.1.100 (192.168.1.100) 56(84) bytes of data. 64 bytes from 192.168.1.100: icmp_seq=1 ttl=64 time=2.57 ms 64 bytes from 192.168.1.100: icmp_seq=2 ttl=64 time=0.396 ms 64 bytes from 192.168.1.100: icmp_seq=3 ttl=64 time=0.400 ms
yum repo配置文件路径:
指定可用的yum仓库 /etc/yum.conf, /etc/yum.repo.d/*.repo
配置文件格式: 有两段组成, 类似windows的ini配置文件
[main] :主配置段
[repo] :仓库配置段
yum repo配置文件的结构:
[reop_ID] #注意repo_ID绝对不能与其他配置文件中的ID重复 name=String #仓库名字 baseurl=http://server/path/to/repo #仓库访问路径, 参见服务器的访问方式: enabled={1|0} #是否启用此仓库, 默认启用 gpgcheck={1|0} #是否检查包来源合法性, 完整性 gpgkey= #gpg检测时公钥文件路径, 可以再本地,可以再服务器上 cost= #定义此仓库的开销, 默认为1000, 越小越优先
OK! ping通了, 开始配置客户机的yum repo配置文件, 把CentOS-Base.repo 中每个仓库都设置为enabled=0,这样我们就不使用默认的仓库, 如果 [base] 等 下面没有enabled项目我们手动添加enabled=0即可
vim /etc/yum.repos.d/CentOS-Base.repo # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [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 enabled=0 #注意这里设置为0, 不使用的意思 #released updates [updates] name=CentOS-$releasever - Updates mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 enabled=0 #注意这里设置为0, 不使用的意思 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 enabled=0 #注意这里设置为0, 不使用的意思 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 #注意这里设置为0, 不使用的意思 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib #baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/ gpgcheck=1 enabled=0 #注意这里设置为0, 不使用的意思 gpgkey= :wq #保存后推出 vim /etc/yum.repos.d/Httpd-test-Base.repo #我们来配置一个自己的repo配置文件,如下: [httpd-192.168.1.100] name=test enabled=1 baseurl=http://192.168.1.100/Packages/ gpgcheck=0 :wq #保存并且退出 yum repolist #看一下yum的repo列表, 如果跟下面输出结果差不多,只要一个repo, 就设置好了 Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile repo id repo name status httpd-192.168.1.100 test 2,695 repolist: 2,695
5. [client端]安装测试
yum install httpd Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package httpd.i686 0:2.2.15-29.el6.centos will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================== Package Arch Version Repository ==================================================================== Installing: httpd i686 2.2.15-29.el6.centos httpd-192.1 Transaction Summary ==================================================================== Install 1 Package(s) Total download size: 828 k Installed size: 2.8 M Is this ok [y/N]: ^CExiting on user Command [root@apache yum.repos.d]# yum install httpd Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package httpd.i686 0:2.2.15-29.el6.centos will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================== Package Arch Version Repository Size ==================================================================== Installing: httpd i686 2.2.15-29.el6.centos httpd-192.168.1.100 828 k Transaction Summary ==================================================================== Install 1 Package(s) Total download size: 828 k Installed size: 2.8 M Is this ok [y/N]: y Downloading Packages: httpd-2.2.15-29.el6.centos.i686.rpm | 828 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Warning: RPMDB altered outside of yum. Installing : httpd-2.2.15-29.el6.centos.i686 1/1 Verifying : httpd-2.2.15-29.el6.centos.i686 1/1 Installed: httpd.i686 0:2.2.15-29.el6.centos Complete!
大功告成辛苦啦