当前位置:网站首页>Quartz分布式实现
Quartz分布式实现
2022-08-09 10:45:00 【猿小飞】
1.项目背景
以前项目都是单体项目,在线上环境发布的时候,都是单机版。后来使用的用户越来越多了。就需要做负载了。因为项目在实际使用的过程中,使用到了定时任务。所以就引入了Quartz框架。
2.出现的问题
2.1.时间不同步的问题
[2021-12-14 11:24:45,956 WARN ] [QuartzScheduler_devScheduler_1-localhost.localdomain1639452248424_ClusterManager] (org.springframework.scheduling.quartz.LocalDataSourceJobStore:?) - This scheduler instance (localhost.localdomain1639452248424) is still active but was recovered by another instance in the cluster. This may cause inconsistent behavior.
当我们应用服务器,出现时间不步的时候,另外一台服务器就会报上面这个错误。
注意了,这个错误出现的频率和你定时事务触发的时间有关,比如你的定时任务是1分钟触发一次,这个错误就会一分钟出现一次。
2.1.1.如何解决这个问题--ntp服务
1.安装 ntp服务进行多台服务器时间同步
rpm -qa|grep ntp
使用该命令,来查询是否已经安装了ntp服务。
ntp基础概念:ntp的基础知识 - 90swj - 博客园
2.如果没有安装,则可以通过yun命令进行安装
yum -y install ntp
安装成功后,会在/etc目录下,会有ntp.conf配置文件。
3.修改配置信息,新增这样的信息:
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
代表允许192.168网段的服务器与此服务器进行时间同步。
参数说明:
用restrict控管权限
nomodify – 用户端不能更改ntp服务器的时间参数
noquery – 用户端不能使用ntpq,ntpc等命令来查询ntp服务器
notrap – 不提供trap远端登陆
restrict 192.168.1.129 nomodify notrap nopeer noquery //当前节点IP地址
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap //集群所在网段的网关(Gateway),子网掩码
修改前:
主节点:
fudge 127.127.1.0 stratum 10 的含义?
fudge 127.127.1.0 stratum 10通常上面还有一行不能少server 127.127.1.0 意思
是当没有时间同步来源的时候以自身的硬件时钟为准,这里的stratum是代表层级,默认是10。
特别注意:这里如果把server都屏蔽掉,运行一段时间后,他不和外部的网络时间同步,也会出现自己跑快的现象。所以解决方法是,我们可以连一下 阿里云的授时网站:
# 国家授时中心
210.72.145.44
# 阿里云
ntp.aliyun.com
s1a.time.edu.cn 北京邮电大学
s1b.time.edu.cn 清华大学
s1c.time.edu.cn 北京大学
s1d.time.edu.cn 东南大学
s1e.time.edu.cn 清华大学
s2a.time.edu.cn 清华大学
s2b.time.edu.cn 清华大学
s2c.time.edu.cn 北京邮电大学
s2d.time.edu.cn 西南地区网络中心
s2e.time.edu.cn 西北地区网络中心
s2f.time.edu.cn 东北地区网络中心
s2g.time.edu.cn 华东南地区网络中心
s2h.time.edu.cn 四川大学网络管理中心
s2j.time.edu.cn 大连理工大学网络中心
s2k.time.edu.cn CERNET桂林主节点
s2m.time.edu.cn 北京大学
ntp.sjtu.edu.cn 202.120.2.101 上海交通大学
实际最后我修改的配置文件为:
4.启动服务
service ntpd start
4.1.开机自启动
chkconfig ntpd on
5.查看ntp服务器有无和上层ntp连通
ntpstat
6.客户端服务器也安装ntp服务,同时修改配置文件
7.客户端也需要开机自启动
chkconfig ntpd on
微信扫一扫:关注我个人订阅号“猿小飞”,更多精彩文章在这里及时发布:
边栏推荐
- 力扣(LeetCode)220. 存在重复元素 III(2022.08.08)
- 备份mongodb数据库(认证)
- tensor.eq() tensor.item() tensor.argmax()
- How tall is the B+ tree of the MySQL index?
- 史上最小白之《Word2vec》详解
- Probably 95% of the people are still making PyTorch mistakes
- cnn的输入输出
- 批量转换经纬度的网页实现方法
- 学习NET-SNMP之二-----------VisualStudio编译Net-SNMP
- Cpolar内网穿透的面板功能介绍
猜你喜欢
Tensorflow realize parameter adjustment of linear equations
activemq 消息持久化
Electron application development best practices
【原创】JPA中@PrePersist和@PreUpdate的用法
RTP
机器学习--朴素贝叶斯(Naive Bayes)
[Original] Usage of @PrePersist and @PreUpdate in JPA
The complete grammar of CSDN's markdown editor
深度学习--神经网络(基础讲解)
【 original 】 VMware Workstation implementation Openwrt soft routing, the ESXI, content is very detailed!
随机推荐
unix环境编程 第十四章 14.4 I/O多路转接
OpengGL绘制立方体的三种方法
15.8 the semaphore Unix environment programming chapter 15
用Word写代码
【 original 】 VMware Workstation implementation Openwrt soft routing, the ESXI, content is very detailed!
VBA实战(11) - 工作表(Sheet) 操作汇总
Preparation for gold three silver four: how to successfully get an Ali offer (experience + interview questions + how to prepare)
unix环境编程 第十四章 14.8 存储映射I/O
强化学习 (Reinforcement Learning)
1001 害死人不偿命的(3n+1)猜想 (15 分)
CSDN的markdown编辑器语法完整大全
Invisible OOM in kubernetes
unix系统编程 第十五章 15.2管道
10000以内素数表(代码块)
[Original] Usage of @PrePersist and @PreUpdate in JPA
类与对象 (下)
unix环境编程 第十五章 15.3 函数popen和pclose
情感分析SowNLP词库
[Error record] Solve the problem that ASRock J3455-ITX cannot be turned on without a monitor plugged in
Tensorflow realize parameter adjustment of linear equations