Linux_CentOS 中systemctl 管理服務、防火牆 firewalld 以及 SELinux 配置

使用 systemctl 管理服務

systemctl 就是 service chkconfig 這兩個命令的整合,在 CentOS 7 就開始被使用了,systemctl是系統服務管理器命令,它實際上將 service chkconfig 這兩個命令組合到一塊兒。 linux

Syetemclt 管理服務經常使用命令

 

1、啓動服務:systemctl start httpd 2、關閉服務:systemctl stop httpd 3、重啓服務:systemctl restart httpd 4、查看一個服務的狀態:systemctl status httpd 5、查看一個服務是否在運行:systemctl is-active httpd 6、查看當前已經運行的服務:systemctl list-units -t service 7、列出全部服務: systemctl list-units -at service 注意順序 8. 設置開機自啓動: systemctl enable httpd 9. 中止開機自啓動: systemctl disable httpd 10、列出全部自啓動服務: systemctl list-unit-files|grep enabled systemctl list-unit-files|grep disabled systemctl list-unit-files|grep disabled | grep httpd 11、使指定服務重新加載配置:systemctl reload httpd

 

Firewalld 防火牆的設置

CentOS7(RHEL7)開始,官方的標準防火牆設置軟件從 iptables 變動爲 firewalld,相信很多習慣使用iptables 的人會感到十分不習慣,但實際上 firewalld 更爲簡單易用。 centos

 

firewalld 的基本使用:
安全

啓動: systemctl start firewalld
關閉: systemctl stop firewalld 
查看狀態: systemctl status firewalld 
開機禁用 : systemctl disable firewalld 
開機啓用 : systemctl enable firewalld

配置 firewall-cmd :
服務器

查看版本: firewall-cmd --version 查看幫助: firewall-cmd --help 顯示狀態: firewall-cmd --state 查看全部打開的端口: firewall-cmd --zone=public --list-ports 更新防火牆規則: firewall-cmd --reload 查看區域信息: firewall-cmd --get-active-zones 查看指定接口所屬區域: firewall-cmd --get-zone-of-interface=eth0 拒絕全部包:firewall-cmd --panic-on 取消拒絕狀態: firewall-cmd --panic-off 查看是否拒絕: firewall-cmd --query-panic

怎麼開啓一個端口:

firewall-cmd --zone=public --add-port=80/tcp --permanent (–permanent 永久生效,沒有此參數重 啓後失效) 從新載入: firewall-cmd --reload 修改 firewall-cmd 配置後必須重啓 查看: firewall-cmd --zone= public --query-port=80/tcp 刪除: firewall-cmd --zone= public --remove-port=80/tcp --permanent

 

SELinux 防火牆的設置

 

安全加強型 Linux(Security-Enhanced Linux)簡稱 SELinux,它是一個 Linux 內核模塊,也是 Linux 的一個安全子系統。 SELinux 主要由美國國家安全局開發。2.6 及以上版本的 Linux 內核都已經集成了 SELinux 模塊。

SELinux 的結構及配置很是複雜,並且有大量概念性的東西,要學精難度較大。不少 Linux 系統管理員嫌麻煩都把 SELinux 關 閉了。阿里雲安裝的 centos 默認已經關閉了。西部數碼雲服務器默認也是關閉的。 tcp

 

查看 SELinux 狀態: 阿里雲

1、/usr/sbin/sestatus -v ##若是 SELinux status 參數爲 enabled 即爲開啓狀態 SELinux status: enabled 2、 getenforce  ##也能夠用這個命令檢查

關閉 SELinux: spa

1、臨時關閉(不用重啓機器): etenforce 0 ##設置 SELinux 成爲 permissive 模式 setenforce 1 設置 SELinux 成爲 enforcing 模式 2、修改配置文件須要重啓機器: 修改/etc/selinux/config 文件 將 SELINUX=enforcing 改成 SELINUX=disabled
相關文章
相關標籤/搜索