1. 程式人生 > >基於tinyproxy搭建yum代理服務器

基於tinyproxy搭建yum代理服務器

mtu packet onf adc enca 容器 back user spa

在我們實際的工作當中,經常會遇到這種情況,我們對線上服務器進行操作時是通過跳板機來進行的,出於安全性及投入資金來考慮非必要情況下除跳板機以外的服務器是沒有內網ip的,所以當我們位於內網的服務器需要使用yum安裝軟件包時就遇到了不能連接網絡的問題,我們可以通過部署基於Tinyproxy的http代理來用作yum代理,操作如下:

1.首先我們還是新建了一個名為TInyproxy的docker容器,新建容器後我們發現我們並沒有ping命令,所以需要安裝initscripts包

[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:12:00:05


inet addr:172.18.0.5 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:acff:fe12:5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0

RX bytes:0 (0.0 b) TX bytes:508 (508.0 b)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0


collisions:0 txqueuelen:1
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

[[email protected] ~]# ping www.baidu.com
bash: ping: command not found

[[email protected] ~]# yum install initscripts

安裝完成後,ping百度查看我們是否可以連接外網

[[email protected] ~]# ping www.baidu.com
PING www.baidu.com (119.75.218.70) 56(84) bytes of data.
64 bytes from 119.75.218.70: icmp_seq=1 ttl=53 time=5.83 ms
64 bytes from 119.75.218.70: icmp_seq=2 ttl=53 time=4.44 ms

2.通過yum安裝TInyproxy軟件包搭建Tinyproxy代理服務器,修改主配置文件

[[email protected] ~]# yum -y install epel-release tinyproxy

[[email protected] ~]# vim /etc/tinyproxy/tinyproxy.conf  #主配置文件

添加以下項:

Allow 127.0.0.1  #視環境而定,添加允許的網段或主機

Port 8888  #設定一個運行Tinyproxy需要使用的端口,此端口在內網機的yum配置文件中同樣需要指定

3.創建用於模擬內網的服務器,修改yum配置文件,指定使用代理服務器。

[[email protected] ~]# vim /etc/yum.conf

添加以下項:

proxy=http:172.18.0.5:8888  #ip及端口視情況而定

proxy_username=username  #並非必要
proxy_password=password   #並非必要

4.搭建完成後,進行測試

[[email protected] ~]# yum clean all && yum makecache  無報錯即可

基於tinyproxy搭建yum代理服務器