日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

在CentOS下安装crontab服务

發布時間:2025/5/22 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在CentOS下安装crontab服务 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天在測試機上 配置crontab時發現它沒有 安裝,所以趕緊安裝一個.



CentOS 版本:5.7


操作步驟



1. 確認crontab是否安裝:

執行 crontab 命令如果報 command not found,就表明沒有安裝

2. 安裝 crontab

執行 yum install -y vixie-cron

3. 確認是否安裝成功:

執行 crontab -e


4. 看是否設置了開機自動啟動

chkconfig --list crond

5. 啟動crontab

service crond start




詳細記錄


[root@node16 eap_designer]# crontab -e
-bash: crontab: command not found
[root@node16 eap_designer]# yum install -y crontab
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
base? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?| 1.1 kB? ???00:00? ?
extras? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? | 2.1 kB? ???00:00? ?
extras/primary_db? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???| 171 kB? ???00:00? ?
updates? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?| 1.9 kB? ???00:00? ?
updates/primary_db? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? | 464 kB? ???00:01? ?
Setting up Install Process
No package crontab available.
Nothing to do
[root@node16 eap_designer]# yum install -y cron
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
Setting up Install Process
No package cron available.
Nothing to do
[root@node16 eap_designer]# yum install -y crond
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
Setting up Install Process
No package crond available.
Nothing to do
[root@node16 eap_designer]# yum install -y crontab
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
Setting up Install Process
No package crontab available.
Nothing to do
[root@node16 eap_designer]# yum install -y crontabs
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
Setting up Install Process
Package crontabs-1.10-8.noarch already installed and latest version
Nothing to do
[root@node16 eap_designer]# crontab
-bash: crontab: command not found



[root@node16 eap_designer]# cd
[root@node16 ~]#
[root@node16 ~]#

查了一下資料,才知道它不叫cron,crond,crontab,crontabs,它叫vixie-cron
[root@node16 ~]# yum install -y vixie-cron
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package vixie-cron.i386 4:4.1-77.el5_4.1 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================
Package? ?? ?? ?? ?? ?? ?? ?? ? Arch? ?? ?? ?? ?? ?? ?? ? Version? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? Repository? ?? ?? ?? ?? ???Size
====================================================================================================================================
Installing:
vixie-cron? ?? ?? ?? ?? ?? ?? ? i386? ?? ?? ?? ?? ?? ?? ? 4:4.1-77.el5_4.1? ?? ?? ?? ?? ?? ?? ?? ? base? ?? ?? ?? ?? ?? ?? ???79 k

Transaction Summary
====================================================================================================================================
Install? ?? ? 1 Package(s)
Upgrade? ?? ? 0 Package(s)

Total download size: 79 k
Downloading Packages:
vixie-cron-4.1-77.el5_4.1.i386.rpm? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?|??79 kB? ???00:00? ?
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
??Installing? ???: vixie-cron? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?1/1

Installed:
??vixie-cron.i386 4:4.1-77.el5_4.1? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?

Complete!



[root@node16 ~]# crontab -l
no crontab for root
[root@node16 ~]#
[root@node16 ~]# chkconfig --list crontab
在 crontab 服務中讀取信息時出錯:沒有那個文件或目錄
[root@node16 ~]# chkconfig --list cron
在 cron 服務中讀取信息時出錯:沒有那個文件或目錄
[root@node16 ~]# chkconfig --list
anacron? ?? ?? ?0:關閉??1:關閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關閉
avahi-daemon? ? 0:關閉??1:關閉??2:關閉??3:啟用??4:啟用??5:啟用??6:關閉
avahi-dnsconfd??0:關閉??1:關閉??2:關閉??3:關閉??4:關閉??5:關閉??6:關閉
crond? ?? ?? ???0:關閉??1:關閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關閉
gpm? ?? ?? ?? ? 0:關閉??1:關閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關閉
haldaemon? ?? ? 0:關閉??1:關閉??2:關閉??3:啟用??4:啟用??5:啟用??6:關閉
iscsi? ?? ?? ???0:關閉??1:關閉??2:關閉??3:啟用??4:啟用??5:啟用??6:關閉
iscsid? ?? ?? ? 0:關閉??1:關閉??2:關閉??3:啟用??4:啟用??5:啟用??6:關閉
jexec? ?? ?? ???0:啟用??1:啟用??2:啟用??3:啟用??4:啟用??5:啟用??6:啟用
kudzu? ?? ?? ???0:關閉??1:關閉??2:關閉??3:啟用??4:啟用??5:啟用??6:關閉
lvm2-monitor? ? 0:關閉??1:啟用??2:啟用??3:啟用??4:啟用??5:啟用??6:關閉
mcstrans? ?? ???0:關閉??1:關閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關閉
messagebus? ?? ?0:關閉??1:關閉??2:關閉??3:啟用??4:啟用??5:啟用??6:關閉
multipathd? ?? ?0:關閉??1:關閉??2:關閉??3:關閉??4:關閉??5:關閉??6:關閉
mysql? ?? ?? ???0:關閉??1:關閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關閉
netconsole? ?? ?0:關閉??1:關閉??2:關閉??3:關閉??4:關閉??5:關閉??6:關閉
netfs? ?? ?? ???0:關閉??1:關閉??2:關閉??3:啟用??4:啟用??5:啟用??6:關閉
netplugd? ?? ???0:關閉??1:關閉??2:關閉??3:關閉??4:關閉??5:關閉??6:關閉
network? ?? ?? ?0:關閉??1:關閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關閉
rawdevices? ?? ?0:關閉??1:關閉??2:關閉??3:啟用??4:啟用??5:啟用??6:關閉
rdisc? ?? ?? ???0:關閉??1:關閉??2:關閉??3:關閉??4:關閉??5:關閉??6:關閉
restorecond? ???0:關閉??1:關閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關閉
sshd? ?? ?? ?? ?0:關閉??1:關閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關閉
syslog? ?? ?? ? 0:關閉??1:關閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關閉
tcsd? ?? ?? ?? ?0:關閉??1:關閉??2:關閉??3:關閉??4:關閉??5:關閉??6:關閉
xfs? ?? ?? ?? ? 0:關閉??1:關閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關閉
[root@node16 ~]# chkconfig --list crond
crond? ?? ?? ???0:關閉??1:關閉??2:啟用??3:啟用??4:啟用??5:啟用??6:關閉
[root@node16 ~]# service crond
用法: /etc/init.d/crond {start|stop|status|reload|restart|condrestart}
[root@node16 ~]# service crond status
crond 已停
[root@node16 ~]#





[root@node16 ~]#
[root@node16 ~]# service crond start
啟動 crond:? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???[確定]
[root@node16 ~]# service crond status
crond (pid??16932) 正在運行...

[root@node16 ~]#


完成了上面基礎工作后,就來看看怎么使用crontab定時執行PHP腳本:
(1)我在/root下新建test.php文件,內容如下:
  • <?php
  • #!/usr/bin/php -q
  • echo date('Y-m-d H:i:s')."from http://www.phpddt.com \n";
  • ?>

  • 說明:你可以用whereis php查找php執行文件位置。 在命令行輸入php -q test.php 測試你寫的PHP程序是否可以正常運行


    (2)然后crontab -e編寫如下shell:
  • * * * * * /usr/bin/php -f /root/test.php >> test.log

  • 說明:test.php必須為可執行文件:chmod +x test.php
    測試結果很正常,截圖如下:

    當然你可以用使用crontab -e繼續添加任務,在/var/spool/cron下你可以看到一個root文件。

    可以看可以用tail -f /var/log/cron觀察日志
    也可用ps -aux | grep cron 查看所有的進程

    《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

    總結

    以上是生活随笔為你收集整理的在CentOS下安装crontab服务的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。