主机名 IP地址  网关   DNS   服务类型 
Master

eth0:192.168.17.130(VMnet4)

eth1:192.168.30.130(NAT)

192.168.30.2 119.29.29.29  Squid
client eth0:192.168.17.131(VMnet4) 192.168.17.131  无  

服务端安装Squid服务

[root@Master ~]# yum install -y squid

配置正向代理,修改配置文件

[root@Master ~]# vim /etc/squid/squid.conf   //添加
acl localdomain src 192.168.30.0/
http_access allow localdomain
这里修改配置文件的第二种方式是
搜索http_access deny all将deny修改为allow,同时注释掉上面添加的两行内容

启动squid服务测试

在客户端测试

只是有点慢,还有不知道为什么打不开百度。

配置透明代理,在正向代理的基础上。

[root@Master ~]# vim /etc/squid/squid.conf
http_port transparent #直接搜索http_port 3128然后在行尾加上一个单词即可

开启IPv4地址转发

[root@Master ~]# vim /etc/sysctl.conf 

net.ipv4.ip_forward = 

使之生效,并配置iptables:

[root@Master ~]# sysctl -p
net.ipv4.ip_forward =
net.ipv4.conf.default.rp_filter =
net.ipv4.conf.default.accept_source_route =
kernel.sysrq =
kernel.core_uses_pid =
net.ipv4.tcp_syncookies =
kernel.msgmnb =
kernel.msgmax =
kernel.shmmax =
kernel.shmall =
[root@Master ~]# service iptables start
iptables: Applying firewall rules: [ OK ]
[root@Master ~]# iptables -t nat -A POSTROUTING -s 192.168.17.0/ -j SNAT --to 1922.168.30.130 //SNAT代理内部上网,将内部的地址全部转化为可以上网的地址 192.168.1.63
[root@Master ~]# iptables -t nat -A PREROUTING -s 192.168.17.0/ -i eth0 -p tcp --dport -j REDIRECT --to-port 3128 //端口转化,来自192.168.2.0,从eth1且端口为80的数据进行数据重定向到3128,代理服务器为你工作
[root@Master ~]# iptables -L -t nat
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- 192.168.17.0/ anywhere tcp dpt:http redir ports Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
SNAT all -- 192.168.17.0/ anywhere to:192.168.30.130 Chain OUTPUT (policy ACCEPT)
target prot opt source destination

重启squid去客户端测试

客户端确认DNS和网关都可以ping通

然后测试

使用curl -I www.sina.com或者time curl www.sina.com

配置反向代理加速

[root@master ~]# vim /etc/squid/squid.conf

http_access  allow all

http_port  vhost #启用虚拟主机
cache_peer 192.168.17.131 parent no-query originserver weight= name=a
cache_peer 192.168.17.131 parent no-query originserver weight= name=b
#no-query和originserver指明了服务器,不查询直接到源服务器
#name对前面的定义做了一个别名
cache_peer_domain a www.servera.com #访问www.servera.com将直接访问到上面定义的17.131的80端口
cache_peer_domain b www.serverb.com
cache_peer_access a allow all
cache_peer_access b allow all

重启squid

[root@master ~]# service squid restart
Stopping squid: ................ [ OK ]
Starting squid: . [ OK ]

配置虚拟主机,slave作为httpd的服务端

[root@slave ~]# mkdir /var/www/html/sishen
[root@slave ~]# echo "<h1>This is serverb</h1>" > /var/www/html/index.html
[root@slave ~]# echo "<h1>This is servera</h1>" > /var/www/html/sishen/index.html
[root@slave ~]# vim /etc/httpd/conf/httpd.conf
.......
Listen
Listen
............
<VirtualHost *:>
ServerAdmin webmaster@dummy-host.servera.com
DocumentRoot /var/www/html/sishen
ServerName www.servera.com
ErrorLog logs/dummy-host.servera.com-error_log
CustomLog logs/dummy-host.servera.com-access_log common
</VirtualHost>
<VirtualHost *:>
ServerAdmin webmaster@dummy-host.serverb.com
DocumentRoot /var/www/html
ServerName www.serverb.com
ErrorLog logs/dummy-host.serverb.com-error_log
CustomLog logs/dummy-host.serverb.com-access_log common
</VirtualHost>
修改完成后,重启httpd服务

[root@slave ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]

修改C:\Windows\System32\drivers\etc\hosts文件

末尾添加如下内容:
192.168.30.130 www.servera.com
192.168.30.130 www.serverb.com

使用物理机的IE浏览器访问测试

这里我用的Firefox查看的缓存信息,IE出了点问题,通过刷新当前页面可以查看命中缓存信息。

疑问:服务端配置两张网卡,第一次 我的eth0为VMnet4,eth1为NAT;这种情况不能连外网,不知道为什么。第二种情况是将两个顺序颠倒下就可以了。(网关写错了)

最新文章

  1. Android Studio中的CmakeList NDK配置
  2. leetcode bugfree note
  3. Android ProgressBar分析及自定义ProgressBar
  4. C++设计模式-TemplateMethod模板方法模式
  5. Orleans的单线程执行模型
  6. python和shell变量互相传递的几种方法
  7. [ CodeVS冲杯之路 ] P1092
  8. Java基础:Collection—List&amp;Set
  9. 【整理】各种Python的IDE(集成开发环境)的总结和对比
  10. 懒人神器之T4模板
  11. Linux系统编程(15)——shell脚本语法
  12. 带你走近AngularJS 之创建自定义指令
  13. web前端工程师技能总结
  14. Cocos2d-x 详解坐标系统
  15. Java求素数时出现错误
  16. 适用于 Android 的 Visual Studio 模拟器
  17. [Swift]LeetCode963. 最小面积矩形 II | Minimum Area Rectangle II
  18. FPGA配置OV5640摄像头及RGB图像数据采集
  19. Appium日志乱码终结指北
  20. SpringBoot使用HttpClient远程调用

热门文章

  1. C# delegate Action&lt;T&gt; lambda表达式
  2. 分析PHP的include机制
  3. golang基础-WaitGroup、kafka消费者
  4. mysql表分区 partition
  5. SDIO卡 了解
  6. uCos临界区保护
  7. date 命令 时间戳到标准格式转换
  8. 分享一个好用的函数吧,将js中的对象转成url参数
  9. uses-permission和permission详解
  10. SPOJ:Bits. Exponents and Gcd(组合数+GCD)