如何实现本地yum源的共享

上一篇关于Linux yum客户端的配置的博客,介绍了如何通过修改本机yum配置文件来访问网络或者本地的yun sever, 本文就来介绍一下,如何把我们的本地RPM包像yum sever一样通过http或ftp网络方式共享出去。

一、准备好发行版光盘,包,元数据
    CentOS-6.8-x86_64-bin-DVD1.iso
二、准备网络服务http(s);ftp
根据netstat -ntl命令执行结果可以看出,80(http),21(ftp)端口都没有显示, 服务还没有配置

[root@centos6 ~]#netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:44496               0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      
tcp        0      0 :::111                      :::*                        LISTEN      
tcp        0      0 :::55028                    :::*                        LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:631                     :::*                        LISTEN      
tcp        0      0 ::1:25                      :::*                        LISTEN      

1)配置ftp服务
1.安装vsftpd包

[root@centos6 ~]#yum -y -q install vsftpd         <-- 利用配置过的yum仓库
[root@centos6 ~]#rpm -ql vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/rc.d/init.d/vsftpd                           <-- 服务名称
....中间省略....
/usr/share/man/man8/vsftpd.8.gz
/var/ftp
/var/ftp/pub                                      <-- 共享文件存放路径

2.启动ftp服务
以下两种方法均可

[root@centos6 ~]#/etc/rc.d/init.d/vsftpd start    <-- 路径名
Starting vsftpd for vsftpd:                                [  OK  ]
[root@centos6 ~]#service vsftpd start             <-- service指令
Starting vsftpd for vsftpd:                                [  OK  ]

3.设置开机自启动

[root@centos6 ~]#chkconfig vsftpd on

2)配置http服务
1.安装httpd包

[root@centos6 ~]#yum -y install httpd             <-- 利用配置过的yum仓库
[root@centos6 ~]#rpm -ql httpd
/etc/httpd
....中间省略....
/etc/rc.d/init.d/htcacheclean
/etc/rc.d/init.d/httpd                            <-- 服务名称
....中间省略....
/var/www/html                                     <-- 共享文件存放路径
....后面省略....

2.启动http服务

[root@centos6 ~]#cd /etc/httpd/conf.d/
[root@centos6 conf.d]#mv welcome.conf welcome.conf.bak    <-- 重命名welcome.conf文件,否则通过http访问不到/var/www/html共享文件夹
[root@centos6 ~]#/etc/rc.d/init.d/httpd start             <-- 路径名
Starting httpd:                                            [  OK  ]
[root@centos6 ~]#service httpd start                      <-- service指令
Starting httpd:                                            [  OK  ]

3.设置开机自启动

[root@centos6 ~]#chkconfig httpd on

三、关闭防火墙服务

[root@centos6 ~]#service iptables stop             <-- 关闭服务
[root@centos6 ~]#chkconfig iptables off            <-- 禁止开机启动

四、拷贝目标文件到共享目录
1.ftp服务的共享目录是/var/ftp/pub

[root@centos6 /]#cd /var/ftp/pub
[root@centos6 6]#mkdir 6                           <-- 创建以版本号命名的文件夹
[root@centos6 6]#cp -r /misc/cd/Packages           <-- 从光盘拷贝包文件
[root@centos6 6]#cp -r /misc/cd/repodata           <-- 从光盘拷贝元数据
[root@centos6 6]#ls
Packages  repodata

通过浏览器访问ftp://192.168.196.132,已经可以访问共享文件了            <– 本机IP192.168.196.132

如何实现本地yum源的共享

2.同样方法可以把rpm包拷贝到http服务的共享目录下/var/www/html
还有另外一种方法就是把目录/var/ftp/pub挂载到目录/var/www/html,这样通过http访问/var/www/html相当于访问/var/ftp/pub,我们就省去了重复复制的操作

[root@centos6 ~]#mount /var/ftp/pub /var/www/html -B

通过浏览器访问http://192.168.196.132,已经可以访问共享文件了

如何实现本地yum源的共享

五、yum客户端的配置
1.修改yum配置文件

[root@centos6 ~]#vi /etc/yum.repos.d/centos.repo 
[ftpbase]
name=ftp yum base
baseurl=ftp://192.168.196.132/pub/$releasever     
gpgcheck=0
enabled=1

[httpbase]
name=http yum base
baseurl=http://192.168.196.132/$releasever
gpgcheck=0
enabled=1

2.清理缓存

[root@centos6 ~]#yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: ftpbase httpbase
Cleaning up Everything
Cleaning up list of fastest mirrors

3.创建缓存

[root@centos6 ~]#yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
ftpbase                                                                                        | 4.0 kB     00:00     
ftpbase/group_gz                                                                               | 226 kB     00:00     
ftpbase/filelists_db                                                                           | 6.3 MB     00:00     
ftpbase/primary_db                                                                             | 4.7 MB     00:00     
ftpbase/other_db                                                                               | 2.8 MB     00:00     
httpbase                                                                                       | 4.0 kB     00:00     
httpbase/group_gz                                                                              | 226 kB     00:00     
httpbase/filelists_db                                                                          | 6.3 MB     00:00     
httpbase/primary_db                                                                            | 4.7 MB     00:00     
httpbase/other_db                                                                              | 2.8 MB     00:00     
Metadata Cache Created

4.列出yum仓库

[root@centos6 ~]#yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
repo id                                                     repo name                                status
ftpbase                                                     ftp yum base                             6,696
httpbase                                                    http yum base 6,696
repolist: 13,392

结果可以看出,网络yum源已经创建成功,可以通过http或者ftp服务访问了

六、第三方的软件仓库的配置
上面是以发行版光盘为rpm包的来源,提供了元数据repodata,假如我们想要分享第三方的软件,就必须使用createrepo命令来生成所需的repodata

[root@centos6 6]#cd /var/ftp/pub/6     <--cd到Package所在目录
[root@centos6 6]#mv repodata /root/    <--移走已有repodata 
[root@centos6 6]#createrepo ./         <--创建元数据
Spawning worker 0 with 3206 pkgs       <--rpm包数小于6696是由于我们只拷贝一张光盘上的rpm包
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@centos6 6]#ls
Packages  repodata

来测试一下yum源

[root@centos6 6]#yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: ftpbase httpbase
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@centos6 6]#yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
ftpbase                                                                                     | 2.9 kB     00:00     
ftpbase/filelists_db                                                                        | 3.3 MB     00:00     
ftpbase/primary_db                                                                          | 2.5 MB     00:00     
ftpbase/other_db                                                                            | 1.4 MB     00:00     
httpbase                                                                                    | 2.9 kB     00:00     
httpbase/filelists_db                                                                       | 3.3 MB     00:00     
httpbase/primary_db                                                                         | 2.5 MB     00:00     
httpbase/other_db                                                                           | 1.4 MB     00:00     
Metadata Cache Created
[root@centos6 6]#yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
repo id                                                     repo name                           status
ftpbase                                                     ftp yum base                        3,206
httpbase                                                    http yum base 3,206
repolist: 6,412

yum源配置成,而且手动生成的repodata能正确反映rpm包的实际数目了!

原创文章,作者:ffu,如若转载,请注明出处:http://www.178linux.com/78133

(3)
ffuffu
上一篇 2017-06-17 15:30
下一篇 2017-06-17 16:54

相关推荐

  • 用户和组——Linux基本命令(10)

    1.     用户和组的配置文件 Linux用户和组的主要配置文件: /etc/passwd:用户及其属性信息(名称、UID、主组ID等) /etc/group:组及其属性信息 /etc/shadow:用户密码及其相关属性 /etc/gshadow:组密码及其相关属性   2. /etc/passwd 在Li…

    2017-07-22
  • shell中的位置参数变量

    要了解位置变量,首先要知道什么是变量?  变量就是让某一个特定的字符串来代表不固定的内容,简单理解就是用一个简单的“字眼”来替代另一个比较复杂或者容易变动的数据。 而什么又是位置变量呢?  位置变量就是bash将传递给脚本的参数,按照位置不同,保存在不同的位置变量中,以便于脚本调用这些变量。 位置参数变量: $1, $2, ……

    Linux干货 2016-08-12
  • 文件通配符练习

    课后资料补充 * : 通配符,代表任意字符(0到多个)? : 通配符,代表一个字符# : 注释/ : 跳转符号,将特殊字符或通配符还原成一般符号| : 分隔两个管线命令的界定; : 连续性命令的界定~ : 用户的根目录$ : 变量前需要加的变量值! : 逻辑运算中的&q…

    Linux干货 2016-08-08
  • 详解LVM逻辑卷

       LVM逻辑卷管理 当os6中partprobe 命令不能同步分区完的分区信息,及用ll /dev/sd*、cat /proc/partation、lsblk看的设备分区内容和用fdisk -l 看到的信息不同步 所以用partx -a 设备名或者用partx -a –nr 分区号 设备名 其中表示n是设备名,r 是ran…

    Linux干货 2016-08-29
  • 常见HTTP code大全

    1xx(临时响应)表示临时响应并需要请求者继续执行操作的状态代码。 代码 说明 100 (继续) 请求者应当继续提出请求。服务器返回此代码表示已收到请求的第一部分,正在等待其余部分。  101 (切换协议) 请求者已要求服务器切换协议,服务器已确认并准备切换。 2xx (成功)表示成功处理了请求的状…

    Linux干货 2016-09-19
  • 马哥教育网络班22期+第12周作业

    week11 1、请描述一次完整的http请求处理过程; 2、httpd所支持的处理模型有哪些,他们的分别使用于哪些环境。 3、源码编译安装LAMP环境(基于wordpress程序),并写出详细的安装、配置、测试过程。 4、建立httpd服务器(基于编译的方式进行),要求:      提供两个基于名称的虚拟主…

    Linux干货 2016-10-31