服务开机启动(code=exited, status=203/EXEC)错误,由于SELinux 开启安全模式

cshan_ 2024-07-30 15:37:03 阅读 55

开机自启动配置:

在网上看了好多关于 出现 (code=exited, status=203/EXEC)错误的原因,主要有以下几点:

原因1 :systemctl执行脚本时需要知道脚本的解释器

原因2:目标目录的执行权限不够

原因3:要执行的脚本编码格式不正确

原因4:定义的workingdirectory路径有问题

参考连接:定义服务开机启动code=exited status=203/exec 错误 systemctl 自定义service执行shell脚本时报错code exited status 203 EXEC_(code=exited, status=203/exec)-CSDN博客

bug,以上问题都不是我出现问题的真正原因,我碰到的是 由于SELinux 开启安全模式(SELinux 主要作用就是最大限度地减小系统中服务进程可访问的资源)导致不能设置开机自启动service

如何关闭 SELinux:

        两种办法,如果系统无法立刻关闭,建议 先设置临时,同时也去修改配置文件关闭,待合适时机重启服务器

  临时关闭:

[root@SHD-SVR-V3 bin]# getenforce #查看selinux状态

Enforcing

[root@SHD-SVR-V3 bin]# setenforce 0 #临时关闭selinux

[root@SHD-SVR-V3 bin]# getenforce

Permissive

永久关闭(需要重启):

[root@SHD-SVR-V3 bin]# vi /etc/selinux/config

SELINUX=enforcing 修改为 SELINUX=disabled

#重启服务器生效

设置好,再去执行 

[root@SHD-SVR-V3 bin]# systemctl start node_exporter

[root@SHD-SVR-V3 bin]# systemctl status node_exporter

● node_exporter.service - node_exporter Monitoring System

Loaded: loaded (/etc/systemd/system/node_exporter.service; disabled; vendor preset: disabled)

Active: active (running) since Wed 2024-01-03 17:06:38 CST; 7s ago

Main PID: 467456 (node_exporter)

Tasks: 5 (limit: 101075)

Memory: 7.4M

CGroup: /system.slice/node_exporter.service

└─467456 /usr/local/bin/node_exporter --web.listen-address=:9100



声明

本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。