服务(service) 本质就是进程,但是是运行在后台的,通常都会监听某个端口,等待其它程序的请求,比如(mysql , sshd 防火墙等),因此我们又称为守护进程,是 Linux 中非常重要的知识点。
在 CentOS7.0 后 不再使用 service ,而是 systemctl
- 查看当前防火墙的状况,关闭防火墙和重启防火墙
service iptables status
开启或关闭防火墙
service ipatbles start
service iptables stop
查看服务名
/etc/init.d/服务名称
列出服务名称
ls -l /etc/init.d/
chkconfig 指令介绍
通过 chkconfig 命令可以给每个服务的各个运行级别设置自启动/关闭
语法:
- chkconfig --list|grep xxx
- chkconfig 服务名 --list
- chkconfig --level 5 服务名 on/off
请将 sshd 服务在运行级别为 5 的情况下,不要自启动
chkconfig --level 5 sshd off
请显示当前系统所有服务的各个运行级别的运行状态
bash> chkconfig --list
2) 案例 2 :请查看 sshd 服务的运行状态
bash> service sshd status
将 sshd 服务在运行级别 5 下设置为不自动启动,看看有什么效果?
bash> chkconfig --level 5 sshd off
4) 案例 4: 当运行级别为 5 时,关闭防火墙。
bash> chkconfig --level 5 iptables off
5) 案例 5: 在所有运行级别下,关闭防火墙
bash> chkconfig iptables off
案例 6: 在所有运行级别下,开启防火墙
bash> chkconfig iptables on
使用细节
chkconfig 重新设置服务后自启动或关闭,需要重启机器 reboot 才能生效