目錄
一、環(huán)境介紹
二、安裝squid
三、配置代理
擴(kuò)展一、JAVA應(yīng)用通過(guò)代理訪問(wèn)外網(wǎng)
擴(kuò)展二、通過(guò)nginx代理實(shí)現(xiàn)yum跳轉(zhuǎn)
擴(kuò)展三、代理harbor鏡像方式訪問(wèn)
一、環(huán)境介紹
192.168.7.131可以通外網(wǎng)
192.168.7.129不通外網(wǎng)
需要通過(guò)代理的方式實(shí)現(xiàn)192.168.7.129可以訪問(wèn)外網(wǎng)
二、安裝squid
?1、在192.168.7.131主機(jī)(可以訪問(wèn)外網(wǎng))使用yum安裝squid
yum -y install squid
??2、編輯/etc/squid/squid.conf配置文件
?默認(rèn)端口為3128,可根據(jù)實(shí)際需求更改
?3、啟動(dòng)squid服務(wù)并實(shí)現(xiàn)開機(jī)自啟
systemctl start squid
systemctl enable squid
三、配置代理
1、在不通外網(wǎng)的主機(jī)192.168.7.129進(jìn)行測(cè)試curl www.baidu.com
2、在/etc/profile中添加以下內(nèi)容
[root@jh-newa-node09 ~]# tail -2 /etc/profile
export http_proxy=http://192.168.7.131:3128
export https_proxy=https://192.168.7.131:3128
[root@jh-newa-node09 ~]# source /etc/profile
3、配置后再次測(cè)試
擴(kuò)展一、JAVA應(yīng)用通過(guò)代理訪問(wèn)外網(wǎng)
bin/setenv.sh文件中添加
-Dhttp.proxyHost=192.168.7.131 -Dhttp.proxyPort=3128 -Dhttps.proxyHost=192.168.7.131 -Dhttps.proxyPort=3128
擴(kuò)展二、通過(guò)nginx代理實(shí)現(xiàn)yum跳轉(zhuǎn)
1、在通外網(wǎng)的主機(jī)上配置nginx
#nginx配置文件中添加如下參數(shù),暴露本機(jī)的8082 8083端口,將請(qǐng)求轉(zhuǎn)發(fā)至mirrors.aliyun.com
[root@ecs-37b3-0729076 ~]# vim /etc/nginx/nginx.conf
server {
listen 192.168.7.131:8083;
server_name mirrors.cloud.aliyuncs.com;
location / {
proxy_pass http://mirrors.aliyun.com;
# index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 192.168.7.131:8082;
server_name epel.com;
location / {
proxy_pass http://mirrors.aliyun.com;
# index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
[root@ecs-37b3-0729076 ~]# systemctl start nginx
2、在不通外網(wǎng)主機(jī)/etc/yum.repos.d/目錄下替換yum源
[root@jh-newa-node09 ~]# cd /etc/yum.repos.d/
[root@jh-newa-node09 yum.repos.d]# ls
CentOS.repo epel-7.repo repo
[root@jh-newa-node09 yum.repos.d]# sed -i s/mirrors.aliyun.com/192.168.7.131:8083/g CentOS.repo
[root@jh-newa-node09 yum.repos.d]# sed -i s/mirrors.aliyun.com/192.168.7.131:8082/g epel-7.repo
3、測(cè)試:
[root@jh-newa-node09 yum.repos.d]# yum -y install squid
擴(kuò)展三、代理harbor鏡像方式訪問(wèn)
1、確保外網(wǎng)主機(jī)到鏡像倉(cāng)庫(kù)網(wǎng)絡(luò)可達(dá)
?2、內(nèi)網(wǎng)主機(jī)docker配置文件中添加如下參數(shù)
mkdir /etc/systemd/system/docker.service.d
vim /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://192.168.7.131:3128"
Environment="HTTPS_PROXY=http://192.168.7.131:3128"
systemctl daemon-reload
systemctl restart docker
3、測(cè)試:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-720831.html
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-720831.html
到了這里,關(guān)于Linux內(nèi)網(wǎng)服務(wù)器通過(guò)代理訪問(wèn)外網(wǎng)服務(wù)器的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!