Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] macOS 下 mosdns -s 安装成系统服务因权限问题不启动 #357

Closed
UptonEdward opened this issue May 27, 2022 · 7 comments
Closed

Comments

@UptonEdward
Copy link

UptonEdward commented May 27, 2022

Bug 描述和复现步骤(必填):

  1. 摘抄wiki中国内外分流/广告屏蔽的配置并进行简单修改,更改log级别为debug,指定了log输出路径
  2. 将geosite.dat和geoip.dat放入mosdns所在路径
  3. 在mosdns目录下
sudo ./mosdns -s install -c config.yaml
sudo ./mosdns -s start
  1. 分别输出
2022-05-27T13:21:32.811+0800	info	v3/main.go:215	install mosdns: done
2022-05-27T13:21:45.464+0800	info	v3/main.go:215	start mosdns: done
  1. mosdns未在指定路径输出log,我将log file写成'./mosdns.log'也无输出
  2. lsof -i:553并没有看到端口占用,且clash将此地址作为上游dns也得不到任何解析

mosdns 的版本号(必填):

v3.8.0-0-g42e20fb

操作系统和 CPU 架构(必填):

macOS amd64

使用的配置文件(必填):


log:
level: debug
file: '/Users/xx/Desktop/服务器/mosdns/mosdns.log'

plugin:

  • tag: main_server # 服务器插件。接收客户端的请求。
    type: server
    args:
    entry:
    - main_sequence
    - modify_ttl

    server: # 监听以下协议和端口
    - protocol: udp
    addr: 127.0.0.1:553
    - protocol: tcp
    addr: 127.0.0.1:553
    - protocol: udp
    addr: '[::1]:553'
    - protocol: tcp
    addr: '[::1]:553'

  • tag: main_sequence
    type: sequence
    args:
    exec:
    - if:
    - query_is_ad_domain
    exec:
    - _block_with_nxdomain
    - _return

    - mem_cache
    
    - if:
        - query_is_local_domain
        - '!_query_is_common'
      exec:
        - forward_local
        - _return
    
    - if:
        - query_is_non_local_domain
      exec:
        - _prefer_ipv4
        - forward_remote
        - _return
    
    - primary:
        - forward_local
        - if:
            - '!response_has_local_ip'
          exec:
            - _drop_response
      secondary:
        - _prefer_ipv4
        - forward_remote
      fast_fallback: 200
      always_standby: true
    
  • tag: 'mem_cache'
    type: 'cache'
    args:
    size: 1024

  • tag: 'modify_ttl'
    type: 'ttl'
    args:
    minimal_ttl: 300
    maximum_ttl: 3600

  • tag: forward_local
    type: fast_forward
    args:
    upstream:
    - addr: https://1.12.12.12/dns-query

  • tag: forward_remote
    type: fast_forward
    args:
    upstream:
    - addr: https://1.1.1.1/dns-query

  • tag: query_is_local_domain
    type: query_matcher
    args:
    domain:
    - 'ext:./geosite.dat:cn'

  • tag: query_is_non_local_domain
    type: query_matcher
    args:
    domain:
    - 'ext:./geosite.dat:geolocation-!cn'

  • tag: query_is_ad_domain
    type: query_matcher
    args:
    domain:
    - 'ext:./geosite.dat:category-ads-all'

  • tag: response_has_local_ip
    type: response_matcher
    args:
    ip:
    - 'ext:./geoip.dat:cn'

mosdns 的 log 记录:

mosdns未输出任何日志

@UptonEdward UptonEdward changed the title [BUG]macOS下mosdns无任何输出,且未占用端口 [BUG]macOS下mosdns不工作,无任何输出,且未占用端口 May 27, 2022
@UptonEdward UptonEdward changed the title [BUG]macOS下mosdns不工作,无任何输出,且未占用端口 [BUG]macOS下mosdns不工作,且不输出任何日志信息,且未占用端口 May 27, 2022
@IrineSistiana
Copy link
Owner

IrineSistiana commented May 27, 2022

配置文件和mosdns没有问题。

可能是macos系统限制了mosdns。

mosdns未输出任何日志

没有日志文件的写权限?

@UptonEdward
Copy link
Author

运行之前是chmod 777 mosdns的啊🤔

@UptonEdward
Copy link
Author

配置文件和mosdns没有问题。

可能是macos系统限制了mosdns。

mosdns未输出任何日志

没有日志文件的写权限?

我去/Library/LaunchDaemons/看了一眼,那个plist确实是被写入了,我uninstall的话也会被删除。

当我尝试着直接把plist内的指令./mosdns -s run -c config.yaml -dir xxxxx拿来用的时候,mosdns就可以输出日志,同时也会正常工作,分流也没问题。

说明sudo ./mosdns -s run这个指令可以让mosdns正常运行,而start就不可以。所以我认为是问题应该是出在sudo ./mosdns -s start那一步,看来这个指令失效了。

@IrineSistiana
Copy link
Owner

-s 这个功能是调用其他包完成的。我没用过 macos 所以也不了解 macos 的启动流程。

如果 mosdns 运行了,它一定会向 stdout 写入三条日志(版本号和配置文件位置),然后再去加载配置文件,打开日志文件等等。如果这个时候出错了错误日志仍然会写近 stdout 。

你可以看看 macos 有没有记下 stdout 里的日志。

@UptonEdward
Copy link
Author

UptonEdward commented May 27, 2022

在stdout文件里找到了,每次./mosdns -s start都会先是:

2022-05-27T20:54:12.464+0800	info	v3/main.go:157	current working directory: /Users/xxx/Desktop/服务器/mosdns
2022-05-27T20:54:12.466+0800	info	v3/main.go:179	mosdns is running as a service
2022-05-27T20:54:12.466+0800	info	v3/main.go:223	mosdns ver: v3.8.0-0-g42e20fb
2022-05-27T20:54:12.466+0800	info	v3/main.go:224	arch: amd64, os: darwin, go: go1.18.1
2022-05-27T20:54:12.466+0800	info	coremain/run.go:65	loading config	{"file": "config.yaml"}

不到一秒之后,在error stdout里就会有这样的输出

2022-05-27T20:54:12.467+0800	fatal	coremain/run.go:37	failed to load config	{"error": "failed to parse the config file: open config.yaml: operation not permitted"}
2022-05-27T20:54:22.516+0800	fatal	coremain/run.go:37	failed to load config	{"error": "failed to parse the config file: open config.yaml: operation not permitted"}
2022-05-27T20:54:32.573+0800	fatal	coremain/run.go:37	failed to load config	{"error": "failed to parse the config file: open config.yaml: operation not permitted"}
2022-05-27T20:54:42.630+0800	fatal	coremain/run.go:37	failed to load config	{"error": "failed to parse the config file: open config.yaml: operation not permitted"}
2022-05-27T20:54:52.681+0800	fatal	coremain/run.go:37	failed to load config	{"error": "failed to parse the config file: open config.yaml: operation not permitted"}

我确认了一下,这个配置文件的权限是全开的(所有人都可以读写),仍然会有这样的问题。在start后面加上-dir也是这样,感觉很奇怪。

@IrineSistiana IrineSistiana added the help wanted Extra attention is needed label May 27, 2022
@IrineSistiana IrineSistiana changed the title [BUG]macOS下mosdns不工作,且不输出任何日志信息,且未占用端口 [BUG] macOS 下 mosdns -s 安装成系统服务因权限问题不启动 May 27, 2022
@UptonEdward
Copy link
Author

找到原因了,要在系统便好设置的安全性与隐私那里把mosdns的完全磁盘访问权限勾选上。如有可能,可否将这个issue pin一下?感觉之后也会有人遇到类似问题...

@IrineSistiana
Copy link
Owner

en,我会写在 wiki 里。

@IrineSistiana IrineSistiana removed the help wanted Extra attention is needed label May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants