squid stunnel 为 docker 配置代理服务器

www.allocmem.com · · 3046 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

目地

为k8s的docker服务提供http/https代理,解决docker无法pull gcr.io/google_containers 谷歌镜像问题

环境

  1. GCE ubuntu 16.04
  2. k8s集群机器 ubuntu16.04

简要步骤

  • GCE 搭建squid正向http/https代理服务器
  1. 直接使用apt-get install 安装 apt-get install squid3 -y 注意:配置文件在/etc/squid或/etc/squid3下,根据系统不同可能会有一点差异,由于这里进行快速安装,不需要暴露端口给外部使用,也不需要密码,所以配置文件我这里保持默认
  • GCE 安装stunnel代理服务器
  1. stunnel主要用来在GCE和k8s机器上代理的数据传输进行加密,否则明文传输很快会被GFW拦截.注意stunnel分为服务端和客户端,GCE上安装服务端,在k8s集群上安装客户端

  2. 直接使用apt-get install 安装服务端 apt-get install stunnel4 -y

  3. 编辑配置文件 vim /etc/stunnel/stunnel.conf

    verify = 2 #要求并验证每个SSL连接的证书。如果未显示证书或无效证书,则会丢弃连接。
    
    
    CAfile = /etc/stunnel/stunnel.pem ##下一步生成的证书地址
    
    
    client = no #是否为客户端 这里是服务端填写no
    
    
    [squid]
    accept = 65501
    connect = 127.0.0.1:3128 #本地squid服务地址
    cert = /etc/stunnel/stunnel.pem #下一步生成的证书地址
    
  4. 客户端stunnel.conf示例配置

  5. cert = stunnel.pem
    client = yes
    [squid]
    accept = 127.0.0.1:8080
    connect = [Server’s Public IP]:8888

     

  6. openssl生成证书,用户stunnel加密解密

    openssl genrsa -out key.pem 2048   
    
    
    openssl req -new -x509 -key key.pem -out 
    
    
    cert.pem -days 1095
    
    
    cat key.pem cert.pem >> /etc/stunnel/stunnel.pem
    

    注意:创建证书时,系统会要求您提供一些国家/地区信息,可随便输入,但是当被要求输入“Common Name”时,您必须输入正确的hostname或IP地址(VPS),我这里输入的ip地址。

  7. 通过配置/etc/default/stunnel4文件启用自动启动,vim /etc/default/stunnel4

    #将ENABLED更改为1:
    
    
    ENABLED=1
    
  8. 重新启动Stunnel使配置生效,使用以下命令:

    /etc/init.d/stunnel4 restart
    
  • K8S 集群机器分别搭建stunnel
  1. 安装步骤几乎和上面相同
  2. scp或其他方法把证书拷贝到k8s集群中
  3. 配置文件不同 cert = /etc/stunnel/stunnel.pem #和服务端完全相同的证书 client = yes #声明为客户端 [squid] accept = 127.0.0.1:65502 #本地代理的端口,即为http/https代理地址 connect = {GCE_IP}:65501 #GCE 服务端ip和端口

浏览器SwitchyOmega代理穿透GFW

  1. 配置添加http代理127.0.0.1:65502 即可
  2. docker添加http/https代理请参考官方文档 https://docs.docker.com/engine/admin/systemd/#start-manually

参考文献

  1. https://www.stunnel.org/howto.html
  2. https://www.digitalocean.com/community/tutorials/how-to-set-up-an-ssl-tunnel-using-stunnel-on-ubuntu

本文来自:www.allocmem.com

感谢作者:www.allocmem.com

查看原文:squid stunnel 为 docker 配置代理服务器

3046 次点击  
加入收藏 微博
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传