正向代理
(实验条件:代理端IP:172.25.254.110能上网无httpd服务;
虚拟机IP:172.25.254.210不能上网;让210使用代理去联网)
正向代理 是位于客户端和原始服务器之间的服务器,
为了从原始服务器取得内容,客户端向代理发送一个请求并指定目标(原始服务器),
然后代理向原始服务器转交请求并将获得的内容返回给客户端。
1.配置真机网络
vim /etc/sysconfig/network-scripts/ifcfg-eth0
vim /etc/resolv.conf
nameserver 114.114.114.114 ##配置虚拟机网关,先让110能上网
systemctl restart network
2.下载代理软件
yum install squid.x86_64 -y ##代理软件
vim /etc/squid/squid.conf
# And finally deny all other access to this proxy
56 :http_access allow all ##允许所有的访问
# Uncomment and adjust the following to add a disk cache directory.
62 :cache_dir ufs /var/spool/squid 100 16 256 ###100:最大缓存100M;
systemctl restart squid ###重启代理
firewall-cmd --permanent --add-port=3128/tcp ##开启端口3128;代理端口是3128
firewall-cmd --reload ##刷新
3.配置虚拟机
(1)在 preferences-->Advanced-->Network-->settings-->manual proxy configuration
-->http proxy:代理主机IP; port:3128-->点击use this proxy server for all protocols
(2)使用代理,输入网址和端口
(3)测试:
成功访问百度
注意:成功上网;因为使用的是虚拟机的代理,可以上网但是ping不通
反向代理
(实验条件:三台主机:客户端IP:172.25.254.210;代理端IP:172.25.254.110;服务端IP:172.25.254.57)
反向代理方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器
1.在服务端
vim /var/www/html/index.html ###写好默认发布文件
2.在代理端
yum install squid.x86_64 -y
vim /etc/squid/squid.conf ##编辑配置文件
http_access allow all
http_port 80 vhost vport ##80:服务端端口
cache_peer 172.25.254.57 parent 80 0 no-query ##cache_peer:缓存策略;172.25.254.57(服务端IP,缓存服务端让客户端查看); parent:没有备用的代理;80:服务端端口为80;0:没有备用端口;no-query:没有备用的代理
# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /var/spool/squid 100 16 256
systemctl restart squid ###重启代理
3.在客户端
输入代理端IP,成功访问服务端的发布文件
平衡轮循(把访问量分散开)
一定要关闭调度端防火墙
1.在调度端(提供轮循调度)
vim /etc/squid/squid.conf
# And finally deny all other access to this proxy
http_access allow all
# Squid normally listens to port 3128
http_port 80 vhost vport
cache_peer 172.25.254.57 parent 80 0 no-query originserver round-robin name=web1
cache_peer 172.25.254.210 parent 80 0 no-query originserver round-robin name=web2
cache_peer_domain web1 web2 www.westos.com
(originserver:源服务器)
# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /var/spool/squid 100 16 256
2.在客户端
(1)进行地址解析:
vim /etc/hosts
172.25.254.110(代理端,也就是调度端IP) www.westos.com ##访问www.westos.com就要在客户端解析该地址
(2)编辑210的IP的http的内容
vim /var/www/html
(3)进行访问
浏览器每刷新一次会访问调度端指定的两个主机(57和210);
这样一来把大量的访问数据分散开来,但是访问的信息不会被改变,
同时缓解了服务器的压力,客户端也感到访问速度的增加。
测试:
点网页的刷新: