当前位置:   article > 正文

headscale headscale-ui 部署 docker_headscale docker

headscale docker

网上的基本都不成功,根据官方重新摸了遍。

1、新建挂载目录,创建数据库文件:

  1. mkdir -p /xxx/headscale/config
  2. touch /xxx/headscale/config/db.sqlite

2、配置文件

/xxx/headscale/config/config.yaml     端口我改了,根据自己情况来

  1. ---
  2. # headscale will look for a configuration file named `config.yaml` (or `config.json`) in the following order:
  3. #
  4. # - `/etc/headscale`
  5. # - `~/.headscale`
  6. # - current working directory
  7. # The url clients will connect to.
  8. # Typically this will be a domain like:
  9. #
  10. # https://myheadscale.example.com:443
  11. #
  12. server_url: http://<public_ip>:8081
  13. # Address to listen to / bind to on the server
  14. #
  15. # For production:
  16. # listen_addr: 0.0.0.0:8080
  17. listen_addr: 0.0.0.0:8081
  18. # Address to listen to /metrics, you may want
  19. # to keep this endpoint private to your internal
  20. # network
  21. #
  22. metrics_listen_addr: 0.0.0.0:6030
  23. # Address to listen for gRPC.
  24. # gRPC is used for controlling a headscale server
  25. # remotely with the CLI
  26. # Note: Remote access _only_ works if you have
  27. # valid certificates.
  28. #
  29. # For production:
  30. # grpc_listen_addr: 0.0.0.0:50443
  31. grpc_listen_addr: 127.0.0.1:50443
  32. # Allow the gRPC admin interface to run in INSECURE
  33. # mode. This is not recommended as the traffic will
  34. # be unencrypted. Only enable if you know what you
  35. # are doing.
  36. grpc_allow_insecure: false
  37. # Private key used to encrypt the traffic between headscale
  38. # and Tailscale clients.
  39. # The private key file will be autogenerated if it's missing.
  40. #
  41. private_key_path: /etc/headscale/private.key
  42. # The Noise section includes specific configuration for the
  43. # TS2021 Noise protocol
  44. noise:
  45. # The Noise private key is used to encrypt the
  46. # traffic between headscale and Tailscale clients when
  47. # using the new Noise-based protocol. It must be different
  48. # from the legacy private key.
  49. private_key_path: /etc/headscale/noise_private.key
  50. # List of IP prefixes to allocate tailaddresses from.
  51. # Each prefix consists of either an IPv4 or IPv6 address,
  52. # and the associated prefix length, delimited by a slash.
  53. # While this looks like it can take arbitrary values, it
  54. # needs to be within IP ranges supported by the Tailscale
  55. # client.
  56. # IPv6: https://github.com/tailscale/tailscale/blob/22ebb25e833264f58d7c3f534a8b166894a89536/net/tsaddr/tsaddr.go#LL81C52-L81C71
  57. # IPv4: https://github.com/tailscale/tailscale/blob/22ebb25e833264f58d7c3f534a8b166894a89536/net/tsaddr/tsaddr.go#L33
  58. ip_prefixes:
  59. - fd7a:115c:a1e0::/48
  60. - 100.64.0.0/10
  61. # DERP is a relay system that Tailscale uses when a direct
  62. # connection cannot be established.
  63. # https://tailscale.com/blog/how-tailscale-works/#encrypted-tcp-relays-derp
  64. #
  65. # headscale needs a list of DERP servers that can be presented
  66. # to the clients.
  67. derp:
  68. server:
  69. # If enabled, runs the embedded DERP server and merges it into the rest of the DERP config
  70. # The Headscale server_url defined above MUST be using https, DERP requires TLS to be in place
  71. enabled: false
  72. # Region ID to use for the embedded DERP server.
  73. # The local DERP prevails if the region ID collides with other region ID coming from
  74. # the regular DERP config.
  75. region_id: 999
  76. # Region code and name are displayed in the Tailscale UI to identify a DERP region
  77. region_code: "headscale"
  78. region_name: "Headscale Embedded DERP"
  79. # Listens over UDP at the configured address for STUN connections - to help with NAT traversal.
  80. # When the embedded DERP server is enabled stun_listen_addr MUST be defined.
  81. #
  82. # For more details on how this works, check this great article: https://tailscale.com/blog/how-tailscale-works/
  83. stun_listen_addr: "0.0.0.0:3478"
  84. # List of externally available DERP maps encoded in JSON
  85. urls:
  86. - https://controlplane.tailscale.com/derpmap/default
  87. # Locally available DERP map files encoded in YAML
  88. #
  89. # This option is mostly interesting for people hosting
  90. # their own DERP servers:
  91. # https://tailscale.com/kb/1118/custom-derp-servers/
  92. #
  93. # paths:
  94. # - /etc/headscale/derp-example.yaml
  95. paths: []
  96. # If enabled, a worker will be set up to periodically
  97. # refresh the given sources and update the derpmap
  98. # will be set up.
  99. auto_update_enabled: true
  100. # How often should we check for DERP updates?
  101. update_frequency: 24h
  102. # Disables the automatic check for headscale updates on startup
  103. disable_check_updates: true
  104. # Time before an inactive ephemeral node is deleted?
  105. ephemeral_node_inactivity_timeout: 30m
  106. # Period to check for node updates within the tailnet. A value too low will severely affect
  107. # CPU consumption of Headscale. A value too high (over 60s) will cause problems
  108. # for the nodes, as they won't get updates or keep alive messages frequently enough.
  109. # In case of doubts, do not touch the default 10s.
  110. node_update_check_interval: 10s
  111. # SQLite config
  112. db_type: sqlite3
  113. # For production:
  114. db_path: /etc/headscale/db.sqlite
  115. # # Postgres config
  116. # If using a Unix socket to connect to Postgres, set the socket path in the 'host' field and leave 'port' blank.
  117. # db_type: postgres
  118. # db_host: localhost
  119. # db_port: 5432
  120. # db_name: headscale
  121. # db_user: foo
  122. # db_pass: bar
  123. # If other 'sslmode' is required instead of 'require(true)' and 'disabled(false)', set the 'sslmode' you need
  124. # in the 'db_ssl' field. Refers to https://www.postgresql.org/docs/current/libpq-ssl.html Table 34.1.
  125. # db_ssl: false
  126. ### TLS configuration
  127. #
  128. ## Let's encrypt / ACME
  129. #
  130. # headscale supports automatically requesting and setting up
  131. # TLS for a domain with Let's Encrypt.
  132. #
  133. # URL to ACME directory
  134. acme_url: https://acme-v02.api.letsencrypt.org/directory
  135. # Email to register with ACME provider
  136. acme_email: ""
  137. # Domain name to request a TLS certificate for:
  138. tls_letsencrypt_hostname: ""
  139. # Path to store certificates and metadata needed by
  140. # letsencrypt
  141. # For production:
  142. tls_letsencrypt_cache_dir: /var/lib/headscale/cache
  143. # Type of ACME challenge to use, currently supported types:
  144. # HTTP-01 or TLS-ALPN-01
  145. # See [docs/tls.md](docs/tls.md) for more information
  146. tls_letsencrypt_challenge_type: HTTP-01
  147. # When HTTP-01 challenge is chosen, letsencrypt must set up a
  148. # verification endpoint, and it will be listening on:
  149. # :http = port 80
  150. tls_letsencrypt_listen: ":http"
  151. ## Use already defined certificates:
  152. tls_cert_path: ""
  153. tls_key_path: ""
  154. log:
  155. # Output formatting for logs: text or json
  156. format: text
  157. level: info
  158. # Path to a file containg ACL policies.
  159. # ACLs can be defined as YAML or HUJSON.
  160. # https://tailscale.com/kb/1018/acls/
  161. acl_policy_path: ""
  162. ## DNS
  163. #
  164. # headscale supports Tailscale's DNS configuration and MagicDNS.
  165. # Please have a look to their KB to better understand the concepts:
  166. #
  167. # - https://tailscale.com/kb/1054/dns/
  168. # - https://tailscale.com/kb/1081/magicdns/
  169. # - https://tailscale.com/blog/2021-09-private-dns-with-magicdns/
  170. #
  171. dns_config:
  172. # Whether to prefer using Headscale provided DNS or use local.
  173. override_local_dns: false
  174. # List of DNS servers to expose to clients.
  175. nameservers:
  176. - 1.1.1.1
  177. # NextDNS (see https://tailscale.com/kb/1218/nextdns/).
  178. # "abc123" is example NextDNS ID, replace with yours.
  179. #
  180. # With metadata sharing:
  181. # nameservers:
  182. # - https://dns.nextdns.io/abc123
  183. #
  184. # Without metadata sharing:
  185. # nameservers:
  186. # - 2a07:a8c0::ab:c123
  187. # - 2a07:a8c1::ab:c123
  188. # Split DNS (see https://tailscale.com/kb/1054/dns/),
  189. # list of search domains and the DNS to query for each one.
  190. #
  191. # restricted_nameservers:
  192. # foo.bar.com:
  193. # - 1.1.1.1
  194. # darp.headscale.net:
  195. # - 1.1.1.1
  196. # - 8.8.8.8
  197. # Search domains to inject.
  198. domains: []
  199. # Extra DNS records
  200. # so far only A-records are supported (on the tailscale side)
  201. # See https://github.com/juanfont/headscale/blob/main/docs/dns-records.md#Limitations
  202. # extra_records:
  203. # - name: "grafana.myvpn.example.com"
  204. # type: "A"
  205. # value: "100.64.0.3"
  206. #
  207. # # you can also put it in one line
  208. # - { name: "prometheus.myvpn.example.com", type: "A", value: "100.64.0.3" }
  209. # Whether to use [MagicDNS](https://tailscale.com/kb/1081/magicdns/).
  210. # Only works if there is at least a nameserver defined.
  211. magic_dns: true
  212. # Defines the base domain to create the hostnames for MagicDNS.
  213. # `base_domain` must be a FQDNs, without the trailing dot.
  214. # The FQDN of the hosts will be
  215. # `hostname.user.base_domain` (e.g., _myhost.myuser.example.com_).
  216. base_domain: example.com
  217. # Unix socket used for the CLI to connect without authentication
  218. # Note: for production you will want to set this to something like:
  219. unix_socket: /etc/headscale/headscale.sock
  220. unix_socket_permission: "0770"
  221. #
  222. # headscale supports experimental OpenID connect support,
  223. # it is still being tested and might have some bugs, please
  224. # help us test it.
  225. # OpenID Connect
  226. # oidc:
  227. # only_start_if_oidc_is_available: true
  228. # issuer: "https://your-oidc.issuer.com/path"
  229. # client_id: "your-oidc-client-id"
  230. # client_secret: "your-oidc-client-secret"
  231. # # Alternatively, set `client_secret_path` to read the secret from the file.
  232. # # It resolves environment variables, making integration to systemd's
  233. # # `LoadCredential` straightforward:
  234. # client_secret_path: "${CREDENTIALS_DIRECTORY}/oidc_client_secret"
  235. # # client_secret and client_secret_path are mutually exclusive.
  236. #
  237. # # The amount of time from a node is authenticated with OpenID until it
  238. # # expires and needs to reauthenticate.
  239. # # Setting the value to "0" will mean no expiry.
  240. # expiry: 180d
  241. #
  242. # # Use the expiry from the token received from OpenID when the user logged
  243. # # in, this will typically lead to frequent need to reauthenticate and should
  244. # # only been enabled if you know what you are doing.
  245. # # Note: enabling this will cause `oidc.expiry` to be ignored.
  246. # use_expiry_from_token: false
  247. #
  248. # # Customize the scopes used in the OIDC flow, defaults to "openid", "profile" and "email" and add custom query
  249. # # parameters to the Authorize Endpoint request. Scopes default to "openid", "profile" and "email".
  250. #
  251. # scope: ["openid", "profile", "email", "custom"]
  252. # extra_params:
  253. # domain_hint: example.com
  254. #
  255. # # List allowed principal domains and/or users. If an authenticated user's domain is not in this list, the
  256. # # authentication request will be rejected.
  257. #
  258. # allowed_domains:
  259. # - example.com
  260. # # Note: Groups from keycloak have a leading '/'
  261. # allowed_groups:
  262. # - /headscale
  263. # allowed_users:
  264. # - alice@example.com
  265. #
  266. # # If `strip_email_domain` is set to `true`, the domain part of the username email address will be removed.
  267. # # This will transform `first-name.last-name@example.com` to the user `first-name.last-name`
  268. # # If `strip_email_domain` is set to `false` the domain part will NOT be removed resulting to the following
  269. # user: `first-name.last-name.example.com`
  270. #
  271. # strip_email_domain: true
  272. # Logtail configuration
  273. # Logtail is Tailscales logging and auditing infrastructure, it allows the control panel
  274. # to instruct tailscale nodes to log their activity to a remote server.
  275. logtail:
  276. # Enable logtail for this headscales clients.
  277. # As there is currently no support for overriding the log server in headscale, this is
  278. # disabled by default. Enabling this will make your clients send logs to Tailscale Inc.
  279. enabled: false
  280. # Enabling this option makes devices prefer a random port for WireGuard traffic over the
  281. # default static port 41641. This option is intended as a workaround for some buggy
  282. # firewall devices. See https://tailscale.com/kb/1181/firewalls/ for more information.
  283. randomize_client_port: true

3、docker-compose 文件  docker这些安装自行搜索

/xxx/headscale/docker-compose.yml

  1. version: '3'
  2. services:
  3. headscale:
  4. image: headscale/headscale:0.22.0
  5. container_name: headscale
  6. command: headscale serve
  7. restart: unless-stopped
  8. volumes:
  9. - /xxx/headscale/config:/etc/headscale
  10. ports:
  11. - "8081:8081"
  12. - "6030:6030"
  13. headscale-ui:
  14. image: ghcr.io/gurucomputing/headscale-ui:2023.01.30-beta-1
  15. restart: unless-stopped
  16. container_name: headscale-ui
  17. ports:
  18. - "8082:80"

4、部署 docker-compose up -d

5、创建 apikey

docker exec headscale headscale api create

6、创建租户

docker exec headscale headscale user create <USERNAME>

7、nginx 配置  可同域名,也可不同域名,但是不能默认同ip不同端口,会有跨域问题。

  1. server {
  2. server_name 域名;
  3. # Security / XSS Mitigation Headers
  4. add_header X-Frame-Options "SAMEORIGIN";
  5. add_header X-XSS-Protection "1; mode=block";
  6. add_header X-Content-Type-Options "nosniff";
  7. location /web {
  8. proxy_redirect off;
  9. proxy_set_header Host $host;
  10. proxy_set_header X-Real-IP $remote_addr;
  11. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  12. proxy_pass http://127.0.0.1:8082;
  13. }
  14. location / {
  15. proxy_pass http://127.0.0.1:8081;
  16. proxy_http_version 1.1;
  17. proxy_set_header Upgrade $http_upgrade;
  18. proxy_set_header Connection "upgrade";
  19. proxy_set_header Host $host;
  20. proxy_redirect http:// https://;
  21. proxy_buffering off;
  22. proxy_set_header X-Real-IP $remote_addr;
  23. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  24. proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
  25. add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
  26. }
  27. }

8、按提示在网页配置域名和apikey

9、客户端安装

9.1、windows:tailscaled 官方下载

                        安装后执行命令:      

tailscale login --login-server http://<public_ip>:8081

-- advertise-routes=xxx.xxx.xxx.xxx/xx  子网路由,按需

--accept-routes=true

--accept-dns=false

9.2、linux:

        docker 安装:    

  1. docker run -d --name tailscaled \
  2. --restart always \
  3. -v /var/lib:/var/lib \
  4. -v /dev/net/tun:/dev/net/tun \
  5. -v /lib/modules:/lib/modules \
  6. --network=host --privileged=true \
  7. tailscale/tailscale tailscaled
docker exec -it tailscaled tailscale login --login-server http://<public_ip>:8081

 转发配置:

  1. echo 'net.ipv4.ip_forward = 1' | tee /etc/sysctl.d/ipforwarding.conf
  2. echo 'net.ipv6.conf.all.forwarding = 1' | tee -a /etc/sysctl.d/ipforwarding.conf
  3. sysctl -p

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号