Ubuntu 安装使用 Clash

起笔于 

Ubuntu 安装使用 Clash

前言

适用范围建立在使用过 window IOS 下的 Clash 为基础的半安装教程

步骤

  1. 取出之前设备配置
  2. 安装配置Clash
  3. 注册为系统服务
  4. 在线管理Clash

取出配置

备好两个文件

  1. Country.mmdb
  2. profiles/xxxxxxxx.yml
打开目录找到两个文件
打开目录找到两个文件

安配 Clash

安装 Clash

下载解压并命名为 clash

  • 解压
  • 重命名
  • 移动到 /usr/local/bin/ 目录下 (方便在任何位置调用Clash)
  • 查看版本
  • 下载地址

配置 Clash

  1. 首次启动
    命令行输入clash即可, 一般会提示失败(不重要), 目的是生成配置文件
  2. 找到配置目录
    一般在 /用户/.config/clash/ 即 /root/.config/clash
  3. 放置全球IP库
    把之前准备的 Country.mmdb 放进去
  4. 写配置文件
    创建一个 config.yaml
config.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# port of HTTP
# port: 7890 ## 解释掉该行,使用mixed-port

# port of SOCKS5
# socks-port: 7891 ## 解释掉该行,使用mixed-port
mixed-port: 52443 ## 提供统一的端口

authentication: ## 增加配置,设置账号和密码
- "username:password"

# web ui 配置
external-controller: 0.0.0.0:52444 # web ui 监听地址
secret: "xxxxxxxxxxxxx" # web ui 密钥

# allow-lan: false
allow-lan: true ## 允许局域网连接

# Rule / Global/ DIRECT (default is Rule)
mode: rule

# external-ui: dashboard ## 关闭external

## 以下贴订阅的配置

接着把之前准备的 /profiles/xxxxxxxx.yml 的文件dns开始到结尾的配置贴到 config.yaml 后面.
window与linux配置不同的是前者读取profiles下的列表, 后者直接读取 config.yaml.

注册为系统服务

在/etc/systemd/system目录下创建clash.service文件

clash.service
1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=Clash Service
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/clash
Restart=on-failure

[Install]
WantedBy=multi-user.target

以后就能直接使用熟悉的服务命令

1
2
3
4
5
systemctl enable clash  # 开机自启
systemctl start clash
systemctl restart clash
systemctl status clash
systemctl stop clash

在线管理

有两个选择, 根据config文件的 web ui 配置, 使用在线网站管理

  1. yacd

如果你不用IP,已经反向代理使用域名并且使用Https, 也可以使用下面的https的yacd

  1. razord

结语

注意端口自行定义与放行


本站由 @钟意 使用 Stellar 主题创建
又拍云 提供CDN加速/云存储服务
vercel 提供托管服务
湘ICP备2023019799号-1
总访问 次 | 本页访问