有時候可能會因為工作需要,會在本地建立yum源以友善安裝有複雜依賴關系的軟體安裝包,或是為了友善區域網路内其他伺服器安裝更新程式
一、安裝createrepo
1.由于建立yum需要createrepo程式,是以建立之前可以檢測本機上是否已經安裝了createrepo程式
# rpm -q createrepo
2.如果沒有安裝可自行下載下傳安裝,安裝createrepo需要以下三個程式包
createrepo
deltarpm
python-deltarpm
3.也可以通過建立國内yum源,來安裝createrepo,可以輕松的解決其之間的依賴關系
<code>[root@linux updates]# yum install createrepo</code>
<code>Setting up Install Process</code>
<code>Resolving Dependencies</code>
<code>--> Running transaction check</code>
<code>---> Package createrepo.noarch 0:0.9.9-22.el6 will be installed</code>
<code>--> Processing Dependency: python-deltarpm </code><code>for</code> <code>package: createrepo-0.9.9-22.el6.noarch</code>
<code>---> Package python-deltarpm.x86_64 0:3.5-0.5.20090913git.el6 will be installed</code>
<code>--> Processing Dependency: deltarpm = 3.5-0.5.20090913git.el6 </code><code>for</code> <code>package: python-deltarpm-3.5-0.5.20090913git.el6.x86_64</code>
<code>---> Package deltarpm.x86_64 0:3.5-0.5.20090913git.el6 will be installed</code>
<code>--> Finished Dependency Resolution</code>
<code>Dependencies Resolved</code>
<code>====================================================================================================================</code>
<code> </code><code>Package Arch Version Repository Size</code>
<code>Installing:</code>
<code> </code><code>createrepo noarch 0.9.9-22.el6 163-OS 96 k</code>
<code>Installing </code><code>for</code> <code>dependencies:</code>
<code> </code><code>deltarpm x86_64 3.5-0.5.20090913git.el6 163-OS 71 k</code>
<code> </code><code>python-deltarpm x86_64 3.5-0.5.20090913git.el6 163-OS 27 k</code>
<code>Transaction Summary</code>
<code>Install 3 Package(s)</code>
<code>Total download size: 194 k</code>
<code>Installed size: 520 k</code>
<code>Is this ok [y/N]: y</code>
<code>Downloading Packages:</code>
<code>(1/3): createrepo-0.9.9-22.el6.noarch.rpm | 96 kB 00:07 </code>
<code>(2/3): deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm | 71 kB 00:04 </code>
<code>(3/3): python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm | 27 kB 00:01 </code>
<code>--------------------------------------------------------------------------------------------------------------------</code>
<code>Total 12 kB/s | 194 kB 00:16 </code>
<code>Running rpm_check_debug</code>
<code>Running Transaction Test</code>
<code>Transaction Test Succeeded</code>
<code>Running Transaction</code>
<code> </code><code>Installing : deltarpm-3.5-0.5.20090913git.el6.x86_64 1/3 </code>
<code> </code><code>Installing : python-deltarpm-3.5-0.5.20090913git.el6.x86_64 2/3 </code>
<code> </code><code>Installing : createrepo-0.9.9-22.el6.noarch 3/3 </code>
<code> </code><code>Verifying : python-deltarpm-3.5-0.5.20090913git.el6.x86_64 1/3 </code>
<code> </code><code>Verifying : createrepo-0.9.9-22.el6.noarch 2/3 </code>
<code> </code><code>Verifying : deltarpm-3.5-0.5.20090913git.el6.x86_64 3/3 </code>
<code>Installed:</code>
<code> </code><code>createrepo.noarch 0:0.9.9-22.el6 </code>
<code>Dependency Installed:</code>
<code> </code><code>deltarpm.x86_64 0:3.5-0.5.20090913git.el6 python-deltarpm.x86_64 0:3.5-0.5.20090913git.el6 </code>
<code>Complete!</code>
<code>[root@linux updates]#</code>
二、建立本地yum源
1、将安裝CD光牒包中的httpd*程式複制到/tmp/httpd目錄下
#mkdir /tmp/httpd
# mount /dev/sr0 /mnt/cd
# cp mnt/cd/Packages/httpd* /tmp/httpd
# cd /tmp/httpd
2、使用createrepo建立yum源
<code>[root@linux httpd]# createrepo /tmp/httpd/ </code><code>//建立yum源</code>
<code>Spawning worker 0 with 5 pkgs</code>
<code>Workers Finished</code>
<code>Gathering worker results</code>
<code>Saving Primary metadata</code>
<code>Saving file lists metadata</code>
<code>Saving other metadata</code>
<code>Generating sqlite DBs</code>
<code>Sqlite DBs complete </code><code>//建立完成</code>
<code>[root@linux httpd]# ls</code>
<code>httpd-2.2.15-39.el6.centos.x86_64.rpm httpd-manual-2.2.15-39.el6.centos.noarch.rpm</code>
<code>httpd-devel-2.2.15-39.el6.centos.i686.rpm httpd-tools-2.2.15-39.el6.centos.x86_64.rpm</code>
<code>httpd-devel-2.2.15-39.el6.centos.x86_64.rpm repodata</code>
注:建立完成後會在其目錄下生産一個repodata檔案夾
<code>[root@linux repodata]# ls</code>
<code>2739576ea0b7fc7093c70c8a99fda0bbd55139adf14046c6f6c0f132948cced9-other.xml.gz</code>
<code>6ae304f284396ef2c9c45281b66f24aaa721281b4af80f07505996cfb6277b19-filelists.sqlite.bz2</code>
<code>afe26ec861be2ac48498fc7416b762991a29244494c37040eb1e7b2b1ae95c77-primary.sqlite.bz2</code>
<code>c4886b02cca505fb78991113b2517cabfa674393c7f973699e87fcf6a5342b1e-filelists.xml.gz</code>
<code>cb9b6fc78f755fd87f461beb816145912555657db3f8455df700332c0fb31686-primary.xml.gz</code>
<code>e6e56919253a8059bac51e7178dadd98b26de2272abb743026be5ba60ef42b4a-other.sqlite.bz2</code>
<code>repomd.xml</code>
3、在/etc/yum.repo.d/目錄下建立repo檔案
<code># vim /etc/yum.repos.d/local.repo </code>
<code>[local-httpd]</code>
<code>name=Local httpd</code>
<code>baseurl=file:</code><code>///tmp/httpd/ //注意此處本地是三個“/”</code>
<code>gpgcheck=0</code>
<code>enable=1</code>
4、驗證是否建立成功
清除本機yum源緩存
<code>[root</code><code>@linux</code> <code>repodata]</code><code># yum clean all</code>
<code>Cleaning repos: </code><code>local</code><code>-httpd</code>
<code>Cleaning up Everything</code>
<code>[root</code><code>@linux</code> <code>repodata]</code><code># rm -rf /var/cache/yum/*</code>
檢視本例yum源清單
<code>[root@linux repodata]# yum repolist</code>
<code>repo id repo name status</code>
<code>local-httpd Local httpd 5</code>
<code>repolist: 5</code>
<code>[root@linux repodata]# yum list available</code>
<code>Available Packages</code>
<code>httpd-devel.i686 2.2.15-39.el6.centos local-httpd</code>
<code>httpd-devel.x86_64 2.2.15-39.el6.centos local-httpd</code>
<code>httpd-manual.noarch 2.2.15-39.el6.centos local-httpd</code>
<code>[root@linux repodata]#</code>
根據已經建立的本地yum源安裝httpd程式
<code>[root@linux httpd]# yum install httpd</code>
<code>---> Package httpd.x86_64 </code><code>0</code><code>:</code><code>2.2.</code><code>15</code><code>-39.</code><code>el6.centos will be installed</code>
<code> </code><code>Package Arch Version Repository Size</code>
<code> </code><code>httpd x86_64 </code><code>2.2.</code><code>15</code><code>-39.</code><code>el6.centos local-httpd </code><code>825</code> <code>k</code>
<code>Install </code><code>1</code> <code>Package(s)</code>
<code>Total download size: </code><code>825</code> <code>k</code>
<code>Installed size: </code><code>2.9</code> <code>M</code>
<code>Is </code><code>this</code> <code>ok [y/N]: y</code>
<code> </code><code>Installing : httpd</code><code>-2.2.</code><code>15</code><code>-39.</code><code>el6.centos.x86_64 </code><code>1</code><code>/</code><code>1</code>
<code> </code><code>Verifying : httpd</code><code>-2.2.</code><code>15</code><code>-39.</code><code>el6.centos.x86_64 </code><code>1</code><code>/</code><code>1</code>
<code> </code><code>httpd.x86_64 </code><code>0</code><code>:</code><code>2.2.</code><code>15</code><code>-39.</code><code>el6.centos </code>
<code>[root@linux httpd]#</code>
5.啟動httpd
<code>[root@linux repodata]# service httpd restart</code>
<code>Stopping httpd: [FAILED]</code>
<code>Starting httpd: httpd: apr_sockaddr_info_get() failed </code><code>for</code> <code>linux</code>
<code>httpd: Could </code><code>not</code> <code>reliably determine the server's fully qualified domain name, using </code><code>127.0.</code><code>0.1</code> <code>for</code> <code>ServerName</code>
<code> </code><code>[ OK ]</code>
6、為了能夠讓區域網路内其他機器能夠通路到此WEB,同時還需要關閉iptables服務:
# service iptables stop //如果不關閉其他機器可能無法通路此WEB
三、根據已經安裝的http建立http yum源
1、複制CD光牒中的mysql安裝包到httpd目錄下
<code>[root</code><code>@linux</code> <code>html]</code><code># cp /mnt/cd/Packages/mysql-5.1.73-3.el6_5.x86_64.rpm /var/httpd/html/</code>
<code>[root</code><code>@linux</code> <code>html]</code><code># lsindex.html.bak mysql-5.1.73-3.el6_5.x86_64.rpm</code>
2、建立yum源
<code>[root@linux html]# createrepo /</code><code>var</code><code>/www/html/</code>
<code>Spawning worker 0 with 1 pkgs</code>
<code>Sqlite DBs complete</code>
<code>[root@linux html]# ls</code>
<code>index.html.bak mysql-5.1.73-3.el6_5.x86_64.rpm repodata</code>
3、建立repo檔案
上述工作一切就緒後,就可以在區域網路内其他機器上編輯repo檔案了
# vim /etc/yum.repos.d/mysql.repo
<code>[Mysql]</code>
<code>name=httpd--Mysql--install</code>
<code>baseurl=http:</code><code>//192.168.67.131/</code>
4、清除yum緩存并檢視清單
<code>[root@linux html]# yum clean all</code>
<code>Cleaning repos: Mysql local-httpd</code>
<code>[root@linux html]# rm -rf /</code><code>var</code><code>/cache/yum/*</code>
<code>[root@linux html]# yum repolist</code>
<code>Mysql | 2.9 kB 00:00 </code>
<code>Mysql/primary_db | 3.3 kB 00:00 </code>
<code>local-httpd | 2.9 kB 00:00 ... </code>
<code>local-httpd/primary_db | 7.2 kB 00:00 ... </code>
<code>repo id repo name status</code>
<code>Mysql httpd--Mysql--install 1</code>
<code>local-httpd Local httpd 5</code>
<code>repolist: 6</code>
<code>[root@linux html]#</code>
5、檢視可安裝但為安裝的yum源内的程式
<code>[root@linux html]# yum list available</code>
<code>mysql.x86_64 5.1.73-3.el6_5 Mysql </code>
6、使用yum安裝mysql
<code>[root@linux html]# yum install mysql</code>
<code>---> Package mysql.x86_64 0:5.1.73-3.el6_5 will be installed</code>
<code> </code><code>Package Arch Version Repository Size</code>
<code> </code><code>mysql x86_64 5.1.73-3.el6_5 Mysql 894 k</code>
<code>Install 1 Package(s)</code>
<code>Total download size: 894 k</code>
<code>Installed size: 2.4 M</code>
<code>mysql-5.1.73-3.el6_5.x86_64.rpm | 894 kB 00:00 </code>
<code> </code><code>Installing : mysql-5.1.73-3.el6_5.x86_64 1/1 </code>
<code> </code><code>Verifying : mysql-5.1.73-3.el6_5.x86_64 1/1 </code>
<code> </code><code>mysql.x86_64 0:5.1.73-3.el6_5 </code>
OK 通過建立的http YUM源已經成功建立完成
如果不足之處還請各位斧正..........
本文轉自 1inux 51CTO部落格,原文連結:http://blog.51cto.com/1inux/1635565