What is Systemctl?
Systemctl is the main tool in RHEL7 's service management tool, which incorporates the functionality of the previous services and Chkconfig. You can use it to enable/disable the service either permanently or only in the current session. CentOS 7 inherits this new feature of Rhel 7 , starting with the CentOS 7.x, where CentOS started using the SYSTEMD service instead of daemon, The original management system to start and manage system services related commands are all replaced by the Systemctl command.
The use of Systemctl has made it possible to change the way in which the/ETC/INIT.D startup scripts of the previous system services have changed, and has greatly improved the efficiency of the system services, which has become simple and easy to use.
Second, the use of Systemctl method
Start a service systemctl start Nginx.service
Close a service systemctl stop Nginx.service
Restart a service systemctl restart Nginx.service
Displays the status of a service Systemctl status Nginx.service
Start a service at boot Systemctl enable Nginx.service
Disable a service at boot systemctl disable Nginx.service
Check to see if the service is booting Systemctl is_enable Nginx.service
To use SYSTEMCTL for unified management, do some preparatory work first:
CENTOS7 services are systemctl脚本 stored in:/usr/lib/systemd/, there are systems (System) and users (user) of the points, such as the need to boot without logging on to run the program, preferably there is a system service inside, that is:/usr/ in the Lib/systemd/system directory, each service ends with .service 3 parts: [Unit] , [Service] and[Install]
Nginx nginx.service file [custom]
1 [Unit]2description=Nginx3After=Network.target4 [Service]5Type=forking6pidfile=/usr/local/nginx/logs/Nginx.pid7execstart=/usr/local/nginx/sbin/Nginx8Execreload=/usr/local/nginx/sbin/nginx-s Reload9Execstop=/usr/local/nginx/sbin/nginx-s StopTenprivatetmp=true One [Install] AWantedby=multi-user.target
PHP php.service file [custom]
1 [Unit] 2 description=php 3 after=network.target 4[Service] 5 type=forking 6 execstart=/usr/local/php/sbin/php-fpm 7 execstop=/ Bin/pkill-9 php-fpm 8 privatetmp=true 9[Install]10 Wantedby=multi-user.target
MySQL mysql.service file [custom]
1 [Unit]2description=MySQL Community Server3After=Network.target4After=Syslog.target5 [Install]6wantedby=multi-User.target7alias=Mysql.service8 [Service]9User=MySQLTengroup=MySQL One #systemctl status is based on the PID to determine the operating state of the service Apidfile=/var/run/mysqld/Mysqld.pid - #start the program with root privileges -permissionsstartonly=true the #set the necessary actions before the program starts. such as initializing related directories, etc. -execstartpre=/usr/bin/mysql-systemd-Start pre - #Start the service -execstart=/usr/bin/Mysqld_safe + #Don ' t signal startup success before a ping works -execstartpost=/usr/bin/mysql-systemd-Start Post + #Give up if ping don ' t get a answer Atimeoutsec=600 at #Restart configuration allows Systemctl to generate new processes after the process has been killed, to prevent the service from being hung out -restart= always -privatetmp=false
"Linux Operations" Systemctl