我正在遵循一个演练,指导您在Ubuntu机器上设置节点。 我正在configuration系统以允许节点在端口80上运行的步骤。它(以及我已经看过的一些其他指南)build议运行以下命令:
sudo setcap cap_net_bind_service=+ep /usr/local/bin/node
这将返回以下错误:
Failed to set capabilities on file `/usr/local/bin/node' (Invalid argument) The value of the capability argument is not permitted for a file. Or the file is not a regular (non-symlink) file
任何想法可能会导致这个错误?
为了避免这个错误,可以使用which node来parsing非符号链接可执行文件,例如:
sudo apt-get install libcap2-bin sudo setcap cap_net_bind_service=+ep `readlink -f \`which node\``
“which”命令显示了shell命令的完整path。
弄清楚了。 但是我发现安装了节点,在/ usr / bin / node中创build了一个sym-link,它指向/ etc / alternatives / node中另一个指向/ usr / bin / nodejs中另一个sym-link的sym-link。
运行针对/ usr / bin / nodejs的命令工作。
FWIW,另一个select是使用authbind。 Authbind使用稍微不同的机制来达到与CAP_NET_BIND_SERVICE类似的目的。 即允许非特权应用使用特权端口。
从apt安装:
sudo apt-get update && sudo apt-get install authbind
假设所需的app.js在非特权用户“user”下运行,并且希望绑定到端口80:
sudo touch /etc/authbind/byport/80 sudo chown user:user /etc/authbind/byport/80 sudo 500 /etc/authbind/byport/80
然后像这样运行你的应用程序:
authbind node app.js
如果你想用“永远”(本质上是守护节点应用程序)的东西,那么这是走了:
authbind --deep forever app.js
setcap命令有时失败的一个原因是因为某些文件系统不支持扩展属性。
The filesystem must support attaching capabilities to an executable file, so that a process gains those capabilities when the file is executed.
http://man7.org/linux/man-pages/man7/capabilities.7.html
Docker尤其如此。 Docker使用BTRFS或AUFS存储后端,但也可以使用overlayfs。 Overlayfs支持设置上限,但BTRFS和AUFS(见下文)不支持。
https://github.com/moby/moby/issues/30557
如果您需要使用AUFS运行映像,则必须使用CONFIG_AUFS_XATTR=y运行内核。
出于这个原因, authbind通常是更好的解决scheme。