105 lines
2.4 KiB
Markdown
105 lines
2.4 KiB
Markdown
# 东京云服务器代理方案
|
||
|
||
## 场景
|
||
国内访问 GitHub / Docker Hub 速度慢,用东京低配云服务器做流量转发。
|
||
|
||
## 服务端(东京服务器)
|
||
|
||
### 1. 安装 squid
|
||
```bash
|
||
apt update && apt install -y squid apache2-utils
|
||
```
|
||
|
||
### 2. 配置 squid(密码认证)
|
||
```bash
|
||
cat > /etc/squid/squid.conf << 'EOF'
|
||
http_port 3128
|
||
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
|
||
auth_param basic realm "Tokyo Proxy"
|
||
acl auth proxy_auth REQUIRED
|
||
http_access allow auth
|
||
http_access deny all
|
||
EOF
|
||
```
|
||
|
||
### 3. 创建用户
|
||
```bash
|
||
htpasswd -cb /etc/squid/passwd 用户名 密码
|
||
```
|
||
|
||
### 4. 重启
|
||
```bash
|
||
systemctl restart squid
|
||
systemctl enable squid
|
||
```
|
||
|
||
### 验证
|
||
```bash
|
||
ss -tlnp | grep 3128
|
||
```
|
||
|
||
---
|
||
|
||
## 国内客户端
|
||
|
||
### Docker 配置
|
||
```bash
|
||
mkdir -p /etc/systemd/system/docker.service.d
|
||
cat > /etc/systemd/system/docker.service.d/http-proxy.conf <<EOF
|
||
[Service]
|
||
Environment="HTTP_PROXY=http://用户名:密码@东京服务器IP:3128"
|
||
Environment="HTTPS_PROXY=http://用户名:密码@东京服务器IP:3128"
|
||
EOF
|
||
|
||
systemctl daemon-reload && systemctl restart docker
|
||
```
|
||
|
||
### Git 配置
|
||
```bash
|
||
git config --global http.proxy http://用户名:密码@东京服务器IP:3128
|
||
git config --global https.proxy http://用户名:密码@东京服务器IP:3128
|
||
```
|
||
|
||
### K3s (containerd) 配置
|
||
K3s 默认使用 containerd,不走 systemd代理,需要在 k3s service 环境变量中配置。
|
||
|
||
```bash
|
||
# 添加代理环境变量到 k3s service
|
||
mkdir -p /etc/systemd/system/k3s.service.d
|
||
cat > /etc/systemd/system/k3s.service.d/http-proxy.conf <<EOF
|
||
[Service]
|
||
Environment="HTTP_PROXY=http://用户名:密码@东京服务器IP:3128"
|
||
Environment="HTTPS_PROXY=http://用户名:密码@东京服务器IP:3128"
|
||
Environment="NO_PROXY=localhost,127.0.0.1,10.0.0.0/8,.svc,.cluster.local"
|
||
EOF
|
||
|
||
systemctl daemon-reload && systemctl restart k3s
|
||
```
|
||
|
||
验证:
|
||
```bash
|
||
crictl pull nginx
|
||
kubectl run nginx --image=nginx
|
||
```
|
||
|
||
### 取消代理(如需直连)
|
||
```bash
|
||
git config --global --unset http.proxy
|
||
git config --global --unset https.proxy
|
||
# Docker 删除 /etc/systemd/system/docker.service.d/http-proxy.conf 后重启
|
||
```
|
||
|
||
---
|
||
|
||
## 验证
|
||
```bash
|
||
docker pull nginx
|
||
git clone https://github.com/torvalds/linux
|
||
```
|
||
|
||
---
|
||
|
||
## 注意事项
|
||
- 东京服务器带宽低(1-2Mbps),Docker 拉大镜像较慢
|
||
- Git 流量小,代理无压力
|
||
- HTTP 代理同时支持 Git 和 Docker,无需 nginx 反代 |