【Clash】Ubuntu安装部署Clash

本地下载所需资源

需要的资源列表

下载完上述资源后解压缩,然后通过sftp上传至服务器

配置运行

创建用户

1
sudo useradd --system --no-create-home --shell /usr/sbin/nologin mihomo || true

移动资源到所需文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
sudo mkdir -p /etc/mihomo/ui /etc/mihomo/run

sudo mv metacubexd-gh-pages /etc/mihomo/ui
sudo chown -R mihomo:mihomo /etc/mihomo/ui

sudo mv mihomo-linux-amd64-v1-v1.19.21 /usr/local/bin/mihomo
sudo chmod 755 /usr/local/bin/mihomo
/usr/local/bin/mihomo -v

sudo mv country-lite.mmdb /etc/mihomo/country.mmdb

创建配置文件

sudo vim /etc/mihomo/config.yaml,示例如下,可以把secret以及机场节点换成你自己的节点

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
mixed-port: 7890
allow-lan: false
bind-address: '*'
ipv6: true
unified-delay: true
tcp-concurrent: true
mode: rule
log-level: info

external-controller: 127.0.0.1:9090
secret: 'a1445698155'
external-ui: /etc/mihomo/ui

profile:
  store-selected: true
  store-fake-ip: true

dns:
  enable: true
  listen: '127.0.0.1:1053'
  ipv6: true
  use-hosts: true
  enhanced-mode: fake-ip
  nameserver:
    - 8.8.8.8
    - 1.1.1.1
  fallback:
    - tls://1.1.1.1:853
  fake-ip-filter:
    - '*.lan'
    - 'localhost'

proxies:
  - { name: '🇺🇸 USA美国-1-1', server: us1.ktmhyld.com, port: 18387, up: 500, down: 500, skip-cert-verify: true, type: hysteria2, password: 8003e5ae-a58a-49fa-bebd-834fa4261ec3 }
  - { name: '🇺🇸 USA美国-2', server: us2.ktmurl.club, port: 18338, up: 500, down: 500, skip-cert-verify: true, type: hysteria2, password: 8003e5ae-a58a-49fa-bebd-834fa4261ec3 }
  - { name: '🇺🇸 USA美国-3', server: us3.ktmurl.club, port: 18338, up: 500, down: 500, skip-cert-verify: true, type: hysteria2, password: 8003e5ae-a58a-49fa-bebd-834fa4261ec3 }

  - {
      name: '🇺🇸 USA美国-01',
      type: vmess,
      server: gtm1.ktmwan.net,
      port: 12885,
      uuid: 8003e5ae-a58a-49fa-bebd-834fa4261ec3,
      alterId: 0,
      cipher: auto,
      udp: true,
      network: ws,
      ws-opts: { path: /, headers: { Host: baidu.com } },
      ws-path: /,
      ws-headers: { Host: baidu.com }
    }
  - {
      name: '🇺🇸 USA美国-02',
      type: vmess,
      server: gtm1.ktmwan.net,
      port: 12885,
      uuid: 8003e5ae-a58a-49fa-bebd-834fa4261ec3,
      alterId: 0,
      cipher: auto,
      udp: true,
      network: ws,
      ws-opts: { path: /, headers: { Host: baidu.com } },
      ws-path: /,
      ws-headers: { Host: baidu.com }
    }
  - {
      name: '🇺🇸 USA美国-03',
      type: vmess,
      server: gtm1.ktmwan.net,
      port: 12885,
      uuid: 8003e5ae-a58a-49fa-bebd-834fa4261ec3,
      alterId: 0,
      cipher: auto,
      udp: true,
      network: ws,
      ws-opts: { path: /, headers: { Host: baidu.com } },
      ws-path: /,
      ws-headers: { Host: baidu.com }
    }

  - name: 静态住宅
    type: socks5
    server: 216.175.196.87
    port: 443
    username: tOpqYxqFVafC
    password: rCEswkw6NV
    udp: true
    dialer-proxy: 前置机场

proxy-groups:
  - name: 前置机场
    type: select
    proxies:
      - DIRECT
      - 🇺🇸 USA美国-1-1
      - 🇺🇸 USA美国-2
      - 🇺🇸 USA美国-3
      - 🇺🇸 USA美国-01
      - 🇺🇸 USA美国-02
      - 🇺🇸 USA美国-03

  - name: AI住宅链式
    type: select
    proxies:
      - 静态住宅

rules:
  # Claude / Anthropic
  - DOMAIN-SUFFIX,anthropic.com,AI住宅链式
  - DOMAIN-SUFFIX,claude.ai,AI住宅链式
  - DOMAIN-SUFFIX,claudeusercontent.com,AI住宅链式
  - DOMAIN-SUFFIX,claude.com,AI住宅链式
  - DOMAIN,api.anthropic.com,AI住宅链式
  - DOMAIN,console.anthropic.com,AI住宅链式

  # OpenAI / ChatGPT
  - DOMAIN-SUFFIX,openai.com,AI住宅链式
  - DOMAIN-SUFFIX,chatgpt.com,AI住宅链式
  - DOMAIN-SUFFIX,oaistatic.com,AI住宅链式
  - DOMAIN-SUFFIX,oaiusercontent.com,AI住宅链式
  - DOMAIN,api.openai.com,AI住宅链式
  - DOMAIN,auth.openai.com,AI住宅链式

  # Gemini
  - DOMAIN-SUFFIX,ai.google.dev,AI住宅链式
  - DOMAIN-SUFFIX,aistudio.google.com,AI住宅链式
  - DOMAIN-SUFFIX,gemini.google.com,AI住宅链式
  - DOMAIN,generativelanguage.googleapis.com,AI住宅链式

  # Other explicit chain targets
  - DOMAIN,ping0.cc,AI住宅链式
  - DOMAIN,ipinfo.io,AI住宅链式

  # China direct
  - GEOIP,CN,DIRECT,no-resolve

  # Everything else goes to front proxy
  - MATCH,前置机场

写systemd服务

sudo vim /etc/systemd/system/mihomo.service

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
[Unit]
Description=Mihomo Service
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=mihomo
Group=mihomo
WorkingDirectory=/etc/mihomo
ExecStart=/usr/local/bin/mihomo -d /etc/mihomo -f /etc/mihomo/config.yaml
Restart=always
RestartSec=5
LimitNOFILE=1048576
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/etc/mihomo

[Install]
WantedBy=multi-user.target
1
2
3
sudo systemctl daemon-reload
sudo systemctl enable --now mihomo
systemctl status mihomo --no-pager

验证服务是否正常

1
2
curl http://127.0.0.1:9090/version \
  -H "Authorization: Bearer a1445698155"

端口转发访问WEBUI

从本地ssh配置端口转发

1
ssh -L 9090:127.0.0.1:9090 user@server-ip

完成后通过本地浏览器访问webui,地址:htttp://127.0.0.1:9090/ui/

终端代理配置

如果是bash,进行如下操作

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
cat >> ~/.bashrc <<'EOF'
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
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
export ALL_PROXY=socks5://127.0.0.1:7890
export no_proxy=127.0.0.1,localhost
export NO_PROXY=127.0.0.1,localhost
EOF

source ~/.bashrc
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计