有时候可能会因为工作需要,会在本地创建yum源以方便安装有复杂依赖关系的软件安装包,或是为了方便局域网内其他服务器安装更新程序
一、安装createrepo
1.由于创建yum需要createrepo程序,所以创建之前可以检测本机上是否已经安装了createrepo程序
# rpm -q createrepo
2.如果没有安装可自行下载安装,安装createrepo需要以下三个程序包
createrepo
deltarpm
python-deltarpm
3.也可以通过创建国内yum源,来安装createrepo,可以轻松的解决其之间的依赖关系
[root@linux updates]# yum install createrepo Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package createrepo.noarch 0:0.9.9-22.el6 will be installed --> Processing Dependency: python-deltarpm for package: createrepo-0.9.9-22.el6.noarch --> Running transaction check ---> Package python-deltarpm.x86_64 0:3.5-0.5.20090913git.el6 will be installed --> Processing Dependency: deltarpm = 3.5-0.5.20090913git.el6 for package: python-deltarpm-3.5-0.5.20090913git.el6.x86_64 --> Running transaction check ---> Package deltarpm.x86_64 0:3.5-0.5.20090913git.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================== Package Arch Version Repository Size ==================================================================================================================== Installing: createrepo noarch 0.9.9-22.el6 163-OS 96 k Installing for dependencies: deltarpm x86_64 3.5-0.5.20090913git.el6 163-OS 71 k python-deltarpm x86_64 3.5-0.5.20090913git.el6 163-OS 27 k Transaction Summary ==================================================================================================================== Install 3 Package(s) Total download size: 194 k Installed size: 520 k Is this ok [y/N]: y Downloading Packages: (1/3): createrepo-0.9.9-22.el6.noarch.rpm | 96 kB 00:07 (2/3): deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm | 71 kB 00:04 (3/3): python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm | 27 kB 00:01 -------------------------------------------------------------------------------------------------------------------- Total 12 kB/s | 194 kB 00:16 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : deltarpm-3.5-0.5.20090913git.el6.x86_64 1/3 Installing : python-deltarpm-3.5-0.5.20090913git.el6.x86_64 2/3 Installing : createrepo-0.9.9-22.el6.noarch 3/3 Verifying : python-deltarpm-3.5-0.5.20090913git.el6.x86_64 1/3 Verifying : createrepo-0.9.9-22.el6.noarch 2/3 Verifying : deltarpm-3.5-0.5.20090913git.el6.x86_64 3/3 Installed: createrepo.noarch 0:0.9.9-22.el6 Dependency Installed: deltarpm.x86_64 0:3.5-0.5.20090913git.el6 python-deltarpm.x86_64 0:3.5-0.5.20090913git.el6 Complete! [root@linux updates]#
二、创建本地yum源
1、将安装光盘包中的httpd*程序复制到/tmp/httpd目录下
#mkdir /tmp/httpd
# mount /dev/sr0 /mnt/cd
# cp mnt/cd/Packages/httpd* /tmp/httpd
# cd /tmp/httpd
2、使用createrepo创建yum源
[root@linux httpd]# createrepo /tmp/httpd/ //创建yum源 Spawning worker 0 with 5 pkgs Workers Finished Gathering worker results Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete //创建完成 [root@linux httpd]# ls httpd-2.2.15-39.el6.centos.x86_64.rpm httpd-manual-2.2.15-39.el6.centos.noarch.rpm httpd-devel-2.2.15-39.el6.centos.i686.rpm httpd-tools-2.2.15-39.el6.centos.x86_64.rpm httpd-devel-2.2.15-39.el6.centos.x86_64.rpm repodata
注:创建完成后会在其目录下生产一个repodata文件夹
[root@linux repodata]# ls 2739576ea0b7fc7093c70c8a99fda0bbd55139adf14046c6f6c0f132948cced9-other.xml.gz 6ae304f284396ef2c9c45281b66f24aaa721281b4af80f07505996cfb6277b19-filelists.sqlite.bz2 afe26ec861be2ac48498fc7416b762991a29244494c37040eb1e7b2b1ae95c77-primary.sqlite.bz2 c4886b02cca505fb78991113b2517cabfa674393c7f973699e87fcf6a5342b1e-filelists.xml.gz cb9b6fc78f755fd87f461beb816145912555657db3f8455df700332c0fb31686-primary.xml.gz e6e56919253a8059bac51e7178dadd98b26de2272abb743026be5ba60ef42b4a-other.sqlite.bz2 repomd.xml
3、在/etc/yum.repo.d/目录下创建repo文件
# vim /etc/yum.repos.d/local.repo [local-httpd] name=Local httpd baseurl=file:///tmp/httpd/ //注意此处本地是三个“/” gpgcheck=0 enable=1
4、验证是否创建成功
清除本机yum源缓存
[root@linux repodata]# yum clean all Cleaning repos: local-httpd Cleaning up Everything [root@linux repodata]# rm -rf /var/cache/yum/*
查看本例yum源列表
[root@linux repodata]# yum repolist repo id repo name status local-httpd Local httpd 5 repolist: 5 [root@linux repodata]# yum list available Available Packages httpd-devel.i686 2.2.15-39.el6.centos local-httpd httpd-devel.x86_64 2.2.15-39.el6.centos local-httpd httpd-manual.noarch 2.2.15-39.el6.centos local-httpd [root@linux repodata]#
根据已经创建的本地yum源安装httpd程序
[root@linux httpd]# yum install httpd Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.2.15-39.el6.centos will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================== Package Arch Version Repository Size ==================================================================================================================== Installing: httpd x86_64 2.2.15-39.el6.centos local-httpd 825 k Transaction Summary ==================================================================================================================== Install 1 Package(s) Total download size: 825 k Installed size: 2.9 M Is this ok [y/N]: y Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : httpd-2.2.15-39.el6.centos.x86_64 1/1 Verifying : httpd-2.2.15-39.el6.centos.x86_64 1/1 Installed: httpd.x86_64 0:2.2.15-39.el6.centos Complete! [root@linux httpd]#
5.启动httpd
[root@linux repodata]# service httpd restart Stopping httpd: [FAILED] Starting httpd: httpd: apr_sockaddr_info_get() failed for linux httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName [ OK ] [root@linux repodata]#
6、为了能够让局域网内其他机器能够访问到此WEB,同时还需要关闭iptables服务:
# service iptables stop //如果不关闭其他机器可能无法访问此WEB
三、根据已经安装的http创建http yum源
1、复制光盘中的mysql安装包到httpd目录下
[root@linux html]# cp /mnt/cd/Packages/mysql-5.1.73-3.el6_5.x86_64.rpm /var/httpd/html/ [root@linux html]# lsindex.html.bak mysql-5.1.73-3.el6_5.x86_64.rpm
2、创建yum源
[root@linux html]# createrepo /var/www/html/ 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 [root@linux html]# ls index.html.bak mysql-5.1.73-3.el6_5.x86_64.rpm repodata
3、创建repo文件
上述工作一切就绪后,就可以在局域网内其他机器上编辑repo文件了
# vim /etc/yum.repos.d/mysql.repo
[Mysql] name=httpd--Mysql--install baseurl=http://192.168.67.131/ gpgcheck=0 enable=1
4、清除yum缓存并查看列表
[root@linux html]# yum clean all Cleaning repos: Mysql local-httpd Cleaning up Everything [root@linux html]# rm -rf /var/cache/yum/* [root@linux html]# yum repolist Mysql | 2.9 kB 00:00 Mysql/primary_db | 3.3 kB 00:00 local-httpd | 2.9 kB 00:00 ... local-httpd/primary_db | 7.2 kB 00:00 ... repo id repo name status Mysql httpd--Mysql--install 1 local-httpd Local httpd 5 repolist: 6 [root@linux html]#
5、查看可安装但为安装的yum源内的程序
[root@linux html]# yum list available Available Packages httpd-devel.i686 2.2.15-39.el6.centos local-httpd httpd-devel.x86_64 2.2.15-39.el6.centos local-httpd httpd-manual.noarch 2.2.15-39.el6.centos local-httpd mysql.x86_64 5.1.73-3.el6_5 Mysql [root@linux html]#
6、使用yum安装mysql
[root@linux html]# yum install mysql Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package mysql.x86_64 0:5.1.73-3.el6_5 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================== Package Arch Version Repository Size ==================================================================================================================== Installing: mysql x86_64 5.1.73-3.el6_5 Mysql 894 k Transaction Summary ==================================================================================================================== Install 1 Package(s) Total download size: 894 k Installed size: 2.4 M Is this ok [y/N]: y Downloading Packages: mysql-5.1.73-3.el6_5.x86_64.rpm | 894 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : mysql-5.1.73-3.el6_5.x86_64 1/1 Verifying : mysql-5.1.73-3.el6_5.x86_64 1/1 Installed: mysql.x86_64 0:5.1.73-3.el6_5 Complete! [root@linux html]#
OK 通过创建的http YUM源已经成功创建完成
如果不足之处还请各位斧正..........
本文出自 “无常” 博客,请务必保留此出处http://1inux.blog.51cto.com/10037358/1635565
原文:http://1inux.blog.51cto.com/10037358/1635565