> CentOS > CentOS教程 >

CentOS 7 / RHEL 7 Systemctl Command

There is a new command named “systemctl” on CentOS 7 or RHEL 7 system, this command control the systemd system and service manager. and may be used to introspect and control the state of the system and service manager. it is integrated with “chkconfig” and “service” command. How to use this command in centos 7 system? this post will show you some examples.

CentOS 7 / RHEL 7 Systemctl Command To Start/Stop Service
Assuming you want to start or stop a apache service using the following command:

1

2

3
 systemctl start httpd.service #====> start httpd service

systemctl stop httpd.service   #===> stop httpd service

systemctl restart httpd.service

#===> restart httpd service
 

if you want tostart the service automatically while system startup, issue the following command:

1

2
 systemctl enable httpd.service   #====> start httpd.service while system startup

systemctl disable httpd.service

#=> do not start service while system startup
 

CentOS 7 / RHEL 7 Systemctl Command Check Service Status
Using the following systemctl command to check the status of one service , type:

systemctl status * .service
 

Example:checking the status of smartd service

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19
 [ root @ itsprite Desktop ] # systemctl status smartd.service

smartd.service - Self Monitoring and Reporting Technology ( SMART ) Daemon

Loaded: loaded ( / usr / lib / systemd / system / smartd.service; enabled )

Active: active ( running ) since Wed 2014 - 12 -03 09: 13 : 30 EST; 1h 53min ago

Main PID: 810 ( smartd )

CGroup: / system.slice / smartd.service

└─ 810 / usr / sbin / smartd -n -q never

Dec 03 09: 13 : 30 itsprite systemd [ 1 ] : Started Self Monitoring and Reporting ...n.

Dec 03 09: 13 : 31 itsprite smartd [ 810 ] : smartd 6.2 2013 -07- 26 r3841 [ x86_64-l...d )

Dec 03 09: 13 : 31 itsprite smartd [ 810 ] : Copyright ( C ) 2002 - 13 , Bruce Allen, C...rg

Dec 03 09: 13 : 31 itsprite smartd [ 810 ] : Opened configuration file / etc / smartm...nf

Dec 03 09: 13 : 31 itsprite smartd [ 810 ] : Configuration file / etc / smartmontools...es

Dec 03 09: 13 : 31 itsprite smartd [ 810 ] : Device: / dev / sda, opened

Dec 03 09: 13 : 31 itsprite smartd [ 810 ] : Device: / dev / sda, [ VMware,  VMware Vi...GB

Dec 03 09: 13 : 31 itsprite smartd [ 810 ] : Device: / dev / sda, IE ( SMART ) not enab...ce

Dec 03 09: 13 : 31 itsprite smartd [ 810 ] : Try 'smartctl -s on /dev/sda' to turn...es

Dec 03 09: 13 : 31 itsprite smartd [ 810 ] : Monitoring 0 ATA and 0 SCSI devices

Hint: Some lines were ellipsized, use -l to show in full.

[ root @ itsprite Desktop ]
#
 

(责任编辑:IT)