1. 程式人生 > >阿裏雲內網機器通過squids代理上訪問外網資源

阿裏雲內網機器通過squids代理上訪問外網資源

transform url accep iss time eval connect 目錄 mas

一、背景
代理服務器A(10.0.1.2)機器有公網地址可正常訪問外網
業務服務器B(10.0.1.33)機器無公網地址不能訪問外網
代理服務器A((10.0.1.2)和業務服務器B(10.0.1.33)在公一個數據中心(同一個局域網)
需要實現B訪問外網通過A代理出去

二、安裝

  1. 在代理服務器A(10.0.1.2)機器上安裝squid
    yum install openssl squid -y
    然後啟動服務
    service squid start

    2、在業務服務器B(10.0.1.33)機器宿主目錄中的.bash_profile或者profile添加如下內容

    cat>>/etc/profile<<-EOF
    export http_proxy=http://10.0.1.2:3128
    export https_proxy=http://10.0.1.2:3128
    EOF
    source /etc/profile

    三、測試代理訪問外網

    在業務服務器B(10.0.1.33)上隨便訪問一個網站如www.baidu.com

    [root@k8s-registry ~]# curl -I http://www.baidu.com
    HTTP/1.1 200 OK
    Accept-Ranges: bytes
    Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
    Content-Length: 277
    Content-Type: text/html
    Date: Tue, 31 Jul 2018 08:37:45 GMT
    ETag: "575e1f8a-115"
    Last-Modified: Mon, 13 Jun 2016 02:50:50 GMT
    Pragma: no-cache
    Server: bfe/1.0.8.18
    X-Cache: MISS from k8s-master
    X-Cache-Lookup: MISS from k8s-master:3128
    Via: 1.1 k8s-master (squid/3.5.20)
    Connection: keep-alive
    [root@k8s-registry ~]# netstat -anlp|grep 3128
    tcp        0      0 10.0.1.33:36674    10.0.1.2:3128     TIME_WAIT   -

    四、至此阿裏雲內網服務器通過可以訪問外網的服務器代理實現訪問互聯網的功能

阿裏雲內網機器通過squids代理上訪問外網資源