☞yum源的生成与配置{ local;cdrom;http;ftp;}
本文是继上一篇文章“CentOS程序安装的3种方式{ 源码包安装 | rpm包安装 | yum安装;}”的补充,上篇文章http://www.178linux.com/38812主要介绍了
基于cdrom的yum源
制作和配置以及归纳了详细的yum命令
。本文继续介绍基于本地file
、远程http
、远程ftp
的私人yum仓库的制作与配置,实现了在不同环境下的yum使用与配置。每种方式适用于不同场合,需根据实际情况选择。
本地yum源
【一】安装createrepo
[root@cent7]~>yum install createrepo
【二】进入repo目录,执行createrepo命令创建repodata目录
[root@cent7]/testdir/repodb>createrepo .
[root@cent7]/testdir/repodb>ls repodata/
126a4254b443d131331b4b0690e9c0b6d21a2086439cafc91c06cef05a4d4d80-filelists.sqlite.bz2
13fdc6b363cf52e0a85e9c14a3c7542ff8aa1414059ed3e60e921abe39b608ca-filelists.xml.gz
565784001204f6fb5bc9cc276322d70295eddb1e013d175e232f4efeb6e43d91-primary.sqlite.bz2
5e9a10c873af5ffb1fdd8e91272852c5c9fe2d2bb46e52ca6749b25a0833f3c0-primary.xml.gz
bf7893674c749b8e5bb4688498d02e729c2ab4839cd6e3baeeeaa0c9d8aa24c7-other.xml.gz
de5be08c023c4647355eb21db734c14e07f61ddce7b3802e6a42867e4a46d45f-other.sqlite.bz2
repomd.xml
【三】进入/etc/yum.repo.d/下创建自己的repo文件
[root@cent7]/etc/yum.repos.d>vim myrepo.repo
[local]
name=/testdir/repodb
baseurl=file:///testdir/repodb
gpgcheck=0
enabled=1
【四】查看yum仓库信息
[root@cent7]/etc/yum.repos.d>yum repolist
Loaded plugins: fastestmirror, langpacks
local | 2.9 kB 00:00
local/primary_db | 1.8 kB 00:00
Determining fastest mirrors
repo id repo name status
local /testdir/repodb 1
repolist: 1
【五】使用yum安装tree软件
[root@cent7]/etc/yum.repos.d>yum install tree
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================
Package Arch Version Repository Size
==============================================================================
Installing:
tree x86_64 1.6.0-10.el7 local 46 k
Transaction Summary
==============================================================================
Installed:
tree.x86_64 0:1.6.0-10.el7
Complete!
至此,本地的yum源已经配置好了,我们可以在/testdir/repodb/目录下添加第三方的rpm包,每次添加完成后要执行一次createrepo命令,由此生成rpm包的元数据。创建本地的yum源极大的方便了软件的安装,充分发挥了yum工具的作用,无论是软件的安装、卸载、升级,yum都在/var/log/yum.log中记录了相关信息。
CentOS 6.8基于httpd-2.2.29的yum源
虽然系统自带的仓库已经很常用,只要连接到互联网我们就能很容易有获取到互联网的yum仓库。但是如果是在企业内网,企业内部不允许访问互联网,又或者如果企业服务器众多,如果都要从互联网去获取yum仓库,那将很占用带宽。基于这种情况,我们就需要自己在企业内部创建yum仓库。下图是国内的开源镜像网站,通过配置repo文件即可作为yum源
【一】下载并解压httpd-2.2.29.tar.bz2
[root@cent6~]/home/testdir>tar xf httpd-2.2.29.tar.bz2
[root@cent6~]/home/testdir>cd httpd-2.2.29
【二】安装Development tools
[root@cent6~]yum groupinstall "Development tools"
【三】配置./configure生成makefile文件,主要是指定软件的安装路径与配置文件的路径,可通过./configure –help查看相关说明与帮助
[root@cent6]/home/testdir/httpd-2.2.29>./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd^C
[root@cent6]/home/testdir/httpd-2.2.29>make && make install
【四】安装完成,导入环境变量和lib库目录
[root@cent6]~>vim /etc/profile.d/httpd.sh
PATH=$PATH:/usr/local/httpd/bin
[root@cent6]~>. /etc/profile.d/http.sh #或重新登录
[root@cent6]~>vim /etc/ld.so.conf.d/httpd.conf
/usr/local/httpd/lib
[root@cent6]~>ldconfig
【五】导入头文件到/usr/include,用软链接或者拷贝
[root@cent6]~>ln -sv /usr/local/include/* /usr/include/
`/usr/include/*' -> `/usr/local/include/*'
【六】导入manual手册的路径到man.config
[root@cent6]~>vim /etc/man.config
MANPATH /usr/local/httpd/man
[root@cent6]~>man apachectl
【七】启动apache,如果成功可以看到80端口已经启用
[root@cent6]~>apachectl start
[root@cent6]~>netstat -tan
Active Internet connections (servers and established)
tcp 0 0 :::80 :::* LISTEN
【八】暂时停止iptables,可以通过/sbin/iptables -F清除所有规则来暂时停止防火墙: (警告:这只适合在没有配置防火墙的环境中,如果已经配置过默认规则为deny的环境,此步骤将使系统的所有网络访问中断)
[root@cent6]~>/sbin/iptables -P INPUT ACCEPT
[root@cent6]~>iptables -F
【九】在另一台主机中测试http是否启动,如果正确安装则可以看到如下结果
[root@cent7]/etc>curl 10.1.253.64
<html><body><h1>It works!</h1></body></html>
【十】确保apache服务启动成功的前提下,开始配置基于http的yum源,首先是在httpd的默认文档路径下创建repo仓库,并放置rpm包,再生成repodata文件
[root@cent6]~>mkdir -p /usr/local/httpd/htdocs/centos/7/extras/x86_64/Packages/
cp /misc/cd/Packages/tree-1.5.3-3.el6.x86_64.rpm ./Packages/
[root@cent6]~>createrepo Packages/ -o /usr/local/httpd/htdocs/centos/7/extras/x86_64/
可以看到生成了一个rpm包的元数据:
可以看到在浏览器中已经可以正常访问http的yum文件列表
【十一】在CentOS 7中配置该repo仓库
[root@cent7]~>vim /etc/yum.repos.d/myrepo.repo
1 [base]
2 name=myrepo
3 baseurl=http://10.1.253.64/centos/7/extras/x86_64/
4
5 gpgcheck=1
6 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
7 enabled=1
在CentOS 7上可以看到:
[root@cent7]~>yum list
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
tree.x86_64 1.6.0-10.el7 installed
[root@cent7]/usr/local/httpd/htdocs/centos/7/extras/x86_64>yum install tree
Loaded plugins: fastestmirror, refresh-packagekit, security
==============================================================================
Package Arch Version Repository Size
==============================================================================
Installing:
tree x86_64 1.5.3-3.el6 base 36 k
Transaction Summary
==============================================================================
Installed:
tree.x86_64 0:1.5.3-3.el6
由此,基于http的yum源已经完成了,但是软件包不是一层不变的,如果有新的第三包需要使用yum安装怎么办呢?
此时需要createrepo –update即可,如下:
[root@cent6]~>createrepo /usr/local/httpd/htdocs/centos/7/extras/x86_64/ --update
Spawning worker 0 with 1 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
CentOS 6.8基于ftp的yum源
【一】安装vsftp程序,光盘镜像中有相应的软件包
[root@cent7]/media/cdrom/Packages>rpm -ih vsftpd*
################################# [100%]
Updating / installing...
################################# [100%]
[root@cent6]/misc/cd/Packages>service vsftpd start
Starting vsftpd for vsftpd: [ OK ]
注意: FTP不需要任何配置,默认就是匿名可以访问的。如果修改了/var/ftp的权限会导致本来是匿名访问的忽然要你输入用户名密码,改回 chmod 755 /var/ftp 即可
【二】把光盘镜像copy到ftp的默认路径/var/ftp/pub,并使用createrepo生成rpm包的元数据
[root@cent6]~>mkdir /var/ftp/pub/Packages/
[root@cent6]~>cp /misc/cd/Packages/tree-1.5.3-3.el6.x86_64.rpm /var/ftp/pub/Packages/
[root@cent6]~>createrepo /var/ftp/pub/centos/Packages -o /var/ftp/pub/centos
Spawning worker 0 with 1 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
【三】在CentOS 7上验证ftp服务器是否可用:
[root@cent7]/home>lftp 10.1.253.64
lftp 10.1.253.64:/> dir pub/centos/
drwxr-xr-x 2 0 0 4096 Aug 09 13:46 Packages
drwxr-xr-x 2 0 0 4096 Aug 09 13:56 repodata
【四】配置repo文件,指向该ftp源
[root@cent7]~>vim /etc/yum.repos.d/myrepo.repo
[ftp]
1 name=ftp
2 baseurl=ftp://10.1.253.64/pub/centos/
3 gpgcheck=0
4 enabled=1
[root@cent7]~>yum clean all
[root@cent7]~>yum repolist
Loaded plugins: fastestmirror
repo id repo name status
ftp ftp 1
repolist: 1
【五】使用yum安装软件
[root@cent7]~>yum install tree
Loaded plugins: fastestmirror
==============================================================================
Package Arch Version Repository Size
==============================================================================
Installing:
tree x86_64 1.5.3-3.el6 ftp 36 k
Transaction Summary
==============================================================================
Installed:
tree.x86_64 0:1.5.3-3.el6
Complete!
由此,基于ftp的yum源已经配置完成了,,但是软件包不是一层不变的,如果有新的第三包需要使用yum安装怎么办呢?此时需要createrepo –update即可,如下:
[root@cent6]~>createrepo /var/ftp/pub/centos/Packages/ --update
Spawning worker 0 with 1 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
最后 but not least
原创文章,作者:helloc,如若转载,请注明出处:http://www.178linux.com/39490