RPM管理工具(网络YUM)及缓存问题

如果服务端和客户端在同一台机器,是本地YUM 
缺点:只能为本机提供YUM服务                 
如果服务端和客户端不在同一台机器,是网络YUM
优点:
1.可以为网络中的所有客户机提供服务
2.基于FTP的YUM源
3.基于HTTP的YUM源

一、首先准备两台LINUX主机(将11.24作为服务端,11.22作为客户机)

[root@11 ~]# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0C:29:80:FB:49  
          inet addr:172.16.11.24  Bcast:172.16.255.255  Mask:255.255.0.0
       
eth0      Link encap:Ethernet  HWaddr 00:0C:29:90:4E:7F  
          inet addr:172.16.11.22  Bcast:172.16.255.255  Mask:255.255.0.0
         

二、搭建FTP服务器,文件要对外开放共享 (FTP:文件传输协议,几乎所有操作系统都可以搭建FTP)

跟本地YUM区别:服务端(一台主机+共享文件的服务)
1、 安装FTP服务-vsftpd软件包(是根据本地YUM安装的)

[root@111 ~]# yum install vsftpd -y
Loaded plugins: product-id, search-disabled-repos, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
Resolving Dependencies
--> Running transaction check

2、service vsftpd start #启动FTP服务
对外开放的是/var/ftp/目录下的文件(将光盘中的文件复制到仓库中去)

[root@111 ~]# service vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]

root@111 mnt]# cp -r * /var/ftp/yum
[root@111 mnt]# cd /var/ftp/yum
[root@111 yum]# ls
EFI      EULA_en  EULA_it  EULA_pt  HighAvailability  LoadBalancer  README         ResilientStorage            ScalableFileSystem
EULA     EULA_es  EULA_ja  EULA_zh  images            media.repo    release-notes  RPM-GPG-KEY-redhat-beta     Server
EULA_de  EULA_fr  EULA_ko  GPL      isolinux          Packages      repodata       RPM-GPG-KEY-redhat-release  TRANS.TBL

3、打开游览器输入ftp://ip -----要考虑防火墙service iptables stop
RPM管理工具(网络YUM)及缓存问题_第1张图片
RPM管理工具(网络YUM)及缓存问题_第2张图片
三、 客户端(另外主机)
1、 保证能ping通服务端
2、两台Linux发行版本查看 (lsb_release -a),客户端的发行版本要跟服务端共享rpm的版本一样
3、 设置仓库的配置文件
[sxkeji] (可以指向多个服务器,仓库的标签)
name = sxkeji # 源名称 (仓库的描述信息,可以随便填写)
baseurl = ftp://服务器ip/共享目录路径 (指定仓库的路径,本地:file://绝对路径 连网:http://或者ftp?/绝对路径)
enabled = 1 (是否启用这个yum源,1为启用)
gpgcheck = 0 (是否使用gpg检测,0为不使用)

[root@11 yum.repos.d]# cat ftp.repo
[ftpyum]
name=ftp 172.16.11.24
baseurl=ftp://172.16.11.24/yum--------------看游览器所需要的包在那个位置
enabled=1
gpgcheck=0

[root@11 yum.repos.d]# yum clean all
Loaded plugins: product-id, search-disabled-repos, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: ftpyum
Cleaning up Everything

四、验证(在11.22机器上验证,并且下载某个包)

[root@11 yum.repos.d]# yum list
Loaded plugins: product-id, search-disabled-repos, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
ftpyum                                                                                                                                               | 4.1 kB     00:00     
ftpyum/primary_db                                                                                                                                    | 3.1 MB     00:00     
Installed Packages
ConsoleKit.x86_64                                                  0.4.1-6.el6                                       @anaconda-RedHatEnterpriseLinux-201604140956.x86_64/6.8
ConsoleKit-libs.x86_64                                             0.4.1-6.el6                                       @anaconda-RedHatEnterpriseLinux-201604140956.x86_64/6.8
GConf2.x86_64                                                      2.28.0-6.el6                                      @anaconda-RedHatEnterpriseLinux-201604140956.x86_64/6.8
MAKEDEV.x86_64                                                     3.24-6.el6                                        @anaconda-RedHatEnterpriseLinux-201604140956.x86_64/6.8
ORBit2.x86_64                                                      2.14.17-5.el6                                     @anaconda-RedHatEnterpriseLinux-201604140956.x86_64/6.8
[root@11 yum.repos.d]# yum install tree -y
Loaded plugins: product-id, search-disabled-repos, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.5.3-3.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================
 Package                               Arch                                    Version                                        Repository                               Size
============================================================================================================================================================================
Installing:
 tree                                  x86_64                                  1.5.3-3.el6                                    ftpyum (是11.24我们设定的仓库的标签)                                  36 k

Transaction Summary

五、如果需要保留缓存的rpm文件,那么就要修改YUM的主要配置文件/etc/yum.conf,将keepcache设置为1
在步骤四中我们下载了tree软件,去YUM的缓存目录/var/cache/yum目录下查看有没有rpm包缓存

[root@11 yum.repos.d]# cd /var/cache/yum
[root@11 yum]# ls
x86_64
[root@11 yum]# cd x86_64
[root@11 x86_64]# ls
6Server
[root@11 x86_64]# cd 6Server
[root@11 6Server]# ls
ftpyum  yum_local
[root@11 6Server]# cd ftpyum--------------因为我们11.24主机的仓库标签是ftpyum
[root@11 ftpyum]# ls
0fb0ba8a643b701c4677af3a26f308479cd8ee566a225a7b6b7e0abed60b8c21-productid.gz    cachecookie  repomd.xml
abfe02384c880facf7fa7915b74b4ffdc9ab007b4bbadf5dde74dddb13d7d68a-primary.sqlite  packages
[root@11 ftpyum]# cd packages
[root@11 packages]# ls
[root@11 packages]# -----------------表示虽然我们安装了软件包,但是是没有缓存的

通过修改主配置文件,可以缓存我们机器下载的RPM包

1、首先卸载tree软件
[root@11 packages]# yum remove tree -y
[root@11 packages]# rpm -q tree
package tree is not installed
2、修改主配置文件/etc/yum.conf 
[root@11 packages]# vim /etc/yum.conf
keepcache=0------------------------------------将这一项参数改为1
3、重新安装tree,再次查看缓存
[root@11 packages]# yum install tree -y
[root@11 packages]# cd /var/cache/yum/x86_64/6Server/ftpyum
[root@11 ftpyum]# ls
0fb0ba8a643b701c4677af3a26f308479cd8ee566a225a7b6b7e0abed60b8c21-productid.gz    cachecookie  repomd.xml
abfe02384c880facf7fa7915b74b4ffdc9ab007b4bbadf5dde74dddb13d7d68a-primary.sqlite  packages
[root@11 ftpyum]# cd packages
[root@11 packages]# ls
tree-1.5.3-3.el6.x86_64.rpm-------------------------是我们安装的包的缓存

你可能感兴趣的:(LINUX学习)