web服务通过ip访问跳转localhost_devops构建Squid代理服务器(1)安装及配置

1、配置IP地址

过程略.....

2、编译安装Squid软件

[root@localhost ~]# tar -zxvf squid-3.4.6.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/squid-3.4.6/
[root@localhost squid-3.4.6]# ./configure
--prefix=/usr/local/squid
--sysconfdir=/etc
--enable-arp-acl
--enable-linux-netfilter
--enable-linux-tproxy
--enable-sasync-io=100
--enable-err-language="Simplify_Chinese"
--enable-underscore
--enable-poll
--enable-gnuregex
[root@localhost squid-3.4.6]# make
[root@localhost squid-3.4.6]# make install

3、创建用户并优化路径

[root@localhost ~]# useradd -M -s /sbin/nologin squid

[root@localhost ~]# ln -s /usr/local/squid/sbin/* /usr/local/sbin/

[root@localhost ~]# chown -R squid:squid /usr/local/squid/var/

[root@localhost ~]# chmod -R 757 /usr/local/squid/var/

4、检查语法并启动

[root@localhost ~]# squid -k parse
[root@localhost ~]# squid -z //清楚缓存
[root@localhost ~]# squid
[root@localhost ~]# netstat -anpt | grep squid
[root@localhost ~]# echo "/usr/local/squid/sbin/squid" > /etc/rc.local

[root@localhost ~]# killall -9 squid //停止squid服务

+++++++++++配置传统代理+++++++++++

-----WEB服务器------------Squid代理----------------Clinet--------
192.168.1.1 192.168.1.10 192.168.1.100

1、修改squid.conf配置文件

[root@localhost ~]# vim /etc/squid.conf
添加:
http_port 3128
reply_body_max_size 10 MB
http_access allow all

2、重启Squid服务

[root@localhost ~]# killall -9 squid
[root@localhost ~]# squid

3、客户端设置代理

打开IE浏览器:打开“工具”---“Internet选项”。“连接”---“局域网设置”中进行设置:

IP地址:192.168.1.10 端口:3128

4、验证:

客户端client访问WEB服务器http://192.168.1.1/
1)Squid代理服务器:
[root@localhost ~]# tail -f /usr/local/squid/var/logs/access.log //客户端访问了WEB服务器
2)WEB服务器:
[root@localhost ~]# tail -f /etc/httpd/logs/access_log //Squid服务器访问了WEB服务器

+++++++++++配置透明代理+++++++++++

-----WEB服务器------------Squid代理----------------Clinet--------
9.9.9.9 eth1:9.9.9.1
eth0:192.168.1.1 192.168.1.100

1、配置IP地址

注意:指定网关
(略)

2、开启路由转发功能

[root@localhost ~]# vim /etc/sysctl.conf
修改:
net.ipv4.ip_forward = 1
[root@localhost ~]#sysctl -p

3、修改squid.conf配置文件

[root@localhost ~]# vim /etc/squid.conf
添加:
http_port 192.168.1.1:3128 transparent

4、重启Squid服务

[root@localhost ~]# killall -9 squid
[root@localhost ~]# squid

5、设置防火墙规则

[root@localhost ~]#iptables -t nat -I PREROUTING -i eth0 -s 192.168.1.0/24 -p tcp --dport 80 -j REDIRECT --to-ports 3128
[root@localhost ~]#iptables -t nat -I PREROUTING -i eth0 -s 192.168.1.0/24 -p tcp --dport 443 -j REDIRECT --to-ports 3128

6、验证:

客户端client访问WEB服务器http://9.9.9.9/
1)Squid代理服务器:
[root@localhost ~]# tail -f /usr/local/squid/var/logs/access.log //客户端访问了WEB服务器
2)WEB服务器:
[root@localhost ~]# tail -f /etc/httpd/logs/access_log //Squid服务器访问了WEB服务器

+++++++++++配置ACL+++++++++++

拒绝访问
[root@localhost ~]# vim /etc/squid.conf
添加:
acl hee src all
http_access deny hee

9953e5bf79ac86755e24bf1e4d0f5716.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值