【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运行不了的坑

相关推荐
云中飞鸿1 天前
虚拟机需要连外网,同时笔记本连接wlan,IP经常变,该怎么配置网络?
服务器·网络·tcp/ip
j_xxx404_1 天前
Linux:进程控制(创建/终止/等待/获取退出信息/多进程)
linux·运维·服务器
yuluo_YX1 天前
Alias for Linux/Mac
linux·elasticsearch·macos
冉佳驹1 天前
Linux ——— 磁盘存储原理与文件系统工作机制
linux·磁盘·硬链接·inode·软链接·磁盘线性化·目录的本质
BUG_MeDe1 天前
LINUX MTU/MSS(1500 1460等)的一些理解
linux·运维·服务器
风流倜傥唐伯虎1 天前
Windows 版 Docker 的 Linux 环境(docker-desktop)与 builder-jammy-base:latest 镜像核心区别
linux·docker·容器
曹牧1 天前
Nginx:正向代理与反向代理
运维·nginx
Ha_To1 天前
2026.1.30 搭建docker仓库
运维·docker·容器
lpfasd1231 天前
Docker Desktop 在国内使用的囧境:镜像拉取失败、加速器失效与破局之道
运维·docker·容器
江湖有缘1 天前
Docker部署SurveyKing调查问卷系统和考试系统
运维·docker·容器