1.环境要求
我安装的是JDK1.8,Python2.7.13,刚开始安装的JDK1.6,执行定时任务时,日志文件里面显示/bin/sh: java: command not found,后来换成1.8没问题了。
2.配置任务
(1)安装crond服务
yum install crontabs
命令说明:
/sbin/service crond start //启动服务
/sbin/service crond stop //关闭服务
/sbin/service crond restart //重启服务
/sbin/service crond reload //重新载入配置
查看crond服务状态 输入
service crond status
显示如下表示服务已启动
[root@localhost /]# service crond status
Redirecting to /bin/systemctl status crond.service
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2017-05-15 15:51:05 CST; 9min ago
Main PID: 6550 (crond)
CGroup: /system.slice/crond.service
└─6550 /usr/sbin/crond -n
May 15 15:51:05 localhost.localdomain systemd[1]: Started Command Scheduler.
May 15 15:51:05 localhost.localdomain systemd[1]: Starting Command Scheduler...
May 15 15:51:05 localhost.localdomain crond[6550]: (CRON) INFO (RANDOM_DELAY ...
May 15 15:51:06 localhost.localdomain crond[6550]: (CRON) INFO (running with ...
May 15 15:51:06 localhost.localdomain crond[6550]: (CRON) INFO (@reboot jobs ...
Hint: Some lines were ellipsized, use -l to show in full.
(2).创建作业配置文件(json格式)
{
"job": {
"setting": {
"speed": {
"byte":1048
},
},
"content": [
{
"reader": {
"name": "oraclereader",
"parameter": {
"column" : [
"name","age"
],
"connection":[{
"jdbcUrl":["jdbc:oracle:thin:@192.168.10.15:1521:orcl"],
"table":["TEST_A"],
}],
"password":"123456",
"username":"root",
}
},
"writer": {
"name": "oraclewriter",
"parameter": {
"username": "root",
"password": "111222",
"column": ["filed1","filed2"],
"preSql": [
"delete from TEST_B"
],
"connection":[{
"jdbcUrl":"jdbc:oracle:thin:@192.168.11.18:1521:orcl",
"table":["TEST_B"],
}],
}
}
}
]
}
}
(3).列出crontab文件,输入crontab -l
no crontal for xxx
0,10,20,35,44,50 * * * * python /home/admin/datax3/bin/datax.py /home/admin/mysql2odps.json >>/home/hanfa.shf/log.`date +\%Y\%m\%d\%H\%M\%S` 2>&1,
(4).创建crontab文件(以前从未创建过crontab任务)
5 13 * * * python /home/admin/datax3/bin/datax.py /home/admin/oracle2oracle.json >>/home/hanfa.shf/log.`date +\%Y\%m\%d\%H\%M\%S` 2>&1
5 13 * * *表示每天的13点5分执行这个任务。