CentOS7服务管理

1. 查看服务

1.1. 查看所有运行的服务

[root@centos7 ~]# systemctl -t service

UNIT LOAD ACTIVE SUB DESCRIPTION

auditd.service loaded active running Security Auditing Service

crond.service loaded active running Command Scheduler

dbus.service loaded active running D-Bus System Message Bus

getty@tty1.service loaded active running Getty on tty1

irqbalance.service loaded active running irqbalance daemon

kmod-static-nodes.service loaded active exited Create list of required stati

network.service loaded active exited LSB: Bring up/down networking

NetworkManager-wait-online.service loaded active exited Network Manager Wait On

NetworkManager.service loaded active running Network Manager

polkit.service loaded active running Authorization Manager

postfix.service loaded active running Postfix Mail Transport Agent

rhel-dmesg.service loaded active exited Dump dmesg to /var/log/dmesg

rhel-import-state.service loaded active exited Import network configuration

rhel-readonly.service loaded active exited Configure read-only root supp

rsyslog.service loaded active running System Logging Service

sshd.service loaded active running OpenSSH server daemon

tuned.service loaded active running Dynamic System Tuning Daemon

vmtoolsd.service loaded active running Service for virtual machines

LOAD = Reflects whether the unit definition was properly loaded.

ACTIVE = The high-level unit activation state, i.e. generalization of SUB.

SUB = The low-level unit activation state, values depend on unit type.

31 loaded units listed. Pass --all to see loaded but inactive units, too.

To show all installed unit files use 'systemctl list-unit-files'.

1.2. 查看所有服务

[root@centos7 ~]# systemctl list-unit-files -t service

UNIT FILE STATE

arp-ethers.service disabled

auditd.service enabled

autovt@.service enabled

blk-availability.service disabled

brandbot.service static

console-getty.service disabled

console-shell.service disabled

container-getty@.service static

cpupower.service disabled

crond.service enabled

dbus-org.freedesktop.timedate1.service static

dbus.service static

debug-shell.service disabled

dnsmasq.service disabled

dracut-cmdline.service static

dracut-initqueue.service static

2. 关闭并禁止自动启动服务

[root@centos7 ~]# systemctl stop postfix

[root@centos7 ~]# systemctl disable postfix

Removed symlink /etc/systemd/system/multi-user.target.wants/postfix.service.

[root@centos7 ~]#

3. 还有一部分SysV服务被chkconfig管理

[root@centos7 ~]# chkconfig --list

Note: This output shows SysV services only and does not include native

systemd services. SysV configuration data might be overridden by native

systemd configuration.

If you want to list systemd services use 'systemctl list-unit-files'.

To see services enabled on particular target use

'systemctl list-dependencies [target]'.

netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off

network 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@centos7 ~]# chkconfig netconsole off