crontab定时任务

yum install -y cronie     #安装定时任务服务
systemctl restart crond.service      #重启定时任务服务

定时任务没有运行,查看cron运行日志
tail -f /var/log/cron
报如下错误:
May 8 10:14:01 localhost crond[9399]: (root) FAILED to authorize user with PAM (Module is unknown)
May 8 10:14:01 localhost crond[9400]: (root) FAILED to authorize user with PAM (Module is unknown)

解决办法:
1、禁用SELinux,可以使用getenforce命令查看是否禁用。

2、查看用户密码是否过期chage -l root,修改为永不过期(命令:chage -M 9999 root,文件:vi /etc/shadow)

2、修改/etc/cron.allow,添加要运行定时任务的用户
root
myuser

3、修改/etc/pam.d/crond,把session required改成session sufficient,这个对非root用户管用,root用户不需要修改该文件

#
# The PAM configuration file for the cron daemon
#
#
# No PAM authentication called, auth modules not needed
account    required pam_access.so
account    include    password-auth
# session    required pam_loginuid.so
session    sufficient pam_loginuid.so
session    include    password-auth
auth       include    password-auth

4、重启crond服务
/etc/init.d/crond restart

参考链接:
      https://www.generateit.net/cron-job/index.php      #在线生成定时任务
      https://www.cnblogs.com/zoulongbin/p/6187238.html
      http://www.tracefact.net/tech/080.html
      https://www.cnblogs.com/fuhai0815/p/14338928.html
      https://opensource4admin.wordpress.com/2014/07/31/failed-to-authorize-user-with-pam-module-is-unknown-solved/
      https://www.cnblogs.com/SunArmy/p/13096861.html   #centos安装crond服务

posted @ 2021-07-03 19:07  風£飛  阅读(250)  评论(0编辑  收藏  举报