Linux内网服务器通过代理访问外网服务器

打印 上一主题 下一主题

主题 550|帖子 550|积分 1650

目次
一、情况先容
二、安装squid
三、设置代理
扩展一、JAVA应用通过代理访问外网
扩展二、通过nginx代理实现yum跳转
扩展三、代理harbor镜像方式访问


一、情况先容

192.168.7.131可以通外网
192.168.7.129不通外网
须要通过代理的方式实现192.168.7.129可以访问外网
二、安装squid

 1、在192.168.7.131主机(可以访问外网)利用yum安装squid

  1. yum -y install squid
复制代码
  2、编辑/etc/squid/squid.conf设置文件


 默认端口为3128,可根据现实需求更改
 3、启动squid服务并实现开机自启
  1. systemctl start squid
  2. systemctl enable squid
复制代码
三、设置代理

1、在不通外网的主机192.168.7.129举行测试curl www.baidu.com

2、在/etc/profile中添加以下内容
  1. [root@jh-newa-node09 ~]# tail -2 /etc/profile
  2. export http_proxy=http://192.168.7.131:3128
  3. export https_proxy=https://192.168.7.131:3128
  4. [root@jh-newa-node09 ~]# source /etc/profile
复制代码
3、设置后再次测试

扩展一、JAVA应用通过代理访问外网

bin/setenv.sh文件中添加
  1. -Dhttp.proxyHost=192.168.7.131 -Dhttp.proxyPort=3128 -Dhttps.proxyHost=192.168.7.131 -Dhttps.proxyPort=3128
复制代码
扩展二、通过nginx代理实现yum跳转

1、在通外网的主机上设置nginx
  1. #nginx配置文件中添加如下参数,暴露本机的8082 8083端口,将请求转发至mirrors.aliyun.com
  2. [root@ecs-37b3-0729076 ~]# vim /etc/nginx/nginx.conf
  3.     server {
  4.         listen       192.168.7.131:8083;
  5.         server_name  mirrors.cloud.aliyuncs.com;
  6.         location / {
  7.           proxy_pass  http://mirrors.aliyun.com;
  8.           # index  index.html index.htm;
  9.         }
  10.         error_page   500 502 503 504  /50x.html;
  11.         location = /50x.html {
  12.             root   html;
  13.         }
  14. }
  15.     server {
  16.         listen       192.168.7.131:8082;
  17.         server_name  epel.com;
  18.         location / {
  19.           proxy_pass http://mirrors.aliyun.com;
  20.           # index  index.html index.htm;
  21.         }
  22.         error_page   500 502 503 504  /50x.html;
  23.         location = /50x.html {
  24.             root   html;
  25.         }
  26. }
  27. [root@ecs-37b3-0729076 ~]# systemctl start nginx
复制代码
2、在不通外网主机/etc/yum.repos.d/目次下更换yum源
  1. [root@jh-newa-node09 ~]# cd /etc/yum.repos.d/
  2. [root@jh-newa-node09 yum.repos.d]# ls
  3. CentOS.repo  epel-7.repo  repo
  4. [root@jh-newa-node09 yum.repos.d]# sed -i s/mirrors.aliyun.com/192.168.7.131:8083/g CentOS.repo
  5. [root@jh-newa-node09 yum.repos.d]# sed -i s/mirrors.aliyun.com/192.168.7.131:8082/g epel-7.repo
复制代码
3、测试:
  1. [root@jh-newa-node09 yum.repos.d]# yum  -y install squid
复制代码

扩展三、代理harbor镜像方式访问

1、确保外网主机到镜像仓库网络可达

 2、内网主机docker设置文件中添加如下参数
  1. mkdir  /etc/systemd/system/docker.service.d
  2. vim /etc/systemd/system/docker.service.d/http-proxy.conf
  3. [Service]
  4. Environment="HTTP_PROXY=http://192.168.7.131:3128"
  5. Environment="HTTPS_PROXY=http://192.168.7.131:3128"
  6. systemctl daemon-reload
  7. systemctl restart docker
复制代码
3、测试:



免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

滴水恩情

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表