02月13, 2023

Centos 安装 Clash

服务器有时候需要科学上网,没有梯子很麻烦。之前写过一篇Centos安装Clash帖子,但是不够详细,重新补充完善一下。

安装Clash

1.下载与当前操作系统匹配的Clash,我的服务器是X86_64 平台下 CentOS7 所以对应的使用clash-linux-amd64-v1.6.5.gz包。

wget -O clash.gz    https://github.com/Dreamacro/clash/releases/download/v1.6.5/clash-linux-       amd64-v1.6.5.gz

2.下载好后解压安装包中 clash 到 /usr/local/bin/ 目录下。

gzip -dc clash.gz > /usr/local/bin/clash
chmod +x /usr/local/bin/clash

3.创建配置文件目录,并且下载MMDB 文件。

mkdir /etc/clash
wget -O /etc/clash/Country.mmdb https://www.sub-speeder.com/client-download/Country.mmdb

4.创建 systemd 脚本,脚本文件路径为 /etc/systemd/system/clash.service,内容如下

[Unit]
Description=clash daemon

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

[Install]
WantedBy=multi-user.target

5.systemd重新载入配置文件,systemctl daemon-reload

配置代理上网

1.在飞机场导入配置文件到本地,并且对配置文件修改。(需要做一些适当的修改)

mixed-port: 7890
socks-port: 7891
allow-lan: true
bind-address: '*'
mode: rule
secret: HuYong19993530 #web-ui密码
log-level: info
external-controller: '127.0.0.1:9090' #web-ui路径
external-ui: /opt/clash-dashboard #web-ui路径
dns:
    enable: true
    ipv6: false
    default-nameserver: [223.5.5.5, 119.29.29.29]
    enhanced-mode: redir-host
    fake-ip-range: 198.18.0.1/16
    use-hosts: true
    nameserver: ['https://doh.pub/dns-query', 'https://dns.alidns.com/dns-query']
    fallback: ['https://doh.dns.sb/dns-query', 'https://dns.cloudflare.com/dns-query', 'https://dns.twnic.tw/dns-query', 'tls://8.8.4.4:853']
    fallback-filter: { geoip: true, ipcidr: [240.0.0.0/4, 0.0.0.0/32] }
proxies:

2.设置系统代理,添加配置文件 /etc/profile.d/proxy.sh并在其中写入如下内容

export http_proxy="127.0.0.1:7890"
export https_proxy="127.0.0.1:7890"
export no_proxy="localhost, 127.0.0.1"

3.重载配置文件

source /etc/profile

配置web-ui

1.克隆clash-dashboard项目到本地.

git clone -b gh-pages --depth 1 https://github.com/Dreamacro/clash-dashboard /opt/clash-dashboard

2.修改 clash 配置文件中 external-ui 的值为 /opt/clash-dashboard

external-ui: /opt/clash-dashboard

3.启动clash服务

systemctl enable clash
systemctl start clash

工具

ACL4SSR 在线订阅转换 将订阅连接转成config.yaml.

引用

本文链接:https://imyoyo.xyz/post/centos-install-clash.html

-- EOF --

Comments