这里以Debian12为例进行部署,请确保安装了基本的gzip,git,nano软件包
遇到文章有问题可以在下面评论区指出~
配置mihomo
先创建一个目录用于存放程序和配置
cd /opt
sudo mkdir Clash
cd /Clash
然后在github或者其他地方上找到mihomo下载链接(下方链接是amd64架构的,如果是arm等其他架构需要自行选择),使用wget或者curl下载到本地
sudo wget https://ghproxy.cn/https://github.com/MetaCubeX/mihomo/releases/download/v1.18.10/mihomo-linux-amd64-compatible-go120-v1.18.10.gz
解压,重命名为mihomo()
sudo gzip -d mihomo-linux-amd64-compatible-go120-v1.18.10.gz
sudo mv mihomo-linux-amd64-compatible-go120-v1.18.10 mihomo
给予执行权限
sudo chmod +x mihomo
然后在github或者其他地方上找到MMDB文件(GeoIP数据库),并下载到本地
sudo wget https://ghproxy.cn/https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb
配置 metacubexd WebUI面板
在github或者其他地方上找到WebUI的git仓库,并使用git克隆到本地
sudo git clone https://ghproxy.cn/https://github.com/metacubex/metacubexd.git -b gh-pages ./ui
接下来通过你的机场订阅链接或者直接手动编写来获得你的配置文件(订阅文件),
#通过机场订阅链接获取 方法1:
sudo wget -O ./config.yaml [你的订阅链接]
#通过机场订阅链接获取 方法2:
sudo curl -o ./config.yaml [你的订阅链接]
#通过机场订阅链接获取 方法3:(注意检查是否获取成功,即查看config.yaml文件)
sudo curl [你的订阅链接] > ./config.yaml
#如果以上方法都失败,那你只能手动编写你的配置文件,比如使用nano,vim等编辑器编写。
#(如果你有在使用Clash Verge,则你可以在Clash Verge的设置->当前配置直接拷贝你的配置文件。)
请保持配置文件的名字为config.yaml,如果不是,可以使用mv命令更改
sudo mv [你的配置文件名字] ./config.yaml
确保获取到的配置文件中external-ui和external-controller配置正确(如果没有就自己在文件头部加上)
可以使用nano编辑配置文件
sudo nano config.yaml
external-ui参数:“./ui
”路径是刚刚克隆到本地的WebUI路径
示例:external-ui: ./ui
external-controller参数:“0.0.0.0:9090
”是mihomo的控制API监听ip以及端口,如果不在乎安全性可以直接使用0.0.0.0:9090
。WebUI通过调用控制API来切换节点以及更改配置。
注意事项:如果系统有防火墙,请在防火墙设置处放行这个端口或者直接关闭防火墙。如ubuntu,则需要在 ufw 中放行 9090 端口。
示例:external-controller: 0.0.0.0:9090
基本WebUI服务即部署完成,
这时只需要加参数执行mihomo即可启动(这里 ./ 是指定工作目录,目录内需要存在刚才修改的config.yaml配置文件)
sudo ./mihomo -d ./
这时即可在浏览器访问http://[ip地址]:9090/ui
即可打开WebUI控制面板。
在第一个框内填写http://[ip地址]:9090
后点击添加按钮即可连接到后端,这样就能比较容易的进行更改节点,打开tun模式等操作。
注意事项:如果设置有密钥secret,则还需要填写下方的密钥,密钥可以在配置文件中可以找到,比如上图中external-ui: ./ui下方的 secret: 8b7477……
)
添加到systemd服务
sudo nano /etc/systemd/system/mihomo.service
[Unit]
Description=mihomo Daemon, Another Clash Kernel.
After=network.target NetworkManager.service systemd-networkd.service iwd.service
[Service]
Type=simple
LimitNPROC=500
LimitNOFILE=1000000
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE CAP_SYS_TIME CAP_SYS_PTRACE CAP_DAC_READ_SEARCH CAP_DAC_OVERRIDE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE CAP_SYS_TIME CAP_SYS_PTRACE CAP_DAC_READ_SEARCH CAP_DAC_OVERRIDE
Restart=always
ExecStartPre=/usr/bin/sleep 1s
ExecStart=/opt/Clash/mihomo -d /opt/Clash/
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
注意:请保证上面的 ExecStart 配置中 /opt/Clash/mihomo 和 /opt/Clash/ 路径正确,为你自己的mihomo程序路径和工作路径
使用以下命令重新加载 systemd
systemctl daemon-reload
启用 mihomo 服务
systemctl enable mihomo
使用以下命令启动 mihomo
systemctl start mihomo
使用以下命令关闭 mihomo
systemctl stop mihomo
使用以下命令重启 mihomo
systemctl restart mihomo
更多请参考https://wiki.metacubex.one/startup/service/
参考文档:
Linux搭建mihomo(2024.8.11) - なのです!
https://wiki.metacubex.one/startup/service/
本站所有文章内容仅供学习了解,非盈利目的,请于下载后 24 小时内删除,不得用作任何商业用途。文字、数据及图片均有所属版权,如转载须注明来源。
务必循遵守所在地、所在国家和用户所在国家的法律法规,作者不对使用者任何不当行为负责。