[Server] 服务器搭建 Clash [DEPRECATED]
Categories Server
Tags
被京东云检测到
clash进程警告了…
背景
实在是有点没办法忍受 Docker 镜像站的限流了,Portainer BE 有自动获取镜像更新状态的功能,用了几次直接干限流了,获取不了状态还会导致 Portainer 卡到爆。今天下午突然觉得还是直接在服务器上部署 Clash 吧。
.ssh/config
在 VS Code 的配置文件中
Host Eagle233-JDCloud
HostName eagle233.top
User eagle233
IdentityFile ~/.ssh/id_rsa.pem
IdentitiesOnly yes
# RemoteForward 7890 127.0.0.1:20660
如上,不再需要本地 Clash 代理
.bashrc
# SSH Proxy
if nc -z 127.0.0.1 7890 >/dev/null 2>&1; then
export http_proxy="http://127.0.0.1:7890"
export https_proxy="http://127.0.0.1:7890"
export all_proxy="socks5://127.0.0.1:7890"
echo "Terminal proxy enabled via Docker Clash (127.0.0.1:7890)"
else
unset http_proxy
unset https_proxy
unset all_proxy
fi
docker-compose.yml
在 Portainer 设置好 Stack
services:
clash:
image: dreamacro/clash:latest
container_name: clash
restart: always
networks:
- clash-net
volumes:
- /home/eagle233/clash/config.yaml:/root/.config/clash/config.yaml
ports:
- "127.0.0.1:7890:7890/tcp"
- "0.0.0.0:9900:9090/tcp"
clash-yacd:
image: haishanh/yacd
container_name: clash-yacd
restart: always
networks:
- clash-net
ports:
- "9901:80"
networks:
clash-net:
driver: bridge
name: clash-net
实测由于 yacd 是 HTTPS,而服务器上的 clash 是 HTTP,无法连接,因此只能本地部署一个 yacd。
Makefile
SUB_URL = "your_url"
CONFIG_FILE = config.yaml
SECRET = 'STRONGPWD'
.PHONY: update restart
update:
@echo "Updating..."
@curl -s -L $(SUB_URL) -o $(CONFIG_FILE).tmp
@sed -i '/^port:/d' $(CONFIG_FILE).tmp
@sed -i '/^socks-port:/d' $(CONFIG_FILE).tmp
@sed -i '/^mixed-port:/d' $(CONFIG_FILE).tmp
@sed -i '/^secret:/d' $(CONFIG_FILE).tmp
@sed -i '/^external-controller:/d' $(CONFIG_FILE).tmp
@sed -i '/^allow-lan:/d' $(CONFIG_FILE).tmp
@sed -i '1i allow-lan: true' $(CONFIG_FILE).tmp
@sed -i '1i external-controller: 0.0.0.0:9090' $(CONFIG_FILE).tmp
@sed -i '1i mixed-port: 7890' $(CONFIG_FILE).tmp
@sed -i '1i secret: "$(SECRET)"' $(CONFIG_FILE).tmp
@mv $(CONFIG_FILE).tmp $(CONFIG_FILE)
@echo "Update Completed!"
@$(MAKE) restart
restart:
@echo "Restarting Clash..."
@docker restart clash
@echo "All Done!"
/etc/docker/daemon.json
去掉镜像网站
{
"insecure-registries": [
"jcloudhub.jcloudcs.com"
],
"registry-mirrors": []
}
sudo systemctl daemon-reload && sudo systemctl restart docker
创建 Docker 守护进程代理
sudo vim /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:7890"
Environment="HTTPS_PROXY=http://127.0.0.1:7890"
Environment="NO_PROXY=localhost,127.0.0.1,jcloudhub.jcloudcs.com"
sudo systemctl daemon-reload && sudo systemctl restart docker
Page views: Loading... · Visitors: Loading...
Except where otherwise noted, original content on this site is dedicated to the public domain under CC0 1.0.
Powered by Hexo & Theme mdsuper
沪ICP备2026040813号