1.正向代理
使squid服务端虚拟机可以上网,做为代理,然后使不可以上网的客户端使用服务端作为代理访问百度。
服务端:
让squid服务端虚拟机连接真机上网:
vim /etc/sysconfig/network-scripts/ifcfg-eth0
GATEWAY=172.25.254.61
route -n
vim /etc/resolv.conf
nameserver 114.114.114.114
ping www.baidu.com
可以上网啦!
yum install squid -y
systemctl start squid
netstat -antlupe | grep squid
vim /etc/squid/squid.conf
56行 http_access allow all
62行 cache_dir ufs /var/spool/squid 100 16 256
:wq
systemctl restart squid
systemctl stop firewalld
ls /var/spool/squid/
客户端:不可以上网,但使用服务端作为代理访问百度
浏览器:
Edit->Perferences->Advanced->Network->Settings->Manual proxy configuration->HTTP Proxy:172.25.254.140 Port:3128保存
操作如下:
vim /etc/squid/squid.conf
打开客户端浏览器:
2.CDN搭建
CDN的全称是Content Delivery Network,即内容分发网络。CDN是构建在网络之上的内容分发网络,依靠部署在各地的边缘服务器,通过中心平台的负载均衡、内容分发、调度等功能模块,使用户就近获取所需内容,降低网络拥塞,提高用户访问响应速度和命中率。
服务端(172.25.254.61):
yum install httpd -y
systemctl start httpd
vim /var/www/html/index.html
172.25.254.61.page
systemctl stop firewalld
squid代理服务器(172.25.254.100):
关闭httpd服务
systemctl stop firewalld
vim /etc/squid/squid.conf
http_port 80 vhost vport
cache_peer 172.25.254.61 parent 80 0 proxy-only
systemctl restart squid
测试主机:
vim /etc/hosts
172.25.254.100 www.shenzhen.com
浏览器设置代理后访问www.shenzhen.com
3.负载均衡
服务端1(172.25.254.10)
vim /var/www/html/index.html
172.25.254.10’page
服务端2(172.25.254.100)
vim /var/www/html/index.html
172.25.254.100’page
squid代理服务器:
参数 weight=2 权重参数 weight=1(默认为1)
cache_peer 172.25.254.10 parent 80 0 proxy-only no-query round-robin originserver name=web1
cache_peer 172.25.254.100 parent 80 0 proxy-only no-query round-robin originserver name=web2 weight=2
cache_peer_domain web1 web2 www.haha.com
测试端:
vim /etc/hosts
172.25.254.200 www.haha.com