CentOS 6.5本地yum源、局域网离线yum仓库(断网情况下轻松安装各种依赖包)

在工作中, 公司的服务器大部分都禁止连接外网的,初始化系统,测试某些产品时,往往缺一些软件或依赖包,一个个上传到机器,如此浪费时间,浪费金钱,en...yum能够自动查找并解决rpm包之间的依赖关系,需要有一个包含各种rpm软件包的repository(软件仓库),提供软件仓库的服务器习惯上成为“源”服务器,网络上有大量的源服务器,但是,由于受到网络连接速度、带宽的限制,导致软件安装耗时过长甚至失败,特别是当有大量服务器大量软件包需要升级时,更新的缓慢程序令人难以忍受,相比较而言,本地YUM源服务器最大优点在局域网的快速网络连接和稳定性,有了局域网中的yum源服务器,即便在网络连接中断的情况下,也不会影响软件升级和安装。

 一、挂载本地ISO镜像方式:

1、下载yum源的DVD镜像,镜像名如下:

CentOS-6.5-x86_64-bin-DVD1

2、将其宿主机的镜像挂载到linux中去:

  • 因iso文件是宿在主机上,所有,通过vmware的文件共享,将宿主机上的iso文件挂载到/mnt/hgfs/目录下
  • VM--Settings--选项--共享文件夹--勾选“总是启用”点击“添加”选取本地iso文件的目录,添加后如下:

3、安装VMware Tools

[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

 4、接下来我们在//mnt/hgfs下看是否有共享的文件:

[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

5、将该镜像挂载到 /media/Centos/

[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/* /新建的文件夹

通过rpm命令手动安装createrepo命令创建yum仓库rpm -ivh createrepo

运行命令:createrepo -v /rpm-directory,如果有分组信息,则在运行命令的时候使用-g参数置顶分组文件。

安装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

 

6、编辑本地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

7、再使用yum list 来查询时,有如下信息表示yum源制作成功,可以看到包的yum源文件名字都变成了c6-media,再按照感受一下速度。

8、测试安装软件ftp

二、自定义局域网离线yum仓库

1、创建yum仓库目录

[root@fenfa /]# mkdir -p /app/yum/centos6.6/x86_64

2、安装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

3、初始化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

4、提供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

5、可以通过浏览器输入本机IP查看

6、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

7、下面我们安装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源中寻找相关依赖包自行安装。非常方便,当然还有其它方法实现的。

posted @ 2019-08-04 00:40  南清风  阅读(3153)  评论(0编辑  收藏  举报