如何配实现Squid多开实例同时运行?
- By : Will
- Category : Forward Proxy
Forward Proxy
1 前言
一个问题,一篇文章,一出故事。
笔者整理本文的原因是遇到Squid遇到需要在同一台服务器启动两个以上的Squid实例的情况,两个实例使用不同的端口同时对外提供服务。
本章基于你已经有以下基础配置实现,
2 最佳实践
2.1 准备实例的配置文件以及服务控制脚本
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
2.2 修改实例配置
vim /etc/squid/squid-dg.conf
以上命令使用VIM编辑DG节点实例,增加如下配置,
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
以下使用VIM命令编辑HK节点实例,
vim /etc/squid/squid-hk.conf
增加如下配置,
http_port 3130 pid_filename /run/squid-hk.pid access_log /var/log/squid/access-hk.log cache_log /var/log/squid/cache-hk.log
2.3 修改实例服务控制脚本
vim /lib/systemd/system/squid-dg.service
以上命令使用VIM编辑DG节点实例,增加如下配置,
## 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
以下使用VIM命令编辑HK节点实例,
vim /lib/systemd/system/squid-hk.service
增加如下配置,
## 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
2.4 重载服务使配置生效
systemctl daemon-reload
2.5 启动服务并配置服务自启动
systemctl start squid-dg squid-hk systemctl status squid-dg squid-hk systemctl enable squid-dg squid-hk
2.6 测试实例
export proxy='http://127.0.0.1:3129' export http_proxy="$proxy" export https_proxy="$proxy" export ftp_proxy="$proxy" export no_proxy="cmdschool.org localhost, 127.0.0.1, ::1" curl https://www.baidu.com
以上通过Shell设置代理指向DG实例然后使用CURL命令测试,以下命令用于测试HK实例,
export proxy='http://127.0.0.1:3130' export http_proxy="$proxy" export https_proxy="$proxy" export ftp_proxy="$proxy" export no_proxy="cmdschool.org localhost, 127.0.0.1, ::1" curl https://www.baidu.com
参阅文档
===================
https://blog.csdn.net/robinspada/article/details/124163818
没有评论