自有服务,可以简单理解为Linux系统开机自动运行的服务。
一.CentOS6与CentOS7差异
CentOS6/RHEL6:
service命令(管理服务开启、停止以及重启)+ chkconfig(定义开机启动项)
service 服务名称 start|stop|restart
CentOS7/RHEL7:
systemctl命令 = system系统 + control控制(服务管理+开启启动项管理)
systemctl start|stop|restart 服务名称
二.显示系统服务
1.列出系统所有服务
systemctl list-units --type service --all
2.列出系统已经启动的服务
systemctl list-units --type service
3.列出服务依赖性
systemctl list-dependencies
Tips:可以和管道结合使用查看我们所需要的服务
三.自有服务管理
systemctl status 系统服务名称 #查看服务状态
systemctl stop 系统服务名称 #停止服务
systemctl start 系统服务名称 #启动服务
systemctl restart 系统服务名称 #重启服务
systemctl reload 系统服务名称 #热重载,只重新加载指定服务的配置文件
systemctl enable 系统服务名称 #开机自启
systemctl disable 系统服务名称 #开机不自启
systemctl enable --now 系统服务名称 #开机自启并立即开启
systemctl mask 系统服务名称 #冻结服务
systemctl unmask 系统服务名称 #解冻服务
四.系统运行模式
1.CentOS6的运行级别
0 系统关机状态
1 单用户工作状态 Single user mode
2 多用户状态(没有NFS) Multiuser, without NFS (The same as 3, if you do not have networking)
3 多用户状态(有NFS) Full multiuser mode (字符模式,服务基本都是此模式)
4 系统未使用,留给用户 unused
5 图形界面 X11 (图形模式,个人计算机都是此模式)
6 系统正常关闭并重新启动 reboot
2.CentOS7的运行级别
0 shutdown.target
1 emergency.target
2 rescure.target
3 multi-user.target 字符模式
4 无
5 graphical.target 图形模式
6 无
3.运行级别控制
systemctl get-default #查看系统运行模式
systemctl set-default 运行级别(CentOS7) #设定系统运行模式
init 0 #关机
init 6 #重启
init 3 #字符模式
init 5 #图形模式
4.CentOS6中的chkconfig
chkconfig是当前不生效,Linux重启之后才生效的命令(开机自启动项)
service是即使生效,重启后失效的命令
CentOS6中
1.设置服务开机启动
chkconfig network on
2.查看是否成功
chkconfig --list |grep sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
0 关机模式
1 单用户模式
2 多用户模式(无NFS)
3 字符模式
4 自定义模式
5 图形模式
6 重启模式
网上找的: