Linux配置clash
Dionysen

下载安装Clash for Linux

这里有各个平台的Clash下载地址。

cd && mkdir clash
cd clash
wget https://git.opclash.com/kehuduan/clash/clash-linux-amd64-v1.18.0.gz

# 解压文件
gzip -d clash-linux-amd64-v1.18.0.gz

# 给予权限
chmod +x clash-linux-amd64-v1.18.0

# 改名移动
mv clash-linux-amd64-v1.18.0 /usr/local/bin/clash

# 查看版本
clash -v

# 首次启动
clash

// INFO[0000] Can't find config, create a initial config file
// INFO[0000] Can't find MMDB, start download
// ERRO[0002] create addr 127.0.0.1:7890 tcp listener error. err:listen tcp 127.0.0.1:7890: bind: address already in use
// 启动 clash 提示以上错误,你就直接使用 ctrl+c 跳过执行 cd $HOME/.config/clash/

创建配置文件

路径为:~/.config/clash/config.yaml,可以从window端的clash复制过来,同时复制一份到root用户的对应目录。

下载mmdb然后放到~/.config/clash中,命名为Country.mmdb

编写systemd服务脚本

/lib/systemd/system/ 目录下创建 clash@.service 文件

sudo vim /lib/systemd/system/clash@.service

写入以下内容并保存:

[Unit]
Description=A rule based proxy in Go for %i.
After=network.target

[Service]
Type=simple
User=%i
Restart=on-abort
ExecStart=/usr/bin/clash

[Install]
WantedBy=multi-user.target

为用户帐户运行 clash 系统实例

重新加载 systemd 模块

systemctl daemon-reload

启动 clash 服务

user 表示的是当前用户名

systemctl start clash@user

例如:

systemctl start clash@dionysen

设置开机自启

systemctl enable clash@user

问题

权限不足

$ sudo systemctl status clash

● clash.service - A rule based proxy in Go for shitao.
Loaded: loaded (/usr/lib/systemd/system/clash.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2019-06-18 17:27:18 CST; 4s ago
Process: 6777 ExecStart=/usr/bin/clash (code=exited, status=203/EXEC)
Main PID: 6777 (code=exited, status=203/EXEC)

Jun 18 17:27:18 localhost.localdomain systemd[1]: Started A rule based proxy in Go for shitao..
Jun 18 17:27:18 localhost.localdomain systemd[6777]: clash.service: Failed to execute command: Permission denied
Jun 18 17:27:18 localhost.localdomain systemd[6777]: clash.service: Failed at step EXEC spawning /usr/bin/clash: Permission denied
Jun 18 17:27:18 localhost.localdomain systemd[1]: clash.service: Main process exited, code=exited, status=203/EXEC
Jun 18 17:27:18 localhost.localdomain systemd[1]: clash.service: Failed with result 'exit-code'.

修改 selinux 成被动模式

sudo vim /etc/sysconfig/selinux
SELINUX=permissive

环境变量

# 配置环境变量
echo -e "export http_proxy=http://127.0.0.1:7890\nexport https_proxy=http://127.0.0.1:7890" >> ~/.bashrc
# or
echo -e "export http_proxy=http://127.0.0.1:7890\nexport https_proxy=http://127.0.0.1:7890" >> ~/.zshrc

在设置中将代理设置为手动:

# HTTP 代理
127.0.0.1:7890

# HTTPS 代理
127.0.0.1:7890

# Socks 主机
127.0.0.1:7891

节点管理

# 节点管理的地址为
http://clash.razord.top/#/proxies
显示评论