Eight week class (May 11)
10.23 Linux Task Scheduler cron
10.24 Chkconfig Tools
10.25 SYSTEMD Management Services
10.26 Unit Introduction
10.27 Target Introduction
Extended
1. Anacron http://blog.csdn.net/strikers1982/article/details/4787226
2. XINETD (the default machine does not install this service, requires Yum install xinetd installation) http://blog.sina.com.cn/s/blog_465bbe6b010000vi.html
3. SYSTEMD Custom Startup script http://www.jb51.net/article/100457.htm
Linux Task Scheduler
It could be a shell script, or it could be a separate command. Whatever the form, it takes some time to execute, so you need to determine a time.
Configuration file for Task Scheduler Etc/crontab
Defines the variables, environment variables, command path mailto who sent the message, and the format. If you do not write the user, the default is root
Define commands for a Linux task plan
crontab-e syntax is the same as Vim
For example, set a 3 o'clock in the morning task:
Explain:
0 3 * * *0 points 3 points per day per month daily execution
The/bin/bash description is to execute the shell script after the/user/local/sbin/123.sh followed by the script to execute and then write to log because it is executed every day, so the append is followed by the error log is appended to this file
You can also use ranges to represent time
0 3 1-10 */2 2,5
3:0 A.M. 1-10, */2 is divisible by 2 is the leap month Tuesday Friday
Then start Crond This service to use this task plan
Systemctl Start Crond
Then use to check if the process is started
Or use Systemctl status Crond to check the status of Crond
Systemctl Stop Crond Stop Crond
View current Task Schedule commands
Crontab-l
Delete the current task schedule
Crontab-r
View task schedules for a specified user
Crontab-u root-l
Attention:
1. Sometimes it is possible to write a script that uses a command rather than an absolute path to the command, which may result in an inability to execute.
2. Write an additional log for each task plan, so there are traces to follow.
3. The file location of the task plan is root under the cron root of the/var/spool/cron/root corresponding user, and the other user's cron has the corresponding user name. So you can copy this file directly to another location for backup.
Linux system service Management-chkconfig
So-called crontab firewalld and so on are services, all services so need to have a service management tool.
CENTOS6 is chkconfig, but 7 is equally compatible.
Display the service
Chkconfig--list
To explain, it looks like there are only 2 processes at the moment, so it's strange, where do the other processes go?
Look at the above explanation, this command value shows the SYSV service, does not include the SYSTEMD service, meaning 6 and the previous version of the service management mechanism is sysv,7 with systemd, so SYSTEMD is 7 and later version of the service manager. This very important process can also be seen from the top command.
Where is the specific location path of the Chkconfig managed service?
/etc/init.d/later in the configuration of Ngix MySQL may also need to put the startup script to this path and then use Chkconfig to manage
Can close the service
Chkconfig Network off
0-6 represents a different service level.
0--shut down the machine
Single user centos6 and previous versions
2--is less than 3. One NFS Service
3--Multi-user mode with no image
4--retention Level
5--multi-user with graphical interface
6--restart
There is no level of CENTOS7. 6 and previous versions can define the RunLevel by changing the configuration file/etc/inittab.
Chkconfig can specify that a level is turned on or off
Chkconfig--level 3 Network off/on
You can also put a custom script in the service, you must put the script in the/ETC/INIT.D directory
Then use the command
Chkconfig--add New Service
Of course, the format of this new service file must meet some criteria. Let's take a look. The following two lines are required
Chkconfig:
Description
The above comment means that the service must be started or shut down at run level 2,3,4,5, the priority of the boot is 90, and the priority of the shutdown is 10. 90 is the start priority, 10 is the stop priority, the priority range is 0-100, the greater the number, the lower the priority.
There will be a deletion if it is added
Chkconfig--del Service Name
The service is deleted, the files are still there.
Linux system service Management--SYSTEMD (CENTOS7 Service management mechanism)
commands to display all types of services
Systemctl list-units--all--type=service
If you don't add--all, you won't list the inactive.
Cron service boot/No boot
Systemctl enable/disable Crond
View cron Status
Systemctl Status Crond
Stop cron Service
Systemctl Stop Crond
Start the Cron service
Systemctl Start Crond
Restart
Systemctl Restart Crond
Check that the Cron service is booting up
Systemctl is-enabled Crond
The contents of the Cron configuration file can also be obtained from the above
From the right soft link to the left, to the right is the true file path
A soft link will be generated after the enable, and the soft link will not be disable.
Ls/user/lib/systemd/system is the system, all the unit. Below are the different types of classifications
Service System Services
Target multiple units consisting of groups
Device hardware devices
Mount File System mount point
AutoMount Automatic mount point
Path file or path
Scope is not an external process initiated by SYSTEMD
Slice Process Group
Snapshots of snapshot systemd
Swap swap files
Timer Timer
CentOS7 does not have a 0-6 operating level, but there are runlevel similarities.
Ls-l runlevel*
It was also soft-linked. You can see from the back what exactly it means.
such as Poweroff Shutdown Rescue Rescue Multi-User multi-user graphical graphical reboot restart
You can see that the type of command is target
systemctl list-units lists the running unit
systemctl list-units--all list all, including failed or inactive unit
systemctl list-units--all--state=inactive lists the unit of inactive
systemctl list-units--type=service List service with Active status
systemctl is-active Crond.service See if a service (cron here) is active
What exactly is the relationship between target and unit?
Target is the unit's collection, the unit is managed, and the system manages the unit with target for ease of management.
View units of target type
Systemctl List-unit-files--type=target
See which unit is under the specified target
systemctl list-dependencies multi-user.target Many users of this target under the unit, so that the target can also continue to have target
View the system default target
Systemctl Get-default
To view the system default target file
ls-l/etc/systemd/system/default.target can see actually also a soft link, real file in/lib/systemd/system/multi-user.target
Set the system default target
Systemctl Set-default multi-user.target After setting up soft links will also change
A service belongs to one type of unit multiple unit consisting of a target with a target containing multiple service
Cat/usr/lib/systemd/system/sshd.service View the specifics of the sshd service
"Install"
Wantedby is multi-user.target need, that is to say it belongs to the target multi-user
LINUX20180511 eight-week class cron chkconf systemd unit target