准备实例的配置文件以及服务控制脚本 ```csharp cp /etc/squid/squid.conf /etc/squid/squid-dg.conf cp /etc/squid/squid.conf /etc/squid/squid-hk.conf cp /lib/systemd/system/squid.service /lib/systemd/system/squid-dg.service cp /lib/systemd/system/squid.service /lib/systemd/system/squid-hk.service ``` 修改实例配置 ```csharp nano /etc/squid/squid-dg.conf ``` dg简单的配置 ```csharp http_port 3129 pid_filename /run/squid-dg.pid access_log /var/log/squid/access-dg.log cache_log /var/log/squid/cache-dg.log ``` ```csharp nano /etc/squid/squid-hk.conf ``` hk简单的配置 ```csharp http_port 3129 pid_filename /run/squid-hk.pid access_log /var/log/squid/access-hk.log cache_log /var/log/squid/cache-hk.log ``` 复杂版的配置内容 ```csharp # =================================== MODE ==== # http proxy 监听端口， Server 的 Connect To 选项指向此端口 http_port 127.0.0.1:3128 #如果从远端过来的代理，这里就需要监控外网IP和端口 #http_port 8.8.8.8:3128 # =================================== ACCESS CONTROL ==== # 接受所有 http 请求（来自 127.0.0.1） http_access allow all #远端允许访问Squid的IP地址，多个IP用空格间隔 #acl myacl src 1.1.1.1 2.2.2.2 #http_access allow myacl # =================================== CONNECTION ==== connect_timeout 30 seconds # 连接超时 visible_hostname squid_FP_1 # 当前节点本机名称 client_persistent_connections on # 启用 client squid 之间的长连接支持 client_idle_pconn_timeout 180 minutes #client squid 之间的长连接空闲超时 half_closed_clients on # 允许 TCP 四次挥手过程中的半双工状态 server_persistent_connections on # 启用 squid server 之间的长连接支持 server_idle_pconn_timeout 180 minute # squid server 之间的长连接空闲超时 forwarded_for transparent # 不添加、不修改也不删除 X-Forwarded-For 头（默认添加） cache deny all # squid 3.x 不能正确缓存 gzip+chuncked 内容 # =================================== LOG FILE ==== pid_filename /run/squid-dg.pid access_log none #access_log daemon:/var/log/squid/access.log squid cache_store_log none ``` 修改实例服务控制脚本 ```csharp nano /lib/systemd/system/squid-dg.service ``` dg配置内容 ```csharp ## Copyright (C) 1996-2022 The Squid Software Foundation and contributors ## ## Squid software is distributed under GPLv2+ license and includes ## contributions from numerous individuals and organizations. ## Please see the COPYING and CONTRIBUTORS files for details. ## [Unit] Description=Squid Web Proxy Server Documentation=man:squid(8) After=network.target network-online.target nss-lookup.target [Service] Type=notify PIDFile=/run/squid-dg.pid Group=proxy RuntimeDirectory=squid RuntimeDirectoryMode=0775 ExecStartPre=/usr/sbin/squid --foreground -z ExecStart=/usr/sbin/squid --foreground -sYC -f /etc/squid/squid-dg.conf ExecReload=/bin/kill -HUP $MAINPID KillMode=mixed NotifyAccess=all [Install] WantedBy=multi-user.target ``` ```csharp nano /lib/systemd/system/squid-hk.service ``` hk配置内容 ```csharp ## Copyright (C) 1996-2022 The Squid Software Foundation and contributors ## ## Squid software is distributed under GPLv2+ license and includes ## contributions from numerous individuals and organizations. ## Please see the COPYING and CONTRIBUTORS files for details. ## [Unit] Description=Squid Web Proxy Server Documentation=man:squid(8) After=network.target network-online.target nss-lookup.target [Service] Type=notify PIDFile=/run/squid-hk.pid Group=proxy RuntimeDirectory=squid RuntimeDirectoryMode=0775 ExecStartPre=/usr/sbin/squid --foreground -z ExecStart=/usr/sbin/squid --foreground -sYC -f /etc/squid/squid-hk.conf ExecReload=/bin/kill -HUP $MAINPID KillMode=mixed NotifyAccess=all [Install] WantedBy=multi-user.target ``` 重载服务使配置生效 ```csharp systemctl daemon-reload ``` 启动服务并配置服务自启动 ```csharp systemctl start squid-dg squid-hk systemctl status squid-dg squid-hk systemctl enable squid-dg squid-hk ```