48 lines
852 B
Bash
48 lines
852 B
Bash
|
|
|
|
# master节点
|
|
# 安装 squid
|
|
yum install -y squid
|
|
|
|
# 备份默认配置
|
|
cp /etc/squid/squid.conf /etc/squid/squid.conf.bak
|
|
|
|
# 编辑 /etc/squid/squid.conf
|
|
|
|
# 定义内网网段 关键!
|
|
acl localnet src 192.168.5.0/24
|
|
|
|
# 允许内网访问
|
|
http_access allow localnet
|
|
http_access allow localhost
|
|
|
|
# 监听端口
|
|
http_port 3128
|
|
|
|
# 其余保持默认,拒绝所有其他
|
|
http_access deny all
|
|
|
|
|
|
systemctl enable squid --now
|
|
|
|
# worker节点
|
|
|
|
## 编辑 /etc/yum.conf
|
|
|
|
[main]
|
|
# ... 其他配置 ...
|
|
proxy=http://192.168.5.41:3128
|
|
|
|
|
|
# 在客户端节点执行
|
|
yum makecache
|
|
yum install -y wget
|
|
|
|
|
|
# 直接执行
|
|
sed -n '/^proxy=/ {p;q}; $ {a proxy=http://192.168.5.41:3128' -e 'p}' /etc/yum.conf
|
|
|
|
# 批量执行
|
|
ssh root@${server} "grep -q '^proxy=' /etc/yum.conf && grep '^proxy=' /etc/yum.conf || echo 'proxy=http://192.168.5.41:3128' >> /etc/yum.conf"
|
|
|