服务管理
[root@root ~]# systemctl start 服务名 #启动服务
[root@root ~]#systemctl stop 服务名 #停止服务
[root@root ~]#systemctl restart 服务名 #重启服务
[root@root ~]#systemctl status 服务名 #查看服务状态
[root@root ~]#systemctl enable 服务名 #设置开机自启服务
[root@root ~]#systemctl disable 服务名 #设置开机不启动服务
计划任务
1.at
只能定义24小时内的计划任务
[root@root ~]# at 15:25 #设置一个在当天 15:25 执行的定时任务
at> date > /tmp/date.txt #将当前系统日期时间输出重定向到 /tmp/date.txt 文件
st> #ctrl+d退出at> <EOT> #表示命令输入结束
job 1 at Tue Apr 1 15:25:00 2025
[root@root ~]# at -l
1 Tue Apr 1 15:25:00 2025 a root #查看待执行的定时任务列表
2.crond
crond 是 Linux 系统中用于定期执行任务的守护进程,与之紧密相关的是 cron 服务,它允许用户根据时间安排来自动化执行特定的任务。
[root@lxy tmp]# systemctl status crond
[root@lxy tmp]# crontab -e
* * * * *
分 00-59
时 00-23
日 01-31
月 01-12
周 0-7 0和7 都是周日
#计划任务的配置文件位置: /var/spool/cron/
* * * * * date >> /tmp/date.txt 每分钟执行一次
*/5 * * * * date >> /tmp/date.txt 每隔5分钟执行一次
10 * * * * date >> /tmp/date.txt 每小时的第10分钟执行
10 10 * * * date >> /tmp/date.txt 每天的10点10分钟
10 10 10 * * date >> /tmp/date.txt 每月10号10点10分执行
10 10 10 10 * date >> /tmp/date.txt 每年10月10号10点10分执行
10 10 10 10 7 date >> /tmp/date.txt 每年10月10号10点10分或者每周日10点10分执行
10 10,15,20 * * * date >> /tmp/date.txt 每天的10点10分,15点10分, 20点10分执行
10 10-20 * * * date >> /tmp/date.txt 每天的10点到20点的10分钟执行
系统计划任务
cron.daily/ 每天执行
cron.hourly/ 每小时执行
cron.monthly/ 每月执行
cron.weekly/ 每周执行
/etc/cron.deny 限制用户使用计划
日志服务
系统日志位置: /var/log
计划任务: /var/log/cron
安全日志: /var/log/secure
系统日志: /var/log/messages
启动日志服务:
[root@lxy tmp]# systemctl restart rsyslog
动态监控日志
[root@lxy tmp]# tail -f /var/log/messages
日志规则格式
AAAA.BBBB CCCC
AAAA: 产生日志对象或者接口
cron
local0-local6 自定义
BBBB: 日志的级别
emerg(pianc) 紧急信息
alert 必须注意的信息
crit 危机信息
error 错误信息
warn 警告信息
notice 稍微注意信息
info 正常信息
debug 调试信息
mail.info mail产生的info级别以上的日志
mail.=error mail产生的只要error日志
mail.!=error mail产生的除了error以外日志
CCCC: 保存日志的位置或者文件 异步写 同步写
保存方式:
[root@lxy tmp]# vim /etc/rsyslog.conf
发送到终端
*.info;mail.none;authpriv.none;cron.none /dev/tty1
发送到用户
*.info;mail.none;authpriv.none;cron.none lxy
发送到文件(默认)
*.info;mail.none;authpriv.none;cron.none /tmp/mylog.log
日志轮转(日志切割)
主配置文件: /etc/logrotate.conf
子配置文件: /etc/logrotate.d/
[root@root ~]# vim /etc/logrotate.d/test
/var/log/test.log {
missingok #丢失不提示
notifempty #空文件不切割
rotate 4 #保留份数
weekly #以周为周期 daily monthly yearly
create 0666 lxy lxy #创建的新的日志文件的 权限以及拥有者 所属组
dateext #扩展名是日期
}[root@lxy ~]# logrotate -f /etc/logrotate.d/test

被折叠的 条评论
为什么被折叠?



