Skip to content

Instantly share code, notes, and snippets.

@cornradio
Last active January 10, 2025 09:42
Show Gist options
  • Save cornradio/2dfba47043391249a2cf3a52d07eaf36 to your computer and use it in GitHub Desktop.
Save cornradio/2dfba47043391249a2cf3a52d07eaf36 to your computer and use it in GitHub Desktop.
squid_install.sh 允许任何地址访问、访问任何端口、允许转发。
#!/bin/bash
# 确保脚本以root权限运行
if [ "$EUID" -ne 0 ]; then
echo "请以root用户或使用sudo运行此脚本"
exit 1
fi
# 检测操作系统类型
if [[ $(grep -oP '(?<=^NAME=")[^"]*' /etc/os-release) =~ "Ubuntu" ]]; then
# Ubuntu 系统
sudo apt-get update && sudo apt-get install -y squid
elif [[ $(grep -oP '(?<=^NAME=")[^"]*' /etc/os-release) =~ "CentOS" ]]; then
# CentOS 系统
sudo yum update && sudo yum install -y squid
else
echo "Unsupported OS detected!"
exit 1
fi
# 备份原始配置文件
cp /etc/squid/squid.conf /etc/squid/squid.conf.bak
# 编辑配置文件
echo "
# 允许所有来源访问(根据需求调整)
acl all src all
http_access allow all
# 监听端口
http_port 9990
# 缓存刷新策略(根据实际需求调整)
refresh_pattern . 0 20% 4320
" > /etc/squid/squid.conf
# 重启Squid服务
systemctl restart squid
echo "Squid已安装并配置完成 运行端口 9990 。
现在允许任何地址访问、访问任何端口、允许转发。
查看服务状态使用:systemctl status squid "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment