七叶笔记 » Linux » CentOS防火墙开启失败怎么解决

CentOS防火墙开启失败怎么解决

CentOS防火墙开启失败怎么解决

突然之间发现centos 7 的防火墙无法启动,且firewall-cmd命令运行报错,防火墙启动报错如下:

[root@localhost firewalld]# systemctl start firewalld.serviceJob for firewalld.service failed because the control process exited with error code. See "systemctl status firewalld.service" and "journalctl -xe" for details.[root@localhost firewalld]# systemctl status firewalld.service● firewalld.service - firewalld - dynamic firewall daemon   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)   Active: failed (Result: exit-code) since 三 2020-01-08 10:43:48 CST; 10s ago     Docs: man:firewalld(1)  Process: 29630 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=127) Main PID: 29630 (code=exited, status=127)

firewall-cmd命令运行报错如下:(推荐学习:Linux视频教程)

[root@localhost yangl]# firewall-cmd Traceback (most recent call last):  File "/usr/bin/firewall-cmd", line 24, in <module>    from gi.repository import GObjectImportError: No module named gi.repository

究其原因是由于使用了自定义安装的python,并将自己安装的python作为默认python导致(此外,将系统默认的python升级为python3也可能会出现类似问题),因此只需将firewalld和firewall-cmd第一行调用的python改为系统的python即可解决。

我的python链接方式如下:

[root@localhost yangl]# cd /usr/bin/[root@localhost bin]# ll python*lrwxrwxrwx. 1 root root   16 9月  28 2018 python -> /usr/bin/python2lrwxrwxrwx. 1 root root   39 9月  28 2018 python2 -> /share/soft/python-2.7.15/bin/python2.7-rwxr-xr-x. 1 root root 7216 7月  13 2018 python2.7      #系统的pythonlrwxrwxrwx. 1 root root    9 9月  28 2018 python2_old -> python2.7lrwxrwxrwx. 1 root root   36 3月   7 2018 python3 -> /share/soft/python-3.6.4/bin/python3lrwxrwxrwx. 1 root root    7 9月  28 2018 python_old -> python2

因此,只需vi打开/usr/sbin/firewalld 和/usr/bin/firewall-cmd,将其中的第一行由#!/usr/bin/python -Es 改为 #!/usr/bin/python2.7 -Es 即可!

本篇文章来自PHP中文网,CentOS使用教程栏目,更多相关教程请关注本栏目!

相关文章