服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|

服务器之家 - 服务器系统 - Centos - centos下简单配置安装Squid 3.0反向代理

centos下简单配置安装Squid 3.0反向代理

2021-03-19 01:42CentOS教程网 Centos

以下安装及配置均为Sudu所在公司应用中使用的脚本,希望高手们能指正我的一些不足。如果测试过程中发现了问题请回复或者联系我。

安装篇:

本教程应用环境为干净centos 5.5 ,预先分好并加载/data分区,并且关闭selinux及iptables

首先修改文件描述符并设定临时端口范围,这些设置重启后生效

复制代码 代码如下:

cat >> /etc/security/limits.conf <<DDD
* soft nofile 8192
* hard nofile 20480
DDD

cat >> /etc/sysctl.conf <<DDD
#set temp port range
net.ipv4.ip_local_port_range = 32768 61000
DDD

init 6


确认修改是否正确

复制代码 代码如下:

[root@sudutest ~]# ulimit -n
8192
[root@suduotest ~]# sysctl -n net.ipv4.ip_local_port_range
net.ipv4.ip_local_port_range = 32768 61000


添加squid专用账户

复制代码 代码如下:

groupadd squid
useradd -g squid -s /bin/false -M squid


添加日志目录、设置缓存和日志目录的权限

复制代码 代码如下:

mkdir /data/squidlog/
chown -R squid.squid /data


然后上传或者wget squid3.0软件tar包,tar zxvf解压,并且进入解压后的目录安装编译

复制代码 代码如下:

./configure –prefix=/usr/local/squid3 –enable-async-io=100 –with-pthreads –enable-storeio="aufs,diskd,ufs" –enable-removal-policies="heap,lru" –enable-icmp –enable-delay-pools –enable-useragent-log –enable-referer-log –enable-kill-parent-hack –enable-arp-acl –enable-default-err-language=Simplify_Chinese –enable-err-languages="Simplify_Chinese English" –disable-poll –disable-wccp –disable-wccpv2 –disable-ident-lookups –disable-internal-dns –enable-basic-auth-helpers="NCSA" –enable-stacktrace –with-large-files –disable-mempools –with-filedescriptors=65535 –enable-ssl –enable-x-accelerator-var
make
make install
make install-pinger


至此squid已经成功安装了,然后大家自己所需的/usr/local/squid3/etc/squid.conf 配置文件,我这边的配置文件将会在本文末尾贴出来供大家研究。

写好配置文件后执行下面的命令初始化cache目录
/usr/local/squid3/sbin/squid -z
然后运行squid,注:-D参数用来跳过DNS检测
/usr/local/squid3/sbin/squid -D
最后设置squid开机自动启动
echo "/usr/local/squid3/sbin/squid -D " >>/etc/rc.local
维护篇:

以下是squid常用的命令
如果修改过配置文件,则用下面的命令重读配置文件(即时生效)
/usr/local/squid3/sbin/squid -k reconfigure
检查配置文件配置的语法是否正确
注:只有像这样的“cache_cf.cc(346) squid.conf:14 unrecognized: 'http1_port'”才是语法错误,
“WARNING: use of 'reload-into-ims'……”这类提示属于意见建议,可以忽略。
/usr/local/squid3/sbin/squid -k parse
查看squid的日志和进程,看squid运行是否正常

复制代码 代码如下:

ps -ef |awk '/^squid/'
cat /data/squidlog/cache.log
/usr/local/squid3/sbin/squid -k check ;echo $?


关闭squid
发出关闭信号,等会话结束后彻底关闭
/usr/local/squid3/sbin/squid -k shutdown
关闭squid(更高优先级,直接关闭squid)
/usr/local/squid3/sbin/squid -k interrupt

关闭squid(最高优先级,直接杀死squid进程)
/usr/local/squid3/sbin/squid -k kill
滚动日志文件
/usr/local/squid3/sbin/squid -k rotate
设置每周二凌晨四点30分自动滚动日志


echo "30 4 * * 2 root /usr/local/squid3/sbin/squid -k rotate " >>/etc/crontab

目前应用中的squid.conf文件,由于日志文件增长很快,所以直接输出到/dev/null丢弃掉了

复制代码 代码如下:

#basic
cache_effective_user squid
cache_effective_group squid
pid_filename /usr/local/squid3/var/logs/squid.pid
visible_hostname squid.678114.com
cache_mgr sudu@sudu.us
error_directory /usr/local/squid3/share/errors/Simplify_Chinese
icon_directory /usr/local/squid3/share/icons
mime_table /usr/local/squid3/etc/mime.conf
hosts_file /etc/hosts

acl DEIpadd dstdom_regex [0-9]$
http_access deny DEIpadd

cache_replacement_policy lru
memory_replacement_policy lru

http_port 80 vhost vport

cache_mem 4024 MB
maximum_object_size_in_memory 5120 KB

icp_port 0

#.cache_dir
cache_dir aufs /data/cache 50000 64 128

max_open_disk_fds 0
maximum_object_size 20 MB

#.cache_peer
cache_peer 125.76.225.44 parent 80 0 no-query originserver no-digest name=all
cache_peer_domain all .678114.com

#acl
acl Safe_ports port 80
acl SSL_ports port 443
acl LanSrc src 192.168.100.0/24
acl webdomain dstdomain .678114.com
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow LanSrc
http_access allow webdomain
http_access deny all

#refresh_pattern
refresh_pattern -i /$ 15 90% 600 reload-into-ims
refresh_pattern -i .html$ 15 90% 600 reload-into-ims
refresh_pattern -i .htm$ 15 90% 600 reload-into-ims
refresh_pattern -i .shtml$ 15 90% 600 reload-into-ims
refresh_pattern -i .hml$ 15 90% 600 reload-into-ims
refresh_pattern -i .gif$ 1440 90% 129600 reload-into-ims
refresh_pattern -i .swf$ 1440 90% 129600 reload-into-ims
refresh_pattern -i .jpg$ 1440 90% 129600 reload-into-ims
refresh_pattern -i .png$ 1440 90% 129600 reload-into-ims
refresh_pattern -i .bmp$ 1440 90% 129600 reload-into-ims
refresh_pattern -i .js$ 120 90% 129600 reload-into-ims
refresh_pattern -i .css$ 120 90% 129600 reload-into-ims
refresh_pattern -i .wma$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .zip$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .mp3$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .rar$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .rm$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .flv$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .rar$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .rm$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .avi$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .3gp$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .mp4$ 1440 90% 21600 reload-into-ims
refresh_pattern -i .wmv$ 1440 90% 21600 reload-into-ims

#keepalived
client_persistent_connections off
server_persistent_connections on

#log
emulate_httpd_log on
logformat web1 %{X-Forwarded-For}>h %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
cache_log /data/squidlog/cache.log
cache_access_log /dev/null web1
cache_store_log /dev/null
strip_query_terms off
logfile_rotate 10

#other
forwarded_for on
log_icp_queries off
via off
httpd_suppress_version_string off
ie_refresh off
tcp_recv_bufsize 32 KB
ipcache_size 1024
ipcache_low 90
ipcache_high 95
cache_swap_low 80
cache_swap_high 90
request_header_max_size 128 KB

quick_abort_min 20 KB
quick_abort_max 20 KB
quick_abort_pct 95

connect_timeout 1 minute
negative_ttl 0 minutes

read_timeout 30 seconds
pconn_timeout 120 seconds
half_closed_clients off
client_lifetime 10 minutes
shutdown_lifetime 5 seconds

hierarchy_stoplist cgi-bin ?
access_log /dev/null squid


本文首发于http://www.sudu.us/simple-to-install-squid-3-0-reverse-proxy-configuration/

延伸 · 阅读

精彩推荐
  • CentosCentOS 7 源码编译安装Python3.9

    CentOS 7 源码编译安装Python3.9

    在CentOS7上默认的Python版本还是python2,如果需要Python3就需要安装第三方源,或者使用源码安装。 ...

    linux运维菜7372021-01-05
  • CentosCentos怎么更新系统? Centos系统怎么更新补丁?

    Centos怎么更新系统? Centos系统怎么更新补丁?

    本文介绍centos如何更新系统及补丁,希望对您有所帮助。 1、如果安装的是图形化界面,则点击左上角:应用程序--系统工具--软件更新,如图所示可以看到...

    百度经验8682019-10-17
  • CentosCentOS中使用Yum把MySQL平滑迁移到MariaDB

    CentOS中使用Yum把MySQL平滑迁移到MariaDB

    这篇文章主要介绍了CentOS中使用Yum把MySQL平滑迁移到MariaDB,本文使用YUM实现,安装一个MariaDB 的安装源即可,需要的朋友可以参考下 ...

    CentOS之家1982019-09-20
  • Centoscentos系统怎么查看软件安装路径?

    centos系统怎么查看软件安装路径?

    centos系统怎么查看软件安装路径?Linux系统一般都是命令行界面,对于安装的软件也是通过命令安装的。对于软件包更新和卸载等有时候需要查看检查是否...

    开源中国4652019-09-11
  • Centoscentos6.6下如何安装GreenPlum4.3.5.2?

    centos6.6下如何安装GreenPlum4.3.5.2?

    一些朋友在问centos6.6下如何安装GreenPlum4.3.5.2?下面小编将为大家带来centos6.6下安装GreenPlum4.3.5.2的教程!希望能够帮助到大家!有需要的朋友一起去看看吧...

    脚本之家3132019-06-02
  • Centos如何配置Centos 6.5 的yum源?

    如何配置Centos 6.5 的yum源?

    如何配置Centos,6.5,的yum源?Linux系统一定会用到一个源安装软件库无论是使用哪一个版本的,下面我与大家分享一下如何配置Centos 6.5 的yum源,需要的朋友可...

    百度经验6732019-09-24
  • CentosCentOS如何备份策略?CentOS备份策略的方法

    CentOS如何备份策略?CentOS备份策略的方法

    很多朋友不知道CentOS如何备份策略?今天小编将为大家带来CentOS备份策略的方法;希望可以帮助到大家,有需要的朋友一起去看看吧...

    服务器之家3892019-06-20
  • Centoscentos中lvs安装配置方法详解

    centos中lvs安装配置方法详解

    c本文主要介绍了centos中lvs安装配置的方法,以下所有操作需关闭selinx和iptables,大家参考使用吧 ...

    centos教程网3232019-09-29