使用sqlserver搭建高可用双机热备的Quartz集群部署附源码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用sqlserver搭建高可用双机热备的Quartz集群部署附源码相关的知识,希望对你有一定的参考价值。

  一般拿Timer和Quartz相比较的,简直就是对Quartz的侮辱,两者的功能根本就不在一个层级上,如本篇介绍的Quartz强大的集群机制,可以采用基于

sqlserver,mysql的集群方案,当然还可以在第三方插件的基础上实现quartz序列化到热炒的mongodb,redis,震撼力可想而知,接下来本篇就和大家聊

一聊怎么搭建基于sqlserver的quartz集群,实现这么一种双机热备的强大功能。

 

一:下载sqlserver版的建表脚本

    首先大家可以通过github上搜索quartz的源代码,在源码项目的/database/tables目录下,可以找到firebird,oracle,mysql,sqlserver等建库脚本,

本篇只需拿取sqlserver版本即可。 https://github.com/quartznet/quartznet/tree/master/database/tables  如下图所示

 

 

   

     从上面的截图中可以看到,我接下来要做的事情就是增加一个你需要创建的database名字,这里取为:【quartz】,完整的脚本如下:

  1 -- this script is for SQL Server and Azure SQL
  2 
  3 CREATE DATABASE [quartz]
  4 GO
  5 
  6 USE [quartz]
  7 GO
  8 
  9 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N\'[dbo].[FK_QRTZ_TRIGGERS_QRTZ_JOB_DETAILS]\') AND OBJECTPROPERTY(id, N\'ISFOREIGNKEY\') = 1)
 10 ALTER TABLE [dbo].[QRTZ_TRIGGERS] DROP CONSTRAINT FK_QRTZ_TRIGGERS_QRTZ_JOB_DETAILS
 11 GO
 12 
 13 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N\'[dbo].[FK_QRTZ_CRON_TRIGGERS_QRTZ_TRIGGERS]\') AND OBJECTPROPERTY(id, N\'ISFOREIGNKEY\') = 1)
 14 ALTER TABLE [dbo].[QRTZ_CRON_TRIGGERS] DROP CONSTRAINT FK_QRTZ_CRON_TRIGGERS_QRTZ_TRIGGERS
 15 GO
 16 
 17 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N\'[dbo].[FK_QRTZ_SIMPLE_TRIGGERS_QRTZ_TRIGGERS]\') AND OBJECTPROPERTY(id, N\'ISFOREIGNKEY\') = 1)
 18 ALTER TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS] DROP CONSTRAINT FK_QRTZ_SIMPLE_TRIGGERS_QRTZ_TRIGGERS
 19 GO
 20 
 21 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N\'[dbo].[FK_QRTZ_SIMPROP_TRIGGERS_QRTZ_TRIGGERS]\') AND OBJECTPROPERTY(id, N\'ISFOREIGNKEY\') = 1)
 22 ALTER TABLE [dbo].[QRTZ_SIMPROP_TRIGGERS] DROP CONSTRAINT FK_QRTZ_SIMPROP_TRIGGERS_QRTZ_TRIGGERS
 23 GO
 24 
 25 IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N\'[dbo].[FK_QRTZ_JOB_LISTENERS_QRTZ_JOB_DETAILS]\') AND parent_object_id = OBJECT_ID(N\'[dbo].[QRTZ_JOB_LISTENERS]\'))
 26 ALTER TABLE [dbo].[QRTZ_JOB_LISTENERS] DROP CONSTRAINT [FK_QRTZ_JOB_LISTENERS_QRTZ_JOB_DETAILS]
 27 
 28 IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N\'[dbo].[FK_QRTZ_TRIGGER_LISTENERS_QRTZ_TRIGGERS]\') AND parent_object_id = OBJECT_ID(N\'[dbo].[QRTZ_TRIGGER_LISTENERS]\'))
 29 ALTER TABLE [dbo].[QRTZ_TRIGGER_LISTENERS] DROP CONSTRAINT [FK_QRTZ_TRIGGER_LISTENERS_QRTZ_TRIGGERS]
 30 
 31 
 32 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N\'[dbo].[QRTZ_CALENDARS]\') AND OBJECTPROPERTY(id, N\'ISUSERTABLE\') = 1)
 33 DROP TABLE [dbo].[QRTZ_CALENDARS]
 34 GO
 35 
 36 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N\'[dbo].[QRTZ_CRON_TRIGGERS]\') AND OBJECTPROPERTY(id, N\'ISUSERTABLE\') = 1)
 37 DROP TABLE [dbo].[QRTZ_CRON_TRIGGERS]
 38 GO
 39 
 40 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N\'[dbo].[QRTZ_BLOB_TRIGGERS]\') AND OBJECTPROPERTY(id, N\'ISUSERTABLE\') = 1)
 41 DROP TABLE [dbo].[QRTZ_BLOB_TRIGGERS]
 42 GO
 43 
 44 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N\'[dbo].[QRTZ_FIRED_TRIGGERS]\') AND OBJECTPROPERTY(id, N\'ISUSERTABLE\') = 1)
 45 DROP TABLE [dbo].[QRTZ_FIRED_TRIGGERS]
 46 GO
 47 
 48 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N\'[dbo].[QRTZ_PAUSED_TRIGGER_GRPS]\') AND OBJECTPROPERTY(id, N\'ISUSERTABLE\') = 1)
 49 DROP TABLE [dbo].[QRTZ_PAUSED_TRIGGER_GRPS]
 50 GO
 51 
 52 IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N\'[dbo].[QRTZ_JOB_LISTENERS]\') AND type in (N\'U\'))
 53 DROP TABLE [dbo].[QRTZ_JOB_LISTENERS]
 54 
 55 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N\'[dbo].[QRTZ_SCHEDULER_STATE]\') AND OBJECTPROPERTY(id, N\'ISUSERTABLE\') = 1)
 56 DROP TABLE [dbo].[QRTZ_SCHEDULER_STATE]
 57 GO
 58 
 59 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N\'[dbo].[QRTZ_LOCKS]\') AND OBJECTPROPERTY(id, N\'ISUSERTABLE\') = 1)
 60 DROP TABLE [dbo].[QRTZ_LOCKS]
 61 GO
 62 IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N\'[dbo].[QRTZ_TRIGGER_LISTENERS]\') AND type in (N\'U\'))
 63 DROP TABLE [dbo].[QRTZ_TRIGGER_LISTENERS]
 64 
 65 
 66 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N\'[dbo].[QRTZ_JOB_DETAILS]\') AND OBJECTPROPERTY(id, N\'ISUSERTABLE\') = 1)
 67 DROP TABLE [dbo].[QRTZ_JOB_DETAILS]
 68 GO
 69 
 70 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N\'[dbo].[QRTZ_SIMPLE_TRIGGERS]\') AND OBJECTPROPERTY(id, N\'ISUSERTABLE\') = 1)
 71 DROP TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS]
 72 GO
 73 
 74 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N\'[dbo].[QRTZ_SIMPROP_TRIGGERS]\') AND OBJECTPROPERTY(id, N\'ISUSERTABLE\') = 1)
 75 DROP TABLE [dbo].QRTZ_SIMPROP_TRIGGERS
 76 GO
 77 
 78 IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N\'[dbo].[QRTZ_TRIGGERS]\') AND OBJECTPROPERTY(id, N\'ISUSERTABLE\') = 1)
 79 DROP TABLE [dbo].[QRTZ_TRIGGERS]
 80 GO
 81 
 82 CREATE TABLE [dbo].[QRTZ_CALENDARS] (
 83   [SCHED_NAME] [NVARCHAR] (120)  NOT NULL ,
 84   [CALENDAR_NAME] [NVARCHAR] (200)  NOT NULL ,
 85   [CALENDAR] [IMAGE] NOT NULL
 86 )
 87 GO
 88 
 89 CREATE TABLE [dbo].[QRTZ_CRON_TRIGGERS] (
 90   [SCHED_NAME] [NVARCHAR] (120)  NOT NULL ,
 91   [TRIGGER_NAME] [NVARCHAR] (150)  NOT NULL ,
 92   [TRIGGER_GROUP] [NVARCHAR] (150)  NOT NULL ,
 93   [CRON_EXPRESSION] [NVARCHAR] (120)  NOT NULL ,
 94   [TIME_ZONE_ID] [NVARCHAR] (80) 
 95 )
 96 GO
 97 
 98 CREATE TABLE [dbo].[QRTZ_FIRED_TRIGGERS] (
 99   [SCHED_NAME] [NVARCHAR] (120)  NOT NULL ,
100   [ENTRY_ID] [NVARCHAR] (140)  NOT NULL ,
101   [TRIGGER_NAME] [NVARCHAR] (150)  NOT NULL ,
102   [TRIGGER_GROUP] [NVARCHAR] (150)  NOT NULL ,
103   [INSTANCE_NAME] [NVARCHAR] (200)  NOT NULL ,
104   [FIRED_TIME] [BIGINT] NOT NULL ,
105   [SCHED_TIME] [BIGINT] NOT NULL ,
106   [PRIORITY] [INTEGER] NOT NULL ,
107   [STATE] [NVARCHAR] (16)  NOT NULL,
108   [JOB_NAME] [NVARCHAR] (150)  NULL ,
109   [JOB_GROUP] [NVARCHAR] (150)  NULL ,
110   [IS_NONCONCURRENT] BIT  NULL ,
111   [REQUESTS_RECOVERY] BIT  NULL 
112 )
113 GO
114 
115 CREATE TABLE [dbo].[QRTZ_PAUSED_TRIGGER_GRPS] (
116   [SCHED_NAME] [NVARCHAR] (120)  NOT NULL ,
117   [TRIGGER_GROUP] [NVARCHAR] (150)  NOT NULL 
118 )
119 GO
120 
121 CREATE TABLE [dbo].[QRTZ_SCHEDULER_STATE] (
122   [SCHED_NAME] [NVARCHAR] (120)  NOT NULL ,
123   [INSTANCE_NAME] [NVARCHAR] (200)  NOT NULL ,
124   [LAST_CHECKIN_TIME] [BIGINT] NOT NULL ,
125   [CHECKIN_INTERVAL] [BIGINT] NOT NULL
126 )
127 GO
128 
129 CREATE TABLE [dbo].[QRTZ_LOCKS] (
130   [SCHED_NAME] [NVARCHAR] (120)  NOT NULL ,
131   [LOCK_NAME] [NVARCHAR] (40)  NOT NULL 
132 )
133 GO
134 
135 CREATE TABLE [dbo].[QRTZ_JOB_DETAILS] (
136   [SCHED_NAME] [NVARCHAR] (120)  NOT NULL ,
137   [JOB_NAME] [NVARCHAR] (150)  NOT NULL ,
138   [JOB_GROUP] [NVARCHAR] (150)  NOT NULL ,
139   [DESCRIPTION] [NVARCHAR] (250) NULL ,
140   [JOB_CLASS_NAME] [NVARCHAR] (250)  NOT NULL ,
141   [IS_DURABLE] BIT  NOT NULL ,
142   [IS_NONCONCURRENT] BIT  NOT NULL ,
143   [IS_UPDATE_DATA] BIT  NOT NULL ,
144   [REQUESTS_RECOVERY] BIT  NOT NULL ,
145   [JOB_DATA] [IMAGE] NULL
146 )
147 GO
148 
149 CREATE TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS] (
150   [SCHED_NAME] [NVARCHAR] (120)  NOT NULL ,
151   [TRIGGER_NAME] [NVARCHAR] (150)  NOT NULL ,
152   [TRIGGER_GROUP] [NVARCHAR] (150)  Nginx+Keepalived(双机热备)搭建高可用负载均衡环境(HA)

LVS + Keepalived 搭建高可用的负载均衡群集

Keepalived+Haproxy搭建高可用Web群集

使用nginx搭建高可用,高并发的wcf集群

双机热备的Quartz集群

heartbeat+nginx搭建高可用HA集群