服务器搭建clash服务
ubuntu无桌面版 部署clash
下载必要文件
1、下载clash 压缩包 :https://github.com/Dreamacro/clash/releases 在官网选择合适的压缩包
2、下载Country.mmdb 文件 : wget -O Country.mmdb www.sub-speeder.com/client-download/Country.mmdb
需要科学上网才可下载,这属实是矛盾了,可先在windows下载 再传过去。 网盘链接:https://yun.laohu.space/share/c4J1_IHJ
(Country.mmdb 是一个 MaxMind 公司提供的 IP 地址 → 国家的映射数据库)
安装
1、仔细看每条指令,clash必须安装在/etc/clash下! chmod +x clash
获取运行权限
2、wget -O config.yaml <clash订阅url>
下载订阅文件 config.yaml
mkdir /etc/clash # 创建clash文件夹 |
配置
1、配置clash.service服务
echo "[Unit] |
直接运行上面指令,给clash添加启动指令,类似快捷方式
/usr/lib/systemd/system/clash.service 当心这个文件出现语法错误!
再执行该语句 systemctl daemon-reload
重新加载 systemd 配置文件
2、将之前下载完成的config.yaml文件和 Country.mmdb文件复制到/root/.config/clash/
进入/root/.config/clash并再复制到/etc/clash中
cd /root/.config/clash/ |
服务操作命令
service clash start # 启动
service clash stop # 停止
service clash restart # 重启
service clash status # 状态
运行
然后通过浏览器访问 http://clash.razord.top 进行策略组设置。
打开界面后 选择服务器的 IP地址 密钥好像可有可有 我写得 root
点击 “添加”即可进入配置 页面
问题!!
这里 我进去配置页面后,可以看到各个节点信息什么,但是我的系统代理带不开。。。。。
解决
最终clash正常运行,却发现依然无法连接外网, 原因是浏览器或者是你正在运行的命令窗口没有指向clash的 7890端口
需要添加
root@linux:/opt/clash# export http_proxy=http://127.0.0.1:7890 |
docker 部署clash
下载配置文件
新建 /opt/clash 将下载的配置文件改为 config.yaml文件
运行容器
docker run -d --name clash -p 7890:7890 -p 7891:7891 -p 9090:9090 -v /opt/clash/config.yaml:/root/.config/clash/config.yaml -v /opt/clash/ui:/opt/clash/ui dreamacro/clash |
docker run -d 运行容器
–name clash 容器名称
-p 7890:7890 -p 7891:7891 端口映射 流量流动
-p 9090:9090 ui界面
-v /opt/clash/config.yaml:/root/.config/clash/config.yaml 将容器的配置文件映射到外部的刚才新建的文件,用外部文件代替
-v /opt/clash/ui:/opt/clash/ui dreamacro/clash 映射ui配置文件
运行正常后,需要将使用的对象指向clash代理 才可以连接科学网络
如 浏览器 需要修改浏览器配置
命令行窗口 需要执行
export http_proxy=http://127.0.0.1:7890 |
将端口指向这个代理端口 才可运行
可将开启和关闭设置在 ~/.bashrc文件下
# ~/.bashrc: executed by bash(1) for non-login shells. |
添加完这两个,即可通过 proxy控制开启 unproxy控制关闭