clash linux部署
于自己主力系统是Mac和Linux,Mac端好说直接有ClashX,
但是linux下没什么特别好用更用的,
带gui的因为自己的linux是服务器如果要调试的话还得接显示器, 所以v2ray就略显鸡肋, 经过很多尝试发现clash+dashboard貌似是linux服务端最优解, 部署了很多次了, 但是每次由于时间原因都没有把具体部署细节写下来, 后续再次部署的时候再去查就很烦, 趁想起来就赶紧补上
项目地址
clash主程序
yacd dashboard
安装
先在用户目录建立clash的文件夹, 因为我自己是内网所以直接root目录
mkdir -p /root/.config/clash && cd /root/.config/clash
用clash的一个主要原因就是因为支持订阅, 用机场比较方便,
前提是你的机场支持clash订阅
所以我们先把机场给我们的config.yaml给下载下来, 比如你可以使用wget
wget "机场给你的订阅链接" -O config.yaml
然后我们去git上把clash二进制文件和yacd dashboard给下载下来
wget https://github.com/Dreamacro/clash/releases/download/v1.11.12/clash-linux-amd64-v1.11.12.gzwget https://github.com/haishanh/yacd/releases/download/v0.3.7/yacd.tar.xz
因为我们是intel架构的linux, 所以这里clash系统架构我们选择linux-amd64`
然后我们将这两个文件进行解压
gzip -d clash-linux-amd64-v1.11.12.gztar -zxvf yacd.tar.xz
将下载下来的clash重命名方便操作, 并赋予可执行权限
mv clash-linux-amd64-v1.11.12 clashchmod +x clash
将下来下来的yacd更名为dashboard
mv public dashboard
然后我们对config.yaml进行配置使其加载dashboard
port: 7890socks-port: 7891allow-lan: truemode: Rulelog-level: infosecert: 123456 // 增加这一行, 如果你希望你的clashweb要密码访问可以在这块配置密码, 如果不需要直接注释掉即可external-ui: dashboard // 增加这一行external-controller: 0.0.0.0:9090
接下来验证你的操作是否有效可以执行
./clash -d .------------Output------------INFO[0000] Start initial compatible provider Proxies INFO[0000] Start initial compatible provider Spotify INFO[0000] Start initial compatible provider Microsoft INFO[0000] Start initial compatible provider GlobalTV INFO[0000] Start initial compatible provider Apple INFO[0000] Start initial compatible provider Steam INFO[0000] Start initial compatible provider AsianTV INFO[0000] Start initial compatible provider PayPal INFO[0000] Start initial compatible provider Speedtest INFO[0000] Start initial compatible provider Netflix INFO[0000] Start initial compatible provider Youtube INFO[0000] Start initial compatible provider Telegram INFO[0000] Start initial compatible provider Others INFO[0000] RESTful API listening at: [::]:9090INFO[0000] HTTP proxy listening at: [::]:7890INFO[0000] SOCKS proxy listening at: [::]:7891ERRO[0000] Start DNS server error: listen udp 0.0.0.0:53: bind: address already in use
我这里报53端口占用,原因是ubuntu自带的systemd-resolved.service启动着,默认情况下系统靠这个组建解析dns,
分析了config.yaml配置文件, 默认启动了透明代理,
但是我想了想也需要所以就留着了,如果你不需要直接去config.yaml给dns那部分注释掉,
但是可能会影响clash某些操作,需要你根据情况自行配置
针对53端口占用, 我直接
systemctl stop systemd-resolved.service systemctl disable system-resolved.service
给停了, 也把自启动给停了, 这样也有个问题,
就是开机如果我的clash代理不可用的话那就整个系统都上不了网
接下来把clash, 移到
mv clash /usr/local/bin
然后配置service文件, 方便我们管理
vim /etc/systemd/system/clash.service
[Unit]Description=clash serviceAfter=network.target[Service]Type=simpleUser=rootExecStart=/usr/local/bin/clashRestart=on-failure # or always, on-abort, etc[Install]WantedBy=multi-user.target
然后使其生效
systemctl daemon-reload systemctl enable clash systemctl start clash
这时候你在status就应该是成功部署上了
systemctl statu clash-------------Output---------------● clash.service - clash service Loaded: loaded (/etc/systemd/system/clash.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2022-11-10 15:13:08 CST; 2s ago Main PID: 24755 (clash) Tasks: 7 (limit: 2279) Memory: 6.2M CPU: 31ms CGroup: /system.slice/clash.service └─24755 /usr/local/bin/clash11月 10 15:13:08 eden clash[24755]: time="2022-11-10T15:13:08+08:00" level=info msg="Start initial compatible provider Proxies"11月 10 15:13:08 eden clash[24755]: time="2022-11-10T15:13:08+08:00" level=info msg="Start initial compatible provider Apple"11月 10 15:13:08 eden clash[24755]: time="2022-11-10T15:13:08+08:00" level=info msg="Start initial compatible provider PayPal"11月 10 15:13:08 eden clash[24755]: time="2022-11-10T15:13:08+08:00" level=info msg="Start initial compatible provider Microsoft"11月 10 15:13:08 eden clash[24755]: time="2022-11-10T15:13:08+08:00" level=info msg="Start initial compatible provider Youtube"11月 10 15:13:08 eden clash[24755]: time="2022-11-10T15:13:08+08:00" level=info msg="Start initial compatible provider Others"11月 10 15:13:08 eden clash[24755]: time="2022-11-10T15:13:08+08:00" level=info msg="RESTful API listening at: [::]:9090"11月 10 15:13:08 eden clash[24755]: time="2022-11-10T15:13:08+08:00" level=info msg="HTTP proxy listening at: [::]:7890"11月 10 15:13:08 eden clash[24755]: time="2022-11-10T15:13:08+08:00" level=info msg="SOCKS proxy listening at: [::]:7891"11月 10 15:13:08 eden clash[24755]: time="2022-11-10T15:13:08+08:00" level=info msg="DNS server listening at: [::]:53"
linux下连接的时候, 你可以直接可以在终端
export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
当然, 如果你觉得每次都输入太麻烦, 也有个好的办法直接写在bash里, 比如
# Proxy auto startexport https_proxy=http://127.0.0.1:7890export http_proxy=http://127.0.0.1:7890export all_proxy=socks5://127.0.0.1:7890# Open proxyon() {# export https_proxy=http://127.0.0.1:1087# export http_proxy=http://127.0.0.1:1087# export all_proxy=socks5://127.0.0.1:1086
export https_proxy=http://127.0.0.1:7890
export http_proxy=http://127.0.0.1:7890
export all_proxy=socks5://127.0.0.1:7890
echo "HTTP/HTTPS Proxy on"}
# Close proxyoff() {
unset http_proxy
unset https_proxy
unset all_proxy
echo "HTTP/HTTPS Proxy off"}然后我们使其生效
source ~/.bashrc
这样我们每次想让他走代理的时候直接
on
不想用的时候直接off
或者你也可以直接用proxychains-ng, 安装也很简单
apt install proxychains-ng
然后配置
echo "socks5 127.0.0.1 7891" > /etc/proxychains4.conf //也许你的配置文件不是这个, 看情况而变
Over!
目录 返回
首页