這是一個建立於
的文章,其中的資訊可能已經有所發展或是發生改變。
在企業專案開發中會定時執行對應的job,對於一些簡單少的job可以直接使用調度器調度執行任務。當隨著公司的業務越來越多,執行任務越來越多。那麼直接使用任務調度器調度任務執行會變得臃腫,而且對於任務是動態配置不可實現。如:想某一個時刻停止任務的執行、刪除此任務然後修改更新任務執行時間等,如某一個任務配置到多台機器上如何做到不可用時,進行轉移等問題。
為瞭解決此類問題,我們需要對任務的調度和執行進行分開。有統一的任務調度中心-專門進行任務的調度分發任務工作,各個任務的具體任務執行分配到個個項目中。從而達到對任務的統一配置和管理。
#基礎環境
#GO環境
cd /usr/local/src/
mkdir -p $HOME/gocode/src
#
tar -zxf go1.8.3.linux-amd64.tar.gz #https://www.golangtc.com/download
#
echo -e 'export GOPATH=$HOME/gocode\nexport GOROOT=/usr/local/go\nexport GOBIN=$GOROOT/bin\nexport GOPKG=$GOROOT/pkg/tool/linux_amd64\nexport GOARCH=amd64\nexport GOOS=linux\nexport PATH=.:$PATH:$GOBIN:$GOPKG' >>/etc/profile
#
source /etc/profile
#
go version
go version go1.8.3 linux/amd64
#DB環境
yum install epel-release ntpdate chrony -y
rpm -ivh http://repo.mysql.com/mysql-community-release-el6.rpm
yum install mysql-server mysql-client -y
service mysqld start
mysqladmin -uroot password '123456'
>create database scheduler;grant all privileges on *.* to@192.168.28.131 identified by '12345678';flush privileges;
#scheduler安裝
cd $GOPATH/src
git clone https://github.com/shotdog/scheduler
go get github.com/astaxie/beego
go get github.com/shotdog/quartz
go get github.com/go-sql-driver/mysql
#init db scheduler.sql
mysql -uroot -p scheduler < scheduler.sql
#modify conf/app.conf -->database config
vim scheduler/conf/app.conf
db_path = /usr/bin/mysql
db_host = 192.168.28.131
db_port = 3306
db_user = root
db_pass = 12345678
db_name = scheduler
db_type = mysql
#modify main.go -->database config
func init() {
orm.RegisterDriver("mysql", orm.DRMySQL)
orm.RegisterDataBase("default", "mysql", "root:12345678@/scheduler?charset=utf8&loc=Local")
orm.RegisterModel(&entity.JobInfo{},&entity.JobInfoHistory{},&entity.JobSnapshot{})
}
#scheduler運行
cd $GOPATH
cd src
cd scheduler
go build main.go
./main
#client測試
cd $HOME/src && git clone https://github.com/shotdog/scheduler-client.git
cd scheduler-client
go build main.go
./main
Link
https://github.com/shotdog/scheduler
https://github.com/shotdog/kitty
http://www.quartz-scheduler.org/