首頁  >  文章  >  運維  >  CentOS防火牆開啟失敗怎麼解決

CentOS防火牆開啟失敗怎麼解決

angryTom
angryTom原創
2020-03-17 18:17:574980瀏覽

CentOS防火牆開啟失敗怎麼解決

CentOS防火牆開啟失敗怎麼解決

#突然發現centos 7 的防火牆無法啟動,且firewall-cmd指令運行報錯,防火牆啟動報錯如下:

[root@localhost firewalld]# systemctl start firewalld.service
Job 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 GObject
ImportError: 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/python2
lrwxrwxrwx. 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      #系统的python
lrwxrwxrwx. 1 root root    9 9月  28 2018 python2_old -> python2.7
lrwxrwxrwx. 1 root root   36 3月   7 2018 python3 -> /share/soft/python-3.6.4/bin/python3
lrwxrwxrwx. 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使用教學欄目,更多相關教學請關注本專欄!

以上是CentOS防火牆開啟失敗怎麼解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn