1. 使用 systemctl 管理服务
systemctl 是系统服务管理器命令,它是 service 和 chkconfig 这两个命令的整合,在 CentOS 7 就开始被使用。
1. 启动服务;
systemctl start httpd
2. 关闭服务;
systemctl stop hettpd
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
11. 列出所有开机非自启动的服务;
systemctl list-unit-files | grep disabled
12. 将指定服务重新加载;
systemctl reload httpd
2. Firewalld 防火墙的设置
1. 临时启动防火墙;
systemctl start firewalld
2. 临时关闭防火墙;
systemctl stop firewalld
3. 查看防火墙状态;
systemctl status firewalld
4. 开机禁用防火墙;
systemctl disable firewalld
5. 开机启用防火墙;
systemctl enable firewalld
6. 显示防火墙的状态;
firewall-cmd --state
7. 查看所有打开的端口;
firewall-cmd --zone=public --list-ports
8. 查询80端口;
firewall-cmd --zone= public --query-port=80/tcp
9. 开启80端口;
firewall-cmd --zone=public --add-port=80/tcp --permanent
10. 关闭80端口;
firewall-cmd --zone= public --remove-port=80/tcp --permanen
11. 重新载入(修改防火墙配置后必须重新载入);
firewall-cmd --reload
3. SELinux 防火墙的设置
安全增强型 Linux(Security-Enhanced Linux)简称 SELinux,它是一个 Linux 内核模块,也是 Linux 的一个安全子系统。 SELinux 主要由美国国家安全局开发,2.6 及以上版本的 Linux 内核都已经集成了 SELinux 模块。
SELinux 的结构及配置非常复杂,而且有大量概念性的东西,学习难度较大。很多 Linux 系统管理员嫌麻烦都把 SELinux 关闭了,阿里云安装的 centos 默认已经关闭了,西部数码云服务器默认也是关闭的。
1. 查看ESLinux信息;
/usr/sbin/sestatus -v
2. 查看ESLinux是否开启;
getenforce
3. 关闭ESLinux;
setenforce 0
关闭后不用重启服务器。
4. 开启ESLinux;
setenforce 1
开启后不用重启服务器。
5. 修改配置文件;
vi /etc/selinux/config
在该文件中将将 SELINUX=enforcing 改为 SELINUX=disabled 即可关闭防火墙,修改配置文件后需要重启服务器。