squid正向代理
1.讓虛擬機可以上網
vim /etc/sysconfig/network-scripts/ifcfg-eth0
GATEWAY=172.25.254.250 ###通過250的電腦讓虛擬機上網
DNS1=114.114.114.114
systemctl restart network
測試
route -n ###查看網關
ping www.qq.com
2.squid安裝和配置更改172.25.254.117
yum install -y squid ##安裝正向代理
vim /etc/squid/squid.conf ##修改配置文件
55 # And finally deny all other access to this proxy
56 http_access allow all ##允許訪問
57
58 # Squid normally listens to port 3128
59 http_port 3128
60
61 # Uncomment and adjust the following to add a disk cache directory.
62 cache_dir ufs /var/spool/squid 100 16 256 ##創建緩存地點 100M 16個目錄 256個子級目錄
systemctl start squid ##開啓服務
netstat -lntup|grep squid ##查看端口
如果防火牆未關
firewall-cmd --permanent --add-port=3128/tcp ##
firewall-cmd --reload ##
在真機中打開瀏覽器設置代理服務器的ip地址(172.25.254.117)
用真機打開一個網頁就可以正常上網
squid反向代理
1.準備兩臺虛擬機ip地址分別爲真機ip+100 真機ip+200
2.在172.25.254.217中:
yum install -y squid
vim /etc/squid/squid.conf
55 # And finally deny all other access to this proxy
56 http_access allow all ##允許訪問
57
58 # Squid normally listens to port 3128
59 http_port 80 vhost vport
60 cache_peer 172.25.254.117 parent 80 0 no-query
61 # Uncomment and adjust the following to add a disk cache directory.
62 cache_dir ufs /var/spool/squid 100 16 256 ##創建緩存地點
systemctl start squid
systemctl stop firewalld
測試:
打開遊覽器輸入172.25.254.217這時會訪問到117
輪詢
需要至少兩臺已經配置好apache的虛擬機和一臺代理緩存(217)
vim /etc/squid/squid.conf
cache_peer 172.25.254.117 parent 80 0 no-query originserver round-robin name=webserver1
cache_peer 172.25.254.125 parent 80 0 no-query originserver round-robin name=webserver2
cache_peer_domain webserver1 webserver2 www.westos.com
# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /var/spool/squid 100 16 256
# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid
在瀏覽器所在的主機添加解析
vim /etc/hosts