7系统管理
系统管理
概念
进程
服务
守护进程
查看有哪些服务
命令
systemctl
用法:systemctl start|stop|restart|status 服务名
案例:
systemctl stop NetworkManger # 关闭网络服务
运行级别
centos7的运行级别
查看当前的系统运行级别:systemctl get-default
[root@192 ~]# systemctl get-default graphical.target
修改当前的系统运行级别:systemctl set-default
[root@192 ~]# systemctl set-default graphical.target
配置服务开机自启动
centos6
chkconfig --list # 查询系统服务的运行级信息
chkconfig network off # 将network服务的开机自启动选项关闭 chkconfig network on # 将network服务的开机自启动选项开启 chkconfig --level 3 network off # 将运行级别3的network服务开启自启动选项关闭
centos7
查看某个服务是否为开机自启动:systemctl status 服务名
[root@192 ~]# systemctl status NetworkManager # 查看networkmanager服务是否为开机自启动 enabled表示开机自启动 ● NetworkManager.service - Network Manager Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled) Active: inactive (dead) Docs: man:NetworkManager(8)
将某个服务的开机自启动选项关闭:systemctl disable 服务名
[root@192 ~]# systemctl disable NetworkManager # 将networkmanager服务的自启动选项设置为关闭 # disable表示关闭,NetworkManger为服务名 Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service. Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service. Removed symlink /etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service. [root@192 ~]# systemctl status NetworkManager # 再次查看状态。当前为disabled表示关闭状态 ● NetworkManager.service - Network Manager Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:NetworkManager(8)
将某个服务的开机自启动选项开启:systemctl enable 服务名
[root@192 ~]# systemctl enable NetworkManager # 将networkManger服务的开机自启动选项设置为开启 # enable表示开启,后者为服务名 [root@192 ~]# systemctl status NetworkManager # 再次查看状态。enabled表示开启 ● NetworkManager.service - Network Manager Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled) Active: inactive (dead) Docs: man:NetworkManager(8)
查看开机自启动列表:systemctl list-unit-files
[root@192 ~]# systemctl list-unit-files UNIT FILE STATE proc-sys-fs-binfmt_misc.automount static dev-hugepages.mount static dev-mqueue.mount static proc-fs-nfsd.mount static proc-sys-fs-binfmt_misc.mount static run-vmblock\x2dfuse.mount disabled sys-fs-fuse-connections.mount static sys-kernel-config.mount static sys-kernel-debug.mount static tmp.mount disabled var-lib-nfs-rpc_pipefs.mount static brandbot.path disabled cups.path enabled systemd-ask-password-console.path static systemd-ask-password-plymouth.path static systemd-ask-password-wall.path static session-2.scope static session-3.scope static session-6.scope static abrt-ccpp.service enabled abrt-oops.service enabled
关闭和开启防火墙服务systemctl start/stop firewalld(加不加service都行)
[root@192 ~]# systemctl stop firewalld.service # 关闭防火墙,stop表示关闭,换成start表示开启 [root@192 ~]# systemctl status firewalld # 再次查看防火墙状态。inactive表示关闭 ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: inactive (dead) since 二 2024-01-09 20:04:56 CST; 2s ago Docs: man:firewalld(1) Process: 757 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS) Main PID: 757 (code=exited, status=0/SUCCESS)
关机重启
sync:将数据从内存中同步到硬盘
halt:停机关闭系统,但不断电
poweroff:关机,断电
reboot:重启
shutdown 选项 时间
shutdown的选项
- -H:相当于--halt,停机
- -h:相当于poweroff,关机
- -r :相当于reboot,重启
shutdown的时间
- now:立刻关机
- 数字:等待多久关机(单位:分钟)
- 时间:到几点关机(15:20)