10.23 Linux Task Scheduler
crontab -u、-e、-l、-r格式:分 时 日 月 周 user command文件 /var/spool/cron/username分范围 0-59;时范围 0-23;日范围 0-31;月范围 0-12;周范围1-6可用格式 1-5 表示一个范围1到5可用格式 1,2,3 表示1或2或3可用格式 */2 表示被2整除的数字,比如小时,那就是每隔2小时要保证服务是启动状态systemctl start crond.service [[email protected] ~]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executedcrontab -e 编辑任务crontab -l 列出任务crontab -u root -l 列出指定用户任务
10.24 Chkconfig Tools
chkconfig --list chkconfig --level 3 network off chkconfig --level 345 network off chkconfig --del network chkconfig --add network [[email protected] ~]# chkconfig --list 注:该输出结果只显示 SysV 服务,并不包含 原生 systemd 服务。SysV 配置数据 可能被原生 systemd 配置覆盖。 要列出 systemd 服务,请执行 ‘systemctl list-unit-files‘。 查看在具体 target 启用的服务请执行 ‘systemctl list-dependencies [target]‘。 netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关 network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
10.25 Systemd
Systemctl list-units--all--type=service Several commonly used service-related commands systemctl enable Crond.service//Let service boot up systemctl disable Crond//Disable boot SYSTEMCTL status Crond//View status Systemctl stop Crond//Stop service Systemctl start Crond//Start Service Systemctl Restart Crond//Restart service Systemctl is-enable crond//Check if service is started [[email protected] ~]# cat/e Tc/systemd/system/multi-user.target.wants/crond.service [Unit] Description=command Scheduler after=a Uditd.service systemd-user-sessions.service time-sync.target [service] Environmentfile=/etc/sysconfig/crond Execstart=/usr/sbin/crond-n $CRONDARGS execreload=/bin/kill-hup $MAINPID killmode=process [I Nstall] Wantedby=multi-user.target [[email protected] ~]# ls-l/ETC/SYSTEMD/SYSTEM/MULTI-USER.TARGET.W Ants/crond.service lrwxrwxrwx. 1 root root 37 February 05:03/etc/systemd/system/multi-user.target.wants/crond.service-/usr/lib/systemD/system/crond.service
10.26 Unit Introduction
Ls/usr/lib/systemd/system//System all unit, divided into the following types
Service System Services target multiple unit group device Hardware Device 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 Snapshot SYSTEMD snapshot socket interprocess communication socket swap file timer timer [[email protected] system]# Cd/usr/lib/sy Stemd/system [[email protected] system]# ls-l runlevel* lrwxrwxrwx. 1 root root 15 March 2 04:46 runlevel0.target-Poweroff.target lrwxrwxrwx. 1 root root 13 March 2 04:46 runlevel1.target-Rescue.target lrwxrwxrwx. 1 root root 17 March 2 04:46 runlevel2.target-Multi-user.target lrwxrwxrwx. 1 root root 17 March 2 04:46 runlevel3.target-Multi-user.target lrwxrwxrwx. 1 root root 17 March 2 04:46 runlevel4.target-Multi-user.target lrwxrwxrwx. 1 root root 16 March 2 04:46 runlevel5.target-Graphical.target lrwxrwxrwx. 1 root root 13 March 2 04:46 runlevel6.target-Reboot.targetunit related commands systemctl list-units//list running Unitsystemctl l Ist-units--all//list all, including failed or inactive Systemctl list-uNITs--all--state=inactive//list inactive unitsystemctl list-units--type=service//list servicesystemctl Is-ac with active status tive crond.service//See if a service is active [[email protected] system]# systemctl is-active crond.service Active [[email protected] system]# systemctl is-enabled Crond.service enabled
10.27 Target Introduction
The system manages Unitsystemctl list-unit-files--type=targetsystemctl list-dependencies multi-user.target//view specified for easy management with target What Unitsystemctl is under target get-default//view system default Targetsystemctl Set-default Multi-user.target//Set system default target one Servic E belongs to one type of unit multiple unit consisting of a target with a target containing multiple servicecat/usr/lib/systemd/system/sshd.service//See [Install] section [[email protected] system]# systemctl get-default multi-user.target [[email protected] system]# Systemctl Set-default Multi-user.target removed symlink/etc/systemd/system/default.target. Created symlink from/etc/systemd/system/default.target To/usr/lib/systemd/system/multi-user.target. [[email protected] system]# cat/usr/lib/systemd/system/sshd.service [Unit] description=openssh Server daemon DOCUMENTATION=MAN:SSHD (8) Man:sshd_config (5) After=network.target Sshd-keygen.service Wants=sshd-keygen.service [Service] Type=notify environmentfile=/etc/sysconfig/sshd Execstart=/usr/sbin/sshd-d $OPTIONS execreload=/bin/kill-hup $MAINPID killmode=process restart=on-failure RestartSec= 42s [Install] Wantedby=multi-user.target
2018-03-26 Linux Learning