在工做中, 公司的服務器大部分都禁止鏈接外網的,初始化系統,測試某些產品時,每每缺一些軟件或依賴包,一個個上傳到機器,如此浪費時間,浪費金錢,en...yum可以自動查找並解決rpm包之間的依賴關係,須要有一個包含各類rpm軟件包的repository(軟件倉庫),提供軟件倉庫的服務器習慣上成爲「源」服務器,網絡上有大量的源服務器,可是,因爲受到網絡鏈接速度、帶寬的限制,致使軟件安裝耗時過長甚至失敗,特別是當有大量服務器大量軟件包須要升級時,更新的緩慢程序使人難以忍受,相比較而言,本地YUM源服務器最大優勢在局域網的快速網絡鏈接和穩定性,有了局域網中的yum源服務器,即使在網絡鏈接中斷的狀況下,也不會影響軟件升級和安裝。html
一、下載yum源的DVD鏡像,鏡像名以下:python
CentOS-6.5-x86_64-bin-DVD1linux
二、將其宿主機的鏡像掛載到linux中去:nginx
三、安裝VMware Toolsc++
[root@Web-A ~]# ll /media/VMware/Tools/ 總用量 60712 -rw-r--r-- 1 root root 62163222 8月 3 22:00 VMwareTools-9.9.4-3193940.tar.gz [root@Web-A ~]# cd /media/VMware/Tools/ [root@Web-A Tools]# tar xf VMwareTools-9.9.4-3193940.tar.gz [root@Web-A Tools]# ll 總用量 60716 -rw-r--r-- 1 root root 62163222 8月 3 22:00 VMwareTools-9.9.4-3193940.tar.gz drwxr-xr-x 7 root root 4096 10月 30 2015 vmware-tools-distrib [root@Web-A Tools]# cd vmware-tools-distrib/ [root@Web-A vmware-tools-distrib]# ls bin doc etc FILES INSTALL installer lib vmware-install.pl [root@Web-A vmware-tools-distrib]# ./vmware-install.pl #安裝VMware,一路回車+yes Creating a new VMware Tools installer database using the tar4 format. Installing VMware Tools. In which directory do you want to install the binary files? [/usr/bin] What is the directory that contains the init directories (rc0.d/ to rc6.d/)? [/etc/rc.d] What is the directory that contains the init scripts? [/etc/rc.d/init.d] In which directory do you want to install the daemon files? [/usr/sbin] In which directory do you want to install the library files? [/usr/lib/vmware-tools] The path "/usr/lib/vmware-tools" does not exist currently. This program is going to create it, including needed parent directories. Is this what you want? [yes] yes ......此處省略 To enable advanced X features (e.g., guest resolution fit, drag and drop, and file and text copy/paste), you will need to do one (or more) of the following: 1. Manually start /usr/bin/vmware-user 2. Log out and log back into your desktop session; and, 3. Restart your X session. Enjoy, #出現這個表示安裝成功。 --the VMware team
四、接下來咱們在//mnt/hgfs下看是否有共享的文件:git
[root@Web-A vmware-tools-distrib]# ll /mnt/hgfs/ 總用量 0 drwxrwxrwx 1 root root 0 8月 3 22:23 ISO [root@Web-A vmware-tools-distrib]# cd /mnt/hgfs/ISO/ [root@Web-A ISO]# ll 總用量 8414208 -rwxrwxrwx 1 root root 4467982336 3月 19 23:52 CentOS-6.5-x86_64-bin-DVD1.iso -rwxrwxrwx 1 root root 4148166656 6月 11 21:08 CentOS-7.0-1406-x86_64-DVD.iso
五、將該鏡像掛載到 /media/Centos/web
[root@Web-A ISO]# mount -o loop /mnt/hgfs/ISO/CentOS-6.5-x86_64-bin-DVD1.iso /media/Centos/ [root@Web-A ISO]# ll /media/Centos/ 總用量 682 -r--r--r-- 2 root root 14 11月 29 2013 CentOS_BuildTag dr-xr-xr-x 3 root root 2048 11月 29 2013 EFI -r--r--r-- 2 root root 212 11月 28 2013 EULA -r--r--r-- 2 root root 18009 11月 28 2013 GPL dr-xr-xr-x 3 root root 2048 11月 29 2013 images dr-xr-xr-x 2 root root 2048 11月 29 2013 isolinux dr-xr-xr-x 2 root root 655360 11月 29 2013 Packages #rpm包 -r--r--r-- 2 root root 1354 11月 28 2013 RELEASE-NOTES-en-US.html dr-xr-xr-x 2 root root 4096 11月 29 2013 repodata -r--r--r-- 2 root root 1706 11月 28 2013 RPM-GPG-KEY-CentOS-6 -r--r--r-- 2 root root 1730 11月 28 2013 RPM-GPG-KEY-CentOS-Debug-6 -r--r--r-- 2 root root 1730 11月 28 2013 RPM-GPG-KEY-CentOS-Security-6 -r--r--r-- 2 root root 1734 11月 28 2013 RPM-GPG-KEY-CentOS-Testing-6 -r--r--r-- 1 root root 3380 11月 29 2013 TRANS.TBL
注:這樣掛載下次關機就失效了了,將全部rpm文件拷貝到一個文件夾中,cp -rv /media/共享的文件或光盤/Packs/* /新建的文件夾sql
經過rpm命令手動安裝createrepo命令建立yum倉庫rpm -ivh createrepovim
運行命令:createrepo -v /rpm-directory,若是有分組信息,則在運行命令的時候使用-g參數置頂分組文件。centos
安裝createrepo軟件包:
[root@Web-A Packages]# rpm -ivh createrepo-0.9.9-18.el6.noarch.rpm error: Failed dependencies: python-deltarpm is needed by createrepo-0.9.9-18.el6.noarch [root@Web-A Packages]# rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm error: Failed dependencies: deltarpm = 3.5-0.5.20090913git.el6 is needed by python-deltarpm-3.5-0.5.20090913git.el6.x86_64 [root@Web-A Packages]# rpm -ivh deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm Preparing... ########################################### [100%] 1:deltarpm ########################################### [100%] [root@Web-A Packages]# rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm Preparing... ########################################### [100%] 1:python-deltarpm ########################################### [100%] [root@Web-A Packages]# rpm -ivh createrepo-0.9.9-18.el6.noarch.rpm Preparing... ########################################### [100%] 1:createrepo ########################################### [100%]
[root@Web-A Packages]# createrepo ./
Spawning worker 0 with 4023 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
六、編輯本地yum配置文件:
yum默認使用網絡/etc/yum.repos.d/CentOS-Base.repo配置文件,全部須要將其三個文件配置文件失效,將本地yum源文件啓用,配置以下:
備份:
[root@Web-A ISO]# ll /etc/yum.repos.d/ 總用量 16 -rw-r--r--. 1 root root 2523 6月 16 2018 CentOS-Base.repo-rw-r--r--. 1 root root 638 11月 27 2013 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 630 11月 27 2013 CentOS-Media.repo -rw-r--r--. 1 root root 3664 11月 27 2013 CentOS-Vault.repo [root@Web-A ISO]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.BAK [root@Web-A ISO]# mv /etc/yum.repos.d/CentOS-Debuginfo.repo /etc/yum.repos.d/CentOS-Debuginfo.repo.BAK [root@Web-A ISO]# mv /etc/yum.repos.d/CentOS-Vault.repo /etc/yum.repos.d/CentOS-Vault.repo.BAK [root@Web-A ISO]# ll /etc/yum.repos.d/ 總用量 16-rw-r--r--. 1 root root 2523 6月 16 2018 CentOS-Base.repo.BAK -rw-r--r--. 1 root root 638 11月 27 2013 CentOS-Debuginfo.repo.BAK -rw-r--r--. 1 root root 630 11月 27 2013 CentOS-Media.repo -rw-r--r--. 1 root root 3664 11月 27 2013 CentOS-Vault.repo.BAK
配置本地yum源:
[root@Web-A ISO]# vim /etc/yum.repos.d/CentOS-Media.repo # CentOS-Media.repo # # This repo can be used with mounted DVD media, verify the mount point for # CentOS-6. You can use this repo and yum to install items directly off the # DVD ISO that we release. # # To use this repo, put in your DVD and use it with the other repos too: # yum --enablerepo=c6-media [command] # # or for ONLY the media repo, do this: # # yum --disablerepo=\* --enablerepo=c6-media [command] [c6-media] #倉庫名(不要用特殊符號) name=CentOS-$releasever - Media #倉庫描述 baseurl=file:///media/Centos/ #指定倉庫的路徑 # file:///media/cdrom/ #/mnt/cdrom(即爲光盤掛載點) # file:///media/cdrecorder/ gpgcheck=1 #啓用倉庫,1表明啓用,0表明關閉 enabled=1 #不要檢驗軟件包的數字前面 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
七、再使用yum list 來查詢時,有以下信息表示yum源製做成功,能夠看到包的yum源文件名字都變成了c6-media,再按照感覺一下速度。
八、測試安裝軟件ftp
一、建立yum倉庫目錄
[root@fenfa /]# mkdir -p /app/yum/centos6.6/x86_64
二、安裝createrepo、Downloadonly工具
[root@fenfa Packages]# rpm -ivh createrepo-0.9.9-18.el6.noarch.rpm error: Failed dependencies: python-deltarpm is needed by createrepo-0.9.9-18.el6.noarch [root@fenfa Packages]# rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm error: Failed dependencies: deltarpm = 3.5-0.5.20090913git.el6 is needed by python-deltarpm-3.5-0.5.20090913git.el6.x86_64 [root@fenfa Packages]# rpm -ivh deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm Preparing... ########################################### [100%] 1:deltarpm ########################################### [100%] [root@fenfa Packages]# rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm Preparing... ########################################### [100%] 1:python-deltarpm ########################################### [100%] [root@fenfa Packages]# rpm -ivh createrepo-0.9.9-18.el6.noarch.rpm Preparing... ########################################### [100%] 1:createrepo ########################################### [100%] [root@fenfa Packages]# yum install yum-plugin-downloadonly -y
三、初始化repodata索引文件
[root@fenfa /]# createrepo -pdo /app/yum/centos6.6/x86_64 /app/yum/centos6.6/x86_64 Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete
四、提供yum服務,下載新的rpm包
[root@fenfa /]# cd /app/yum/centos6.6/x86_64 [root@fenfa x86_64]# python -m SimpleHTTPServer 80 &>/dev/null & # 能夠用Apache或nginx提供web服務,但用Python的http模塊更簡單,適用於內網環境 [1] 2660 [root@fenfa x86_64]# yum install --downloadonly --downloaddir=/app/yum/centos6.6/x86_64 pcre pcre-devel make zlib zlib-devel gcc-c++ libtool install openssl openssl-devel #只下載軟件不安裝 [root@fenfa x86_64]# ll 總用量 32784 -rw-r--r--. 1 root root 3929020 8月 14 23:02 cpp-4.4.7-23.el6.x86_64.rpm -rw-r--r--. 1 root root 567508 8月 14 23:02 e2fsprogs-1.41.12-24.el6.x86_64.rpm -rw-r--r--. 1 root root 124360 8月 14 23:02 e2fsprogs-libs-1.41.12-24.el6.x86_64.rpm -rw-r--r--. 1 root root 10603660 8月 14 23:02 gcc-4.4.7-23.el6.x86_64.rpm -rw-r--r--. 1 root root 4971176 8月 14 23:02 gcc-c++-4.4.7-23.el6.x86_64.rpm -rw-r--r--. 1 root root 4960920 8月 14 23:02 gcc-gfortran-4.4.7-23.el6.x86_64.rpm -rw-r--r--. 1 root root 20684 8月 14 23:02 keyutils-libs-1.4-5.el6.x86_64.rpm -rw-r--r--. 1 root root 29456 8月 14 23:02 keyutils-libs-devel-1.4-5.el6.x86_64.rpm -rw-r--r--. 1 root root 516132 8月 14 23:02 krb5-devel-1.10.3-65.el6.x86_64.rpm -rw-r--r--. 1 root root 691188 8月 14 23:02 krb5-libs-1.10.3-65.el6.x86_64.rpm -rw-r--r--. 1 root root 38712 8月 14 23:02 libcom_err-1.41.12-24.el6.x86_64.rpm -rw-r--r--. 1 root root 33852 8月 14 23:02 libcom_err-devel-1.41.12-24.el6.x86_64.rpm -rw-r--r--. 1 root root 117980 8月 14 23:02 libgcc-4.4.7-23.el6.i686.rpm -rw-r--r--. 1 root root 106320 8月 14 23:02 libgcc-4.4.7-23.el6.x86_64.rpm -rw-r--r--. 1 root root 274880 8月 14 23:02 libgfortran-4.4.7-23.el6.x86_64.rpm -rw-r--r--. 1 root root 138008 8月 14 23:02 libgomp-4.4.7-23.el6.x86_64.rpm -rw-r--r--. 1 root root 146500 8月 14 23:02 libkadm5-1.10.3-65.el6.x86_64.rpm -rw-r--r--. 1 root root 111508 8月 14 23:02 libselinux-2.0.94-7.el6.x86_64.rpm -rw-r--r--. 1 root root 140160 8月 14 23:02 libselinux-devel-2.0.94-7.el6.x86_64.rpm -rw-r--r--. 1 root root 84072 8月 14 23:02 libselinux-utils-2.0.94-7.el6.x86_64.rpm -rw-r--r--. 1 root root 65484 8月 14 23:02 libsepol-devel-2.0.41-4.el6.x86_64.rpm -rw-r--r--. 1 root root 43092 8月 14 23:02 libss-1.41.12-24.el6.x86_64.rpm -rw-r--r--. 1 root root 303024 8月 14 23:02 libstdc++-4.4.7-23.el6.x86_64.rpm -rw-r--r--. 1 root root 1677328 8月 14 23:02 libstdc++-devel-4.4.7-23.el6.x86_64.rpm -rw-r--r--. 1 root root 398552 8月 14 23:02 make-3.81-23.el6.x86_64.rpm -rw-r--r--. 1 root root 1600772 8月 14 23:02 openssl-1.0.1e-57.el6.x86_64.rpm -rw-r--r--. 1 root root 1227684 8月 14 23:02 openssl-devel-1.0.1e-57.el6.x86_64.rpm -rw-r--r--. 1 root root 200564 8月 14 23:02 pcre-7.8-7.el6.x86_64.rpm -rw-r--r--. 1 root root 327960 8月 14 23:02 pcre-devel-7.8-7.el6.x86_64.rpm -rw-r--r--. 1 root root 44984 8月 14 23:02 zlib-devel-1.2.3-29.el6.x86_64.rpm [root@fenfa x86_64]# createrepo --update /app/yum/centos6.6/x86_64/ #每加入一個rpm包就要更新一下 Spawning worker 0 with 78 pkgs Workers Finished Gathering worker results Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete
五、能夠經過瀏覽器輸入本機IP查看
六、client端配置以下:
[root@web1 ~]# cat /etc/yum.repos.d/CentOS-Media.repo [bqh] name=server baseurl=http://192.168.0.124 enable=1 gpgcheck=0 [root@web1 ~]# yum clean all Loaded plugins: fastestmirror, security Cleaning repos: bqh Cleaning up Everything Cleaning up list of fastest mirrors [root@web1 ~]# yum makecache Loaded plugins: fastestmirror, security Determining fastest mirrors bqh | 2.9 kB 00:00 bqh/filelists_db | 63 kB 00:00 bqh/primary_db | 53 kB 00:00 bqh/other_db | 36 kB 00:00 Metadata Cache Created [root@web1 ~]# yum repolist Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile repo id repo name status bqh server 78 repolist: 30
七、下面咱們安裝nginx服務
[root@web1 nginx-1.6.3]# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package gcc-c++.x86_64 0:4.4.7-4.el6 will be updated ---> Package gcc-c++.x86_64 0:4.4.7-23.el6 will be an update --> Processing Dependency: libstdc++-devel = 4.4.7-23.el6 for package: gcc-c++-4.4.7-23.el6.x86_64 --> Processing Dependency: libstdc++ = 4.4.7-23.el6 for package: gcc-c++-4.4.7-23.el6.x86_64 --> Processing Dependency: gcc = 4.4.7-23.el6 for package: gcc-c++-4.4.7-23.el6.x86_64 ---> Package make.x86_64 1:3.81-20.el6 will be updated ...此處省略 [root@web1 nginx-1.6.3]# rpm -qa make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre pcre-devel gcc-c++-4.4.7-23.el6.x86_64 pcre-devel-7.8-7.el6.x86_64 make-3.81-23.el6.x86_64 zlib-devel-1.2.3-29.el6.x86_64 zlib-1.2.3-29.el6.x86_64 openssl-1.0.1e-57.el6.x86_64 openssl-devel-1.0.1e-57.el6.x86_64 pcre-7.8-7.el6.x86_64 libtool-2.2.6-15.5.el6.x86_64 [root@web1 nginx-1.6.3]# ./configure --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-ht tp_stub_status_modulechecking for OS + Linux 2.6.32-431.el6.x86_64 x86_64 checking for C compiler ... found + using GNU C compiler + gcc version: 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) checking for gcc -pipe switch ... found checking for gcc builtin atomic operations ... found checking for C99 variadic macros ... found checking for gcc variadic macros ... found checking for unistd.h ... found checking for inttypes.h ... found checking for limits.h ... found checking for sys/filio.h ... not found checking for sys/param.h ... found checking for sys/mount.h ... found checking for sys/statvfs.h ... found checking for crypt.h ... found 此處省略...... Configuration summary + using system PCRE library + using system OpenSSL library + md5: using OpenSSL library + sha1: using OpenSSL library + using system zlib library nginx path prefix: "/application/nginx-1.6.3" nginx binary file: "/application/nginx-1.6.3/sbin/nginx" nginx configuration prefix: "/application/nginx-1.6.3/conf" nginx configuration file: "/application/nginx-1.6.3/conf/nginx.conf" nginx pid file: "/application/nginx-1.6.3/logs/nginx.pid" nginx error log file: "/application/nginx-1.6.3/logs/error.log" nginx http access log file: "/application/nginx-1.6.3/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp" [root@web1 nginx-1.6.3]# make && make install make -f objs/Makefile make[1]: Entering directory `/server/tools/nginx-1.6.3' cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os /unix -I objs \ -o objs/src/core/nginx.o \ src/core/nginx.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os /unix -I objs \ -o objs/src/core/ngx_log.o \ src/core/ngx_log.c 此處省略...... test -d '/application/nginx-1.6.3/logs' || mkdir -p '/application/nginx-1.6.3/logs' test -d '/application/nginx-1.6.3/logs' || mkdir -p '/application/nginx-1.6.3/logs' test -d '/application/nginx-1.6.3/html' || cp -R html '/application/nginx-1.6.3' test -d '/application/nginx-1.6.3/logs' || mkdir -p '/application/nginx-1.6.3/logs' make[1]: Leaving directory `/server/tools/nginx-1.6.3' [root@web1 nginx-1.6.3]# echo $? 0 [root@web1 nginx-1.6.3]# lsof -i:80 [root@web1 nginx-1.6.3]# /application/nginx-1.6.3/sbin/nginx -t nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful [root@web1 nginx-1.6.3]# /application/nginx-1.6.3/sbin/nginx [root@web1 nginx-1.6.3]# lsof -i:80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 5683 root 6u IPv4 23834 0t0 TCP *:http (LISTEN) nginx 5684 nginx 6u IPv4 23834 0t0 TCP *:http (LISTEN) [root@web1 nginx-1.6.3]# curl 127.0.0.1 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
ok本地yum源、局域網離線yum倉庫製做到此爲止,安裝你的軟件包,若是須要依賴,系統會自動到yum源中尋找相關依賴包自行安裝。很是方便,固然還有其它方法實現的。