Squid代理服务配置

推荐步骤:
客户端安装elinks安装apache服务
配置代理服务器 安装squid,创建管理squid的用户
配置传统代理、设置linux客户端配置代理
查看apache服务访问日志
配置透明代理

 配置sarg日志分析工具

客户端安装

[root@centos01 ~]# yum -y install elinks

安装apache服务

root@centos03 ~]# yum -y install httpd

写入测试文件

[root@centos03 html]# echo “www.benet.com” > index.html

[root@centos03 html]# ls

index.html

启动httpd服务

[root@centos03 html]# systemctl start httpd

在这里插入图片描述

配置代理服务器

安装squid,创建管理squid的用户

[root@centos02 mnt]# useradd -M -s /sbin/nologin squid

配置squid

root@centos02 ~]# tar zxvf /mnt/squid-3.4.6.tar.gz -C /usr/src/

root@centos02 ~]#cd /usr/src/squid-3.4.6/

[root@centos02 squid-3.4.6]# ./configure --prefix=/usr/local/squid --sysconfdir=/etc --enable-linux-netfilter --enable-async-io=240 --enable-default-err-language=Simplify_Chinese
–disable-poll --enable-epoll --enable-gnuregex

编译安装squid

[root@centos02 squid-3.4.6]# make && make install

优化squid命令

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

创建squid管理服务脚本,添加执行权限

[root@centos02 ~]# vim /etc/init.d/squid

#!/bin/bash

#chkconfig: 35 90 25

#config file:/etc/squid.conf

#pidfile:
/usr/local/squid/var/run/squid.pid

#Description: Squid - Internet object
cache.

PID="/usr/local/squid/var/run/squid.pid"

CONF="/etc/squid.conf"

CMD="/usr/local/squid/sbin/squid"

case “$1” in

start)

netstat -anpt | grep squid
&> /dev/null

if [ $? -eq 0 ]

then

echo “squid is running”

else

echo “正在启动squid…”

$CMD

fi

;;

stop)

$CMD -k kill &> /dev/null

rm -rf $PID &> /dev/null

echo “正在关闭squid…”

;;

startus)

[ -f $PID ] &> /dev/null

if [ $? -eq 0 ]

then

netstat -anpt | grep squid

else

echo “Squid is not running.”

fi

;;

restart)

$0 stop &> /dev/null

echo “正在关闭squid…”

$0 start &> /dev/null

echo “正在启动squid…”

;;

reload)

$CMD -k reconfigure

;;

check)

$CMD -k parse

;;

*)

echo “用法: $0
{start|stop|restart|reload|check|status}”

exit 1

;;

esac

[root@centos02 ~]# chmod +x /etc/init.d/squid

添加系统服务设置开机自动启动

[root@centos02 ~]# chkconfig --add squid

[root@centos02 ~]# chkconfig --level 35 squid on

修改squit目录的所有者

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

配置传统代理

备份主配置文件

root@centos02 ~]# cp /etc/squid.conf /etc/squid.conf.bak

修改主配置文件

[root@centos02 ~]# vim /etc/squid.conf
在这里插入图片描述

检查配置文件语法

[root@centos02 ~]# squid -k parse

启动squid服务

[root@centos02 ~]# /etc/init.d/squid start

[root@centos02 ~]# squid

[root@centos02 ~]# netstat -anptu | grep 3128
在这里插入图片描述

设置linux客户端配置代理

[root@centos01 ~]# vim /etc/profile

HTTP_PROXY=http://192.168.100.20:3128

HTTPS_PROXY=http://192.168.100.20:3128

FTP_PROXY=http://192.168.100.20:3128

NO_PROXY=http://192.168.100.20:3128

export HTTP_PROXY HTTPS_PROXY FTP_PROXY
NO_PROXY

查看apache服务访问日志

[root@centos03 ~]# tail -f /var/log/httpd/access_log

[root@centos01 ~]# source /etc/profile

[root@centos01 ~]# elinks http://192.168.100.30
在这里插入图片描述

查看监控到的日志文件

在这里插入图片描述

客户端配置代理

在这里插入图片描述

在这里插入图片描述

查看监控的日志文件

在这里插入图片描述

配置透明代理

给centos02添加第二块网卡

在这里插入图片描述

给centos03更改网卡
在这里插入图片描述

在这里插入图片描述

添加网关更改IP地址

在这里插入图片描述

[root@centos02 ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens32 /etc/sysconfig/network-scripts/ifcfg-ens34

[root@centos02 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens34

在这里插入图片描述

重启网卡服务

[root@centos02 ~]# systemctl restart network

配置透明代理

配置代理服务器开启路由功能

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

net.ipv4.ip_forward = 1

[root@centos02 ~]# sysctl -p

net.ipv4.ip_forward = 1

给centos01添加DNS

在这里插入图片描述

重启网卡服务

[root@centos01 ~]# systemctl restart network

测试网络是否正常通信

在这里插入图片描述

清空默认防火墙规则

[root@centos02 ~]# iptables -F

[root@centos02 ~]# iptables -t nat -F

查看默认防火墙规则

[root@centos02 ~]# iptables -t nat -L

配置iptables防火墙规则将192.168.100.0网络的80,443,21,8080端口映射到外网的3218端口

[root@centos02 ~]# iptables -t nat -I PREROUTING -i ens32 -s 192.168.100.0/24 -p tcp --dport 80 -j REDIRECT --to 3128

[root@centos02 ~]# iptables -t nat -I PREROUTING -i ens32 -s 192.168.100.0/24 -p tcp --dport 8080 -j REDIRECT --to 3128

[root@centos02 ~]# iptables -t nat -I PREROUTING -i ens32 -s 192.168.100.0/24 -p tcp --dport 443 -j REDIRECT --to 3128

[root@centos02 ~]# iptables -t nat -I PREROUTING -i ens32 -s 192.168.100.0/24 -p tcp --dport 21 -j REDIRECT --to 3128

修改squid主配置文件支持透明代理,先关闭squid

[root@centos02 ~]# /etc/init.d/squid stop

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

http_port 192.168.100.20:3128 transparent

启动squid服务器

[root@centos02 ~]# /etc/init.d/squid start

Win7客户端配置网关

在这里插入图片描述
在这里插入图片描述

查看网站日志
在这里插入图片描述

Linux客户端访问

取消Linux系统的代理

[root@centos01 ~]# unset HTTP_PROXY HTTPS_PROXY FTP_PROXY NO_PROXY

[root@centos01 ~]# elinks http://192.168.200.30

在这里插入图片描述

查看网站服务器日志

在这里插入图片描述

配置sarg日志分析工具,将gd上传

在这里插入图片描述

在这里插入图片描述

解压gd

[root@centos02 mnt]# tar zxvf sarg-2.3.7.tar.gz -C /usr/src/

安装sary

安装依赖软件

[root@centos02 ~]# yum -y install gd gd-devel httpd

强制忽略依赖管理安装gd-devel

[root@centos02 ~]# rpm -ivh gd-devel-2.0.35-11.el6.x86_64.rpm --nodeps

配置sarg

创建安装目录

[root@centos02 ~]# mkdir /usr/local/sarg

配置sary

[root@centos02 ~]# cd /usr/src/sarg-2.3.7/

[root@centos02 sarg-2.3.7]# ./configure --prefix=/usr/local/sarg --sysconfdir=/etc/sarg --enable-extraprotection && make && make install

备份配置文件

[root@centos02 ~]# cp /etc/sarg/sarg.conf /etc/sarg/sarg.conf.bak

创建报告输出目录

[root@centos02 ~]# mkdir -p /usr/local/sarg/noreport

优化执行命令

[root@centos02 ~]# ln -s /usr/local/sarg/bin/sarg /usr/local/bin/

执行sarg执行一次性记录

在这里插入图片描述
Windows7客户端访问测试

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值