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