Skip to content

Instantly share code, notes, and snippets.

@greenqy
Last active May 24, 2016 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save greenqy/e6d1aac0eda556987749 to your computer and use it in GitHub Desktop.
Save greenqy/e6d1aac0eda556987749 to your computer and use it in GitHub Desktop.

目标

使用 apt-mirror 来同步 hortonworks 镜像服务器上的 Ambari, HDP, HDP-UTILS 仓库, 方便本地搭建 Hadoop 集群. 适合于 Ubuntu/Debian 分支的操作系统.

参考

使用 apt-mirror 来同步镜像

安装 apt-mirror:

$ sudo apt-get install apt-mirror

修改配置如下:

$ sudo vim /etc/apt/mirror.list

############# config ##################
#
# set base_path    /var/spool/apt-mirror
#
# set mirror_path  $base_path/mirror
# set skel_path    $base_path/skel
# set var_path     $base_path/var
# set cleanscript $var_path/clean.sh
# set defaultarch  <running host architecture>
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads     20
set _tilde 0
############# end config ##############

deb http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.20/repos/ubuntu14 HDP-UTILS main
deb http://public-repo-1.hortonworks.com/ambari/ubuntu14/2.x/updates/2.1.2 Ambari main
deb http://public-repo-1.hortonworks.com/HDP/ubuntu14/2.x/updates/2.3.2.0 HDP main
clean deb http://public-repo-1.hortonworks.com

其中 deb 开头的三行, 是要同步的远端服务器上的三个目录:

更新

每次更新都可以执行下面的命令, 命令自动退出以后, 查看是否有 error, 如果没有, 表示更新完成. 同步的内容不会再变动, 除非再次执行这条命令.

$ su root
# su - apt-mirror -c apt-mirror

一定要使用 su - apt-mirror -c apt-mirror 来同步, 不然使用root权限的话, 会出现没有权限读取的问题.

同步完成以后, 配置中指定的 repo 会同步到 /var/spool/apt-mirror 目录下的各个目录下面, 各个目录的含义如下:

/var/spool/apt-mirror/mirror
   Mirror places here

/var/spool/apt-mirror/skel
   Place for temporarily downloaded indexes

/var/spool/apt-mirror/var
   Log files placed here. URLs and MD5 checksums also here.

使用镜像源

从本地访问

如果源就在本地, 就可以使用下面的方式来指定源:

$ sudo vim /etc/apt/source.list

deb file:///var/www/html/hdp/ambari/ubuntu14/2.x/updates/2.1.2 Ambari main
deb file:///var/www/html/hdp/HDP-UTILS-1.1.0.20/repos/ubuntu14 HDP-UTILS main
deb file:///var/www/html/hdp/HDP/ubuntu14/2.x/updates/2.3.2.0 HDP main

从web访问

通过 web 来访问源, 需要安装 web 服务器(以 apache 为例), 并在 apache 网页所在目录设置一个软链接指向本地的镜像所在目录.

$ ln -s /var/spool/apt-mirror/mirror/public-repo-1.hortonworks.com/ /var/www/html/hdp

apache 默认是会进入软链接的.

用浏览器访问 http://host-ip/hdp 来查看是否能出现文件列表, 出现的话, 说明可以通过web访问.

接下来配置用 web 方式从局域网的镜像中更新/下载信息:

$ sudo vim /etc/apt/source.list

deb http://cci-ambari/hdp/ambari/ubuntu14/2.x/updates/2.1.2 Ambari main
deb http://cci-ambari/hdp/HDP-UTILS-1.1.0.20/repos/ubuntu14 HDP-UTILS main
deb http://cci-ambari/hdp/HDP/ubuntu14/2.x/updates/2.3.2.0 HDP main

使用 sudo apt-get update 的时候, 会有一个错误信息:

W: Failed to fetch http://cci-ambari/hdp2/HDP-UTILS-1.1.0.20/repos/ubuntu14/dists/HDP-UTILS/main/binary-i386/Packages  404  Not Found

原因是没有 HDP-UTILS 的32位安装包, 反正我们用的都是64位的系统, 所以不影响使用.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment