解决selinux 导致的 systemctl code=exited, status=203/EXEC
问题来源
postgrest 从ubuntu迁移到rokcy linux。
直接执行postgrest命令可以运行。
创建systemctl 服务,执行sudo systemctl start postgrest出现203错误。
bash
Oct 25 09:48:37 PG01 systemd[1]: Started postgrest.service - REST API for any PostgreSQL database.
Oct 25 09:48:37 PG01 (ostgrest)[158752]: postgrest.service: Unable to locate executable '/usr/local/pgrest/postgrest': Permission denied
Oct 25 09:48:37 PG01 (ostgrest)[158752]: postgrest.service: Failed at step EXEC spawning /usr/local/pgrest/postgrest: Permission denied
Oct 25 09:48:37 PG01 systemd[1]: postgrest.service: Main process exited, code=exited, status=203/EXEC
Oct 25 09:48:37 PG01 systemd[1]: postgrest.service: Failed with result 'exit-code'.
检查postgrest可执行文件 权限组为root, 没有问题。
这种情况很有可能是selinux的问题。
解决办法一(推荐)
bash
#恢复文件的安全上下文
restorecon -rv /usr/local/pgrest/postgrest
解决办法二
bash
#关闭selinux
$ setenforce 0
$ sed -i '/^SELINUX=/c'SELINUX=disabled /etc/selinux/config
SELinux是什么
安全增强型 Linux(SELinux)是一种采用安全架构的 Linux® 系统,它能够让管理员更好地管控哪些人可以访问系统。它最初是作为 Linux 内核的一系列补丁,由美国国家安全局(NSA)利用 Linux 安全模块(LSM)开发而成。
SELinux工作原理
SELinux 定义了每个人对系统上的应用、进程和文件的访问控制。利用安全策略(一组告知 SELinux 哪些能访问,哪些不能访问的规则)来强制执行策略所允许的访问。
当应用或进程(称为主体)发出访问对象(如文件)的请求时,SELinux 会检查访问向量缓存(AVC),其中缓存有主体和对象的访问权限。
开启 SELinux 可以提升系统的安全性,但同时也会带来一些问题。在特定场景有的人会选择关闭 SELinux 以换取更好的兼容性。