service定义:一个正在执行的程序或命令,被叫做进程(process)。 启动之后一直存在、常驻内存的进程,被称作服务(service)
target定义:比如network.target。是一组服务的集合
基本语法:
systemctl start | stop | restart | status 服务名
使用实例:
[root@bigdata001 ~]# systemctl restart NetworkManager
[root@bigdata001 ~]#
[root@bigdata001 ~]# systemctl status NetworkManager
● NetworkManager.service - Network Manager
Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
Active: active (running) since 日 2022-05-01 04:24:59 CST; 2 months 13 days ago
Docs: man:NetworkManager(8)
Main PID: 830 (NetworkManager)
CGroup: /system.slice/NetworkManager.service
└─830 /usr/sbin/NetworkManager --no-daemon
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
[root@bigdata001 ~]#
Centos7使用的是NetworkManager,Centos6使用的是network。只需启动其中一个即可。NetworkManager默认是开启的
查看服务的方法:ll /usr/lib/systemd/system
查看所有服务的状态:
[root@bigdata001 ~]# systemctl list-unit-files
UNIT FILE STATE
proc-sys-fs-binfmt_misc.automount static
dev-hugepages.mount static
dev-mqueue.mount static
......省略部分......
timers.target static
umount.target static
chrony-dnssrv@.timer disabled
fstrim.timer disabled
systemd-readahead-done.timer indirect
systemd-tmpfiles-clean.timer static
274 unit files listed.
[root@bigdata001 ~]#
其中static表示:该服务跟其他服务相关,不能决定是启动状态还是未启动状态
系统开机启动过程如下:
系统运行级别:
查看当前的系统运行级别:
[root@bigdata001 ~]# systemctl get-default
multi-user.target
[root@bigdata001 ~]#
设置系统运行级别:
[root@bigdata001 ~]# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
[root@bigdata001 ~]#
shutdown语法如下:
shutdown [OPTIONS...] [TIME] [WALL...]
shutdown操作如下:
shutdown关机时会调用sync
命令
关机操作其它命令:
shutdown -H now
shutdown -P now
shutdown -r now