docker 配置缓存代理服务apt-cacher-ng

Apt-Cacher-NG是一个缓存代理服务(或者apt代理),对基于Debian的设备,如 Ubuntu, Kubuntu, Xubuntu, Edubuntu, Linux Mint等,它被是用来缓存已经下载过的包。
html

wKioL1jbgyzxjb9AAAFjNQixMhc202.png

你有几台电脑连接的网络,你想手动在每台机器上安装或者更新软件包,(可想而知)这是一个至关困难的任务并且耗费时间;这就是咱们为何要配置一个apt-cacher-ng服务到全部系统这个伟大想法的缘由,由于它将从网络首次缓存全部已下载包到 apt-cache server,剩余的Debian, Ubuntu机器得到这些软件包就只需从Apt-Cache直接获取,这将节约咱们的宝贵的时间和网络带宽。git

特色web

  1. apt-cacher-ng 将节约咱们的时间.docker

  2. apt-cacher-ng 将节约咱们的带宽.ubuntu

  3. 经过导入参数,咱们能够整合 ISO p_w_picpath data 或者 DVD到 apt-cacher-ng。vim

本次实验使用docker容器来搭建:浏览器

一、首先建立Dockerfile文件,
缓存

root@ubuntu:~/docker/apt-cache-ng# cat Dockerfile 
FROM        ubuntu

VOLUME      ["/var/cache/apt-cacher-ng"]
RUN     apt-get update && apt-get install -y apt-cacher-ng

EXPOSE      3142
CMD     chmod 777 /var/cache/apt-cacher-ng && /etc/init.d/apt-cacher-ng start && tail -f /var/log/apt-cacher-ng/*

二、build这个镜像
bash

docker build -t eg_apt_cache_ng .

三、启动镜像,而且把端口映射到宿主机的13142上网络

docker run -d -p 13142:3142 --name test_apt_cacher_ng eg_apt_cacher_ng

四、可使用docker命令来查看日志

docker logs -f test_apt_cacher_ng

五、登陆浏览器查看;

wKioL1jbhV6htjA_AAEZZsPnZ_8744.png-wh_50

wKiom1jbhZLBIRp4AAB6E_3pxtY989.png

这里,咱们能够看到 apt-cacher-ng的报告页面,点击静态报告,配置页面的底部,导航到下载命中或者失误的状况页面。

在报告页面咱们须要复制Proxy URL以便后边使用。咱们能够安装包在这个server上,经过配置本地参数,添加实体/etc/apt/apt.conf.d/02proxy的 apt-cache。

Acquire::http { Proxy "http://192.168.0.2:3142"; };

docker官网的说明:

To get your Debian-based containers to use the proxy, you have following options. Note that you must replace dockerhost with the IP address or FQDN of the host running the test_apt_cacher_ng container.

  1. Add an apt Proxy setting echo 'Acquire::http { Proxy "http://dockerhost:3142"; };' >> /etc/apt/conf.d/01proxy

  2. Set an environment variable: http_proxy=http://dockerhost:3142/

  3. Change your sources.list entries to start with http://dockerhost:3142/

  4. Link Debian-based containers to the APT proxy container using --link

  5. Create a custom network of an APT proxy container with Debian-based containers.


六、建立客户端的docker 容器

docker run --rm -t -i -e http_proxy=http://192.168.0.2:3142/ debian bash

这里也是可使用dockerfile来指定

FROM ubuntu
RUN  echo 'Acquire::http { Proxy "http://192.168.0.2:3142"; };' >> /etc/apt/apt.conf.d/01proxy
RUN apt-get update && apt-get install -y vim git

连接容器到apt容器上

 docker run -i -t --link test_apt_cacher_ng:apt_proxy -e http_proxy=http://apt_proxy:3142/ debian bash

你也能够本身建立一个容器,而后进入到容器中,去手动配置

 vim /etc/apt/apt.conf.d/02proxy #在这个路径下建立文件
 Acquire::http { Proxy "http://192.168.0.2:3142"; }; #写入这条内容

七、测试:

处处咱们服务端和客户端都安装完毕

root@ubuntu:~/docker/apt-cache-ng# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
bd4e542edb39        debian              "bash"                   59 minutes ago      Up 59 minutes                                 peaceful_pike
f6fafb226c66        eg_apt_cache_ng     "/bin/sh -c 'chmod..."   About an hour ago   Up About an hour    0.0.0.0:13142->3142/tcp   test_apt_cacher_ng

登陆到客户端中,去更新几个包,或者安装几个包,而后再web上面能够看到缓存来多少个文件

wKiom1jbiEHj0jmLAAB_TOIoztc228.png-wh_50

这里你能够把安装包,卸载,而后再次安装,你会发现速度会很是快,并且web上面也会hits也会有变更来显示你是否从apt上下载



官网:https://www.unix-ag.uni-kl.de/~bloch/acng/html/index.html

docker官网:https://docs.docker.com/engine/examples/apt-cacher-ng/

参考博文:http://liuhong1happy.lofter.com/post/1cdb27c8_60dfc24

相关文章
相关标签/搜索