linux计划任务管理工具,Dagobah 的安装使用手册 ---- Cron 定时任务管理工具

Dagobah 简介

Dagobash 是用 python 编写的一个简单的基于依赖关系的作业调度器。 Dagobah 允许你使用 Cron 语法安排调度工作,你可以非常简单的通过 web 界面点击拖动来定义每个工作的一系列任务的依赖关系。

Dagobash 可以让你重试失败的单个任务,给你发送有用的工作任务成功和失败的报告,并且可以在多种后台持久化你的数据,这样你就不用担心你的数据丢失了。

github 项目地址:Dagobah

安装

我的基础环境:

Linux

RedHat

CentOS 5.8

2.6.18-308.el5 x86_64 GNU/Linux

Python 版本

Python 2.7

SQLite 安装

pip install pysqlite sqlalchemy alembic

注:这样直接安装 sqlite 可能失败,所以需要先安装下一下软件

yum install sqlite*

MongoDB 安装

pip install pymongo

dagobahd 安装

pip install dagobah

注:在我的现有环境,这样安装的时候,启动 dagobah 会报错,主要是 lxml 软件依赖的 libxml2 在 CentOS 5.8 的默认版本太低(应该哈)

错误为:

和 etree.so 这个动态依赖包相关

查看其依赖关系

ldd /usr/local/lib/python2.7/site-packages/lxml/etree.so

结果

linux-vdso.so.1 => (0x00007fff11af1000)

libxslt.so.1 => /usr/lib64/libxslt.so.1 (0x00002b32a90c9000)

libexslt.so.0 => /usr/lib64/libexslt.so.0 (0x00002b32a92ff000)

libxml2.so.2 => /usr/lib64/libxml2.so.2 (0x00002b32a9511000)

libz.so.1 => /usr/lib64/libz.so.1 (0x00002b32a985c000)

libm.so.6 => /lib64/libm.so.6 (0x00002b32a9a71000)

libpthread.so.0 => /lib64/libpthread.so.0 (0x00002b32a9cf4000)

libc.so.6 => /lib64/libc.so.6 (0x00002b32a9f10000)

libgcrypt.so.11 => /usr/lib64/libgcrypt.so.11 (0x00002b32aa26a000)

libdl.so.2 => /lib64/libdl.so.2 (0x00002b32aa4dc000)

libgpg-error.so.0 => /usr/lib64/libgpg-error.so.0 (0x00002b32aa6e0000)

/lib64/ld-linux-x86-64.so.2 (0x0000003084e00000)

可以看到 libxml2.so.2 是依赖的老的 /usr/lib64/ 下面的包。

解决办法

源码安装 libxml2 和 libxslt

wget http://xmlsoft.org/sources/libxml2-2.9.0.tar.gz

tar -zxvf libxml2-2.9.0.tar.gz

cd libxml2-2.9.0

./configure

make

sudo make install

wget http://xmlsoft.org/sources/libxslt-1.1.27.tar.gz

tar -zxvf libxslt-1.1.27.tar.gz

./configure

make

sudo make install

2、把 安装的 lxml2 导出

export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH

安装 lxml

pip install lxml

4、查看依赖关系

[root@solr]# ldd /usr/local/lib/python2.7/site-packages/lxml/etree.so

linux-vdso.so.1 => (0x00007fff11af1000)

libxslt.so.1 => /usr/lib64/libxslt.so.1 (0x00002b32a90c9000)

libexslt.so.0 => /usr/lib64/libexslt.so.0 (0x00002b32a92ff000)

libxml2.so.2 => /usr/local/lib/libxml2.so.2 (0x00002b32a9511000)

libz.so.1 => /usr/lib64/libz.so.1 (0x00002b32a985c000)

libm.so.6 => /lib64/libm.so.6 (0x00002b32a9a71000)

libpthread.so.0 => /lib64/libpthread.so.0 (0x00002b32a9cf4000)

libc.so.6 => /lib64/libc.so.6 (0x00002b32a9f10000)

libgcrypt.so.11 => /usr/lib64/libgcrypt.so.11 (0x00002b32aa26a000)

libdl.so.2 => /lib64/libdl.so.2 (0x00002b32aa4dc000)

libgpg-error.so.0 => /usr/lib64/libgpg-error.so.0 (0x00002b32aa6e0000)

/lib64/ld-linux-x86-64.so.2 (0x0000003084e00000)

可以看到其依赖关系已经变成 libxml2.so.2 => /usr/local/lib/libxml2.so.2 (0x00002b32a9511000)

4、再次安装 dagobah

pip install dagobah

5、启动 dagobah

./dagobah

dagobah 的默认端口是 9000

在启动的时候,其会生成一个配置文件 ~/.dagobahd.yml

Dagobahd:

# host and port for the Flask app. set host to 0.0.0.0 to listen on all IPs

host: 127.0.0.1

port: 9000

# the app's secret key, used for maintaining user sessions

# WARNING: change this to your own random value!

# an easy way to create a key with python is "import os; os.urandom(24)"

app_secret: 'g\xde\xf5\x06@K\xf5:\x1fmZ\xac\x1fO\xe8\xcd\xde\xcf\x90\xaeY7\x8c\x96'

# credentials for single-user auth

auth_disabled: False

password: dagobah

# choose one of the available backends

# None: Dagobah will not use a backend to permanently store data

# sqlite: use a SQLite database. see the SQLite section in this file

# mongo: store results in MongoDB. see the MongoBackend section in this file

backend: sqlite

# choose one of the available email templates

# None: Dagobah won't send you emails when a job finishes or fails

# text: Simple text format

# basic: Simple, tabular HTML email

email: basic

Logging:

# change to False to disable logging entirely

enabled: True

# specify a full path to the log file

# alternatively, specify "default" to log to a file in the dagobahd directory

logfile: default

# specify the log level to use

# choose one of [debug, info, warning, error, critical]

loglevel: info

Email:

# set host and port of the SMTP server to use to send mail

# e.g. host: smtp.gmail.com port: 587

host: smtp.gmail.com

port: 587

# email server authentication

user: None

password: None

# tls is required for some mail servers, specifically Gmail

use_tls: True

# from address in the emails from Dagobah.

# supports the following special variables within curly brackets {}

# {HOSTNAME}: the machine's hostname

from_address: dagobah@{HOSTNAME}

# list of email addresses to send reports to, e.g. ['myemail@gmail.com']

recipients: []

# sets whether Dagobah sends you emails on successful job completion

send_on_success: True

# sets whether Dagobah sends you emails on job and task failures

send_on_failure: True

SQLiteBackend:

# specify a full path to the sqlite database file

# alternatively, specify "default" to create a database file in the dagobahd directory

filepath: default

MongoBackend:

# connection details to a mongo database

host: localhost

port: 27017

db: dagobah

# names of collections within the db specified above

dagobah_collection: dagobah

job_collection: dagobah_job

log_collection: dagobah_log

如果不想使用默认的端口和IP的话,可以修改配置文件

6、访问 Dagobah

以下截图借用官方的图片

登录

密码在配置文件中

bVcL5d

添加 job

bVcL5g

在 job 下添加任务

bVcL5k

指定任务直接的依赖关系

这个点击任务的图片,然后拖动,就可以画出任务直接的关系了

注:定义任务依赖关系后,好像如果一个任务失败的话,后续的任务还是会继续执行,这个如果我是强关系的话,会有点问题。这个先标注下,后续好好研究下。

bVcL5t

给远程主机添加任务

bVcL5I

注:因为我们使用 pip install dagobah 安装的版本(CentOS 5.8) 是不支持远程服务器的任务添加功能了,所以需要使用源码安装

源码安装 Dagobah

从 github 上获取源码

git clone https://github.com/thieman/dagobah.git

python setup.py install

为了能配置远程的服务器,你需要配置 SSH config

vim ~/.ssh/config

加入以下信息

# Contents of ~/.ssh/config

Host test2

HostName 192.168.0.1

User root

IdentityFile ~/.ssh/id_rsa

Host test1

HostName 192.168.0.2

User root

IdentityFile ~/.ssh/id_rsa

注: test2 是主机 192.168.0.1 的别名

配置 ssh 的免密,使用命令 ssh-keygen 和 ssh-copy-id,你懂的,详细过程就不介绍了

启动 dagobah

dagobahd

注:dagobah 安装后,其命令路径为 /usr/local/bin/dagobahd

缺陷

不能定义 job 和 job 之间的依赖关系

不能定义 task 和 job 之间的依赖关系

task 和 task 依赖的话,如果中间的 task 失败,后续的 task 依然可以继续执行,其设计的原则是一个任务失败,不影响整体任务的执行,但是如果我是强依赖,这样就会有问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值