20230705更新#
systemd方式启动Headscale会有启动不成功现象 配置ssl证书后 推荐去官方页面抄nginx反向代理进行增加ssl
推测是因为权限原因,推荐测试时候全新安装不修改配置文件情况下来启动。
在前些日子,写了一篇文章关于headscale服务器的,这次有更深的理解,希望谷歌出来这篇文章的朋友有所帮助
系统debian11 并root用户登录
开启端口#
有用的就8080端口其他端口有需要开放
安装headscale#
创建相关目录与文件
1
2
3
4
| mkdir -p /etc/headscale
mkdir -p /var/lib/headscale
touch /var/lib/headscale/db.sqlite
touch /etc/headscale/config.yaml
|
headscale
从 GitHub 的发布页面下载最新的二进制文件重命名为headscale
上传到/root
目录
1
2
| mv /root/headscale /usr/local/bin/
chmod +x /usr/local/bin/headscale
|
复制Github仓库里的示例配置内容到config.yaml
文件`
1
| nano /etc/headscale/config.yaml
|
配置文件修改内容 如下 证书配置绝对不要双引号直接配置为绝对路径
1
2
3
4
5
6
7
8
9
10
11
12
13
| server_url: http://127.0.0.1:8080
修改为 这选项需要配置域名
server_url: https://he.gao4.top:8080
配置自定义本地证书
tls_cert_path: ""
tls_key_path: ""
修改如下
tls_cert_path: /root/.acme.sh/he.gao4.top/fullchain.cer
tls_key_path: /root/.acme.sh/he.gao4.top/he.gao4.top.key
配置客户端证书模式
tls_client_auth_mode: relaxed
修改为
tls_client_auth_mode: disabled
|
创建 SystemD service 配置文件
1
| nano /etc/systemd/system/headscale.service
|
内容如下
1
2
3
4
5
6
7
8
9
10
11
12
| [Unit]
Description=headscale
After=network.target
[Service]
WorkingDirectory=/etc/headscale
ExecStart=/usr/local/bin/headscale serve
# Disable debug mode
Environment=GIN_MODE=release
[Install]
WantedBy=multi-user.target
|
重载SystemD配置文件
1
| systemctl daemon-reload
|
管理headscale
#
1
2
3
4
| systemctl start headscale.service
systemctl restart headscale.service
systemctl enable headscale.service
systemctl status headscale.service
|
查看端口占用 这一步可以看到headscale
没有端口占用的话就没启动成功
1
| ss -tulnp|grep headscale
|
创建命名空间default
可以理解为 用户
1
| headscale namespaces create default
|
Linux端链接服务端
1
| tailscale up --login-server=https://he.gao4.top:8080 --accept-routes=true --accept-dns=false
|
win下链接服务端
1
| 访问你的服务域名比如说我的https://he.gao4.top:8080/windows
|
查看已创建命名空间
1
| headscale namespaces list
|
查看所有节点情况
删除节点 3 注意带sudo
1
| sudo headscale nodes del -i 3
|
Headscale 端开启路由
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| #查看路由,可以看到对应路由时关闭状态的
# headscale routes list
ID | Machine | Prefix | Advertised | Enabled | Primary
1 | prometheus1-161 | 192.168.1.0/24 | true | false | false
#开启路由
# headscale routes enable -r 1
#再次查看可以看到对应路由时开启状态
# headscale routes list
ID | Machine | Prefix | Advertised | Enabled | Primary
1 | prometheus1-161 | 192.168.1.0/24 | true | true | true
#其他节点查看路由结果
ip route show table 52|grep "192.168.1.0/24"
192.168.1.0/24 dev tailscale0
|
oopenwrt登录节点关闭dns并通告子网路由网段
1
| tailscale up --accept-dns=false --accept-routes --login-server=https://he.gao4.top:8080 --advertise-routes=192.168.100.0/24
|