现象

文件权限正确,但是通过 ·systemd· 启动时仍然报 Permission denied 错误。

文件权限:

[core@localhost ~]$ ll /usr/local/bin/
total 192512
-rwxrwxr-x. 1 core core  39813120 Jun  6 09:00 kubeadm
-rwxrwxr-x. 1 core core  44032000 Jun  6 09:00 kubectl
-rwxrwxr-x. 1 core core 113283800 Jun  6 09:00 kubelet

错误内容:

Jun 06 10:48:52 localhost systemd[1]: Started kubelet: The Kubernetes Node Agent.
Jun 06 10:48:52 localhost systemd[1]: kubelet.service: Main process exited, code=exited, status=203/EXEC
Jun 06 10:48:52 localhost systemd[1]: kubelet.service: Failed with result 'exit-code'.
Jun 06 10:49:02 localhost systemd[1]: kubelet.service: Scheduled restart job, restart counter is at 79.
Jun 06 10:49:02 localhost systemd[1]: Stopped kubelet: The Kubernetes Node Agent.
Jun 06 10:49:02 localhost systemd[13884]: kubelet.service: Failed to execute command: Permission denied
Jun 06 10:49:02 localhost systemd[13884]: kubelet.service: Failed at step EXEC spawning /usr/local/bin/kubelet: Permission denied

解决方案

这个依然是 SELinux 搞的鬼。

这是由于执行文件的 安全上下文 不正确导致的错误,我这边是因为可执行文件是先存放在用户主目录,然后移动到目标目录的。
但是将可执行文件从用户主目录移动到目标目录时它们的 SELinux 上下文不会自动变更,依然是用户主目录。所以出现了问题。

既然知道了原因,那么解决方案也有了,执行下面的命令即可解决。

sudo restorecon -rv /usr/local/bin/

其中 /usr/local/bin/ 时执行文件所在的目录,执行时需要替换成正确的目录。

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐