yum -y install gcc-c++ net-snmp net-snmp-utils libtool
tar zxvf squid-3.3.1.tar.gz
cd squid-3.3.1
./configure --prefix=/usr/local/squid --with-filedescriptors=20480 --enable-default-err-language="Simplify_Chinese"
--prefix=/squid这里为squid的安装目录
--enable-kill-parent-hack关掉squid进程时连同父进程也一起关掉(enable表示开启此项功能,disable则表示关闭)
--enable-large-cache-files支持大的缓存文件
--with-large-files支持大的文件
--with-maxfd=344800覆盖的最大数量的filedescriptors
--enable-snmp简单网络管理协议(SNMP)是监视网络设备和服务器的流行方法。该选项导致编译过程去编译所有的SNMP相关的代码,包括一个裁切版本的CMU SNMP库
--disable-ident-lookups ident是一个简单的协议允许服务器利用客户端的特殊TCP连接来发现用户
--enable-carp Cache数组路由协议(CARP)用来转发丢失的cache到父cache的数组或cluster
--enable-async-io=160同步I/O是squid技术之一,用以提升存储性能。aufs模块使用大量的线程来执行磁盘I/O操作。该代码仅仅工作在linux和solaris系统中。=N_THREADS参数改变squid使用的线程数量 此处Io是有瓶颈限制的
----enable-storeio=ufs,aufs,diskd,null,coss Squid支持大量的不同存储模块。通过使用该选项,你告诉squid编译时使用哪个模块
--enable-epoll支持epoll的IO模式,2.6以上内核才具有
--enable-linux-netfilter netfilter是linux内核的包过滤器的名字
--enable-stacktraces某些系统支持在程序崩溃时,自动产生数据追踪。当你激活该功能后,如果squid崩溃,数据追踪信息被写到cache.log文件。这些信息对开发和程序bug调试有用
--enable-forward-log支持实验forward-log指令
--enable-referer-log该选项激活来自客户请求的HTTP referer日志
--enable-useragent-log该选项激活来自客户请求的HTTP用户代理头的日志
--enable-delay-pools延时池是squid用于传输形状或带宽限制的技术。该池由大量的客户端IP地址组成。当来自这些客户端的请求处于cache丢失状态,他们的响应可能被人工延迟
--enable-follow-x-forwarded-for当一个请求被另一些代理服务器转发时通过从http头中寻找X-Forwarded-For来发现直接或间接的客户端的IP地址
--enable-forw-via-db 支持forw/via数据库
--enable-default-err-language=Simplify_Chinese 该选项设置error_directory指令的默认值
--enable-err-languages="Simplify_Chinese English" squid支持定制错误消息,错误消息可以用多种语言报告。该选项指定复制到安装目录($prefix/share/errors)的语言
--without-system-md5不使用md5加密算法
--disable-internal-dns squid源代码包含两个不同的DNS解决方案,叫做“内部的”和“外部的”。内部查询是默认的,但某些人可能要使用外部技术。该选项禁止内部功能,转向使用旧的方式
4、修改目录权限
chown -R nobody:nobody /usr/local/squid/var
5、编辑 /usr/local/squid/etc/squid.conf
添加:
cache_peer 机器的IP parent 81 0 no-query originserver # 我的httpd端口是81
cache_dir ufs /usr/local/squid/var/cache 50000 16 256
查找 http_port 3128 替换为 http_port 80 transparent
查找 http_access deny all 替换为 http_access allow all
5、创建缓存目录
/usr/local/squid/sbin/squid -z
6、然后启动squid,测试一下是否成功
/usr/local/squid/sbin/squid -NCd1
如果访问的时候出现: clientNatLookup: NF getsockopt(SO_ORIGINAL_DST) failed: (92) Protocol not available
解决办法 执行命令: modprobe ip_conntrack
用ie测试一下,http://localhost,如果能看到中文的拒绝访问错误提示,就说明安装正确,并且已经使用.
以后就可以直接/usr/local/squid/sbin/squid & 后台运行即可。
iptables规则的查看、添加、删除和修改
1、查看
iptables -nvL –line-number
-L 查看当前表的所有规则,默认查看的是filter表,如果要查看NAT表,可以加上-t NAT参数
-n 不对ip地址进行反查,加上这个参数显示速度会快很多
-v 输出详细信息,包含通过该规则的数据包数量,总字节数及相应的网络接口
–line-number 显示规则的序列号,这个参数在删除或修改规则时会用到
2、添加
添加规则有两个参数:-A和-I。其中-A是添加到规则的末尾;-I可以插入到指定位置,没有指定位置的话默认插入到规则的首部。
当前规则:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.4 0.0.0.0/0
添加一条规则到尾部:
[root@test ~]# iptables -A INPUT -s 192.168.1.5 -j DROP
再插入一条规则到第三行,将行数直接写到规则链的后面:
[root@test ~]# iptables -I INPUT 3 -s 192.168.1.3 -j DROP
查看:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.3 0.0.0.0/0
4 DROP all -- 192.168.1.4 0.0.0.0/0
5 DROP all -- 192.168.1.5 0.0.0.0/0
可以看到192.168.1.3插入到第三行,而原来的第三行192.168.1.4变成了第四行。
3、删除
删除用-D参数
删除之前添加的规则(iptables -A INPUT -s 192.168.1.5 -j DROP):
[root@test ~]# iptables -D INPUT -s 192.168.1.5 -j DROP
有时候要删除的规则太长,删除时要写一大串,既浪费时间又容易写错,这时我们可以先使用–line-number找出该条规则的行号,再通过行号删除规则。
[root@test ~]# iptables -nv --line-number
iptables v1.4.7: no command specified
Try `iptables -h' or 'iptables --help' for more information.
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.3 0.0.0.0/0
删除第二行规则
[root@test ~]# iptables -D INPUT 2
4、修改
修改使用-R参数
先看下当前规则:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.5 0.0.0.0/0
将第三条规则改为ACCEPT:
[root@test ~]# iptables -R INPUT 3 -j ACCEPT
再查看下:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
第三条规则的target已改为ACCEPT。
tar zxvf squid-3.3.1.tar.gz
cd squid-3.3.1
./configure --prefix=/usr/local/squid --with-filedescriptors=20480 --enable-default-err-language="Simplify_Chinese"
--prefix=/squid这里为squid的安装目录
--enable-kill-parent-hack关掉squid进程时连同父进程也一起关掉(enable表示开启此项功能,disable则表示关闭)
--enable-large-cache-files支持大的缓存文件
--with-large-files支持大的文件
--with-maxfd=344800覆盖的最大数量的filedescriptors
--enable-snmp简单网络管理协议(SNMP)是监视网络设备和服务器的流行方法。该选项导致编译过程去编译所有的SNMP相关的代码,包括一个裁切版本的CMU SNMP库
--disable-ident-lookups ident是一个简单的协议允许服务器利用客户端的特殊TCP连接来发现用户
--enable-carp Cache数组路由协议(CARP)用来转发丢失的cache到父cache的数组或cluster
--enable-async-io=160同步I/O是squid技术之一,用以提升存储性能。aufs模块使用大量的线程来执行磁盘I/O操作。该代码仅仅工作在linux和solaris系统中。=N_THREADS参数改变squid使用的线程数量 此处Io是有瓶颈限制的
----enable-storeio=ufs,aufs,diskd,null,coss Squid支持大量的不同存储模块。通过使用该选项,你告诉squid编译时使用哪个模块
--enable-epoll支持epoll的IO模式,2.6以上内核才具有
--enable-linux-netfilter netfilter是linux内核的包过滤器的名字
--enable-stacktraces某些系统支持在程序崩溃时,自动产生数据追踪。当你激活该功能后,如果squid崩溃,数据追踪信息被写到cache.log文件。这些信息对开发和程序bug调试有用
--enable-forward-log支持实验forward-log指令
--enable-referer-log该选项激活来自客户请求的HTTP referer日志
--enable-useragent-log该选项激活来自客户请求的HTTP用户代理头的日志
--enable-delay-pools延时池是squid用于传输形状或带宽限制的技术。该池由大量的客户端IP地址组成。当来自这些客户端的请求处于cache丢失状态,他们的响应可能被人工延迟
--enable-follow-x-forwarded-for当一个请求被另一些代理服务器转发时通过从http头中寻找X-Forwarded-For来发现直接或间接的客户端的IP地址
--enable-forw-via-db 支持forw/via数据库
--enable-default-err-language=Simplify_Chinese 该选项设置error_directory指令的默认值
--enable-err-languages="Simplify_Chinese English" squid支持定制错误消息,错误消息可以用多种语言报告。该选项指定复制到安装目录($prefix/share/errors)的语言
--without-system-md5不使用md5加密算法
--disable-internal-dns squid源代码包含两个不同的DNS解决方案,叫做“内部的”和“外部的”。内部查询是默认的,但某些人可能要使用外部技术。该选项禁止内部功能,转向使用旧的方式
4、修改目录权限
chown -R nobody:nobody /usr/local/squid/var
5、编辑 /usr/local/squid/etc/squid.conf
添加:
cache_peer 机器的IP parent 81 0 no-query originserver # 我的httpd端口是81
cache_dir ufs /usr/local/squid/var/cache 50000 16 256
查找 http_port 3128 替换为 http_port 80 transparent
查找 http_access deny all 替换为 http_access allow all
5、创建缓存目录
/usr/local/squid/sbin/squid -z
6、然后启动squid,测试一下是否成功
/usr/local/squid/sbin/squid -NCd1
如果访问的时候出现: clientNatLookup: NF getsockopt(SO_ORIGINAL_DST) failed: (92) Protocol not available
解决办法 执行命令: modprobe ip_conntrack
用ie测试一下,http://localhost,如果能看到中文的拒绝访问错误提示,就说明安装正确,并且已经使用.
以后就可以直接/usr/local/squid/sbin/squid & 后台运行即可。
iptables规则的查看、添加、删除和修改
1、查看
iptables -nvL –line-number
-L 查看当前表的所有规则,默认查看的是filter表,如果要查看NAT表,可以加上-t NAT参数
-n 不对ip地址进行反查,加上这个参数显示速度会快很多
-v 输出详细信息,包含通过该规则的数据包数量,总字节数及相应的网络接口
–line-number 显示规则的序列号,这个参数在删除或修改规则时会用到
2、添加
添加规则有两个参数:-A和-I。其中-A是添加到规则的末尾;-I可以插入到指定位置,没有指定位置的话默认插入到规则的首部。
当前规则:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.4 0.0.0.0/0
添加一条规则到尾部:
[root@test ~]# iptables -A INPUT -s 192.168.1.5 -j DROP
再插入一条规则到第三行,将行数直接写到规则链的后面:
[root@test ~]# iptables -I INPUT 3 -s 192.168.1.3 -j DROP
查看:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.3 0.0.0.0/0
4 DROP all -- 192.168.1.4 0.0.0.0/0
5 DROP all -- 192.168.1.5 0.0.0.0/0
可以看到192.168.1.3插入到第三行,而原来的第三行192.168.1.4变成了第四行。
3、删除
删除用-D参数
删除之前添加的规则(iptables -A INPUT -s 192.168.1.5 -j DROP):
[root@test ~]# iptables -D INPUT -s 192.168.1.5 -j DROP
有时候要删除的规则太长,删除时要写一大串,既浪费时间又容易写错,这时我们可以先使用–line-number找出该条规则的行号,再通过行号删除规则。
[root@test ~]# iptables -nv --line-number
iptables v1.4.7: no command specified
Try `iptables -h' or 'iptables --help' for more information.
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.3 0.0.0.0/0
删除第二行规则
[root@test ~]# iptables -D INPUT 2
4、修改
修改使用-R参数
先看下当前规则:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.5 0.0.0.0/0
将第三条规则改为ACCEPT:
[root@test ~]# iptables -R INPUT 3 -j ACCEPT
再查看下:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
第三条规则的target已改为ACCEPT。