【linux】解决selinux 导致的 systemctl code=exited, status=203/EXEC

解决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 以换取更好的兼容性。

参考文章:SELinux权限问题导致GreatSQL运行不了的坑

相关推荐
心灵宝贝10 小时前
CentOS 7 安装 unzip-6.0-21.el7.x86_64.rpm 步骤详解(附安装包)
linux·服务器·centos
q***133410 小时前
在linux(Centos)中Mysql的端口修改保姆级教程
linux·mysql·centos
Autism....10 小时前
服务器理解
运维·服务器
Starry_hello world10 小时前
Linux 文件缓冲区
linux
天亮之前_ict10 小时前
【故障排查】intel 服务器安装Win server 2019蓝屏解决方法
运维·服务器
牢七10 小时前
操作系统。
linux
SongYuLong的博客11 小时前
openwrt源码编译环境搭建-安装Luci
linux·嵌入式硬件
熙客11 小时前
Linux:监控命令
linux·运维
飞鱼&11 小时前
Linux 常用命令
linux·运维·服务器
喵了几个咪11 小时前
使用Bazel构建你的Kratos微服务
java·运维·微服务