解决服务器时间回跳的问题

检查时间是否会回跳

#需要多执行几次,检查local time和rtc time是否一致,如果不一致就有可能导致时间回跳
timedatectl status

安装时间同步服务

#centos
yum install chrony
systemctl enable chronyd.service

配置时间同步服务

vim /etc/chrony.conf

配置文件样例

# 同步使用的端口
acquisitionport 1123

# 存储Server时间的本地目录
dumpdir /var/run/chrony

# Ignore stratum in source selection.
stratumweight 0.01

# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

# 闰秒配置,17h34m消化1s
leapsecmode slew
maxslewrate 1000
smoothtime 400 0.001 leaponly

# In first three updates step the system clock instead of slew
# if the adjustment is larger than 10 seconds.
# makestep 0.1 3

## Server config
# Allow NTP client access from local network.
allow 0.0.0.0/0

# Listen for commands only on localhost.
bindaddress 0.0.0.0
port 123
clientloglimit 1073741824
#ratelimit interval 1
#ratelimit burst 16
# Serve time even if not synchronized to any NTP server.
local stratum 5

## Command config
bindcmdaddress 127.0.0.1
bindcmdaddress /var/run/chrony/chronyd.sock
cmdallow all

## Real Time clock(RTC)
hwclockfile /etc/adjtime
rtcautotrim 10
rtcsync

keyfile /etc/chrony.keys

# Specify the key used as password for chronyc.
commandkey 1

# Generate command key if missing.
generatecommandkey

## Log
# Send a message to syslog if a clock adjustment is larger than 0.5 seconds.
logchange 0.1
log measurements statistics tracking
logdir /var/log/chrony

# Server配置
#ip address is the stable clock source which customer provided
server ntp.aliyun.com iburst minpoll 4 maxpoll 6 prefer

检查时间同步服务是否正常

#输出内容里的IP前边是*代表服务正常,?代表有问题
chronyc sources -v

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
问题描述: 使用Vue3和Sortable.js实现拖拽排序功能,拖拽排序后重新赋值给原数组,出现回跳问题,即拖拽的元素会回到原来的位置。 原因分析: 这是因为拖拽排序后,Sortable.js会将原数组的顺序重新排列,而Vue.js对数组的响应式更新是通过监测数组的变异方法(如push、pop、shift、unshift、splice、sort、reverse等)来实现的,而Sortable.js并没有调用这些变异方法,所以Vue.js并没有检测到数组的变化,从而导致回跳问题解决方法: 一种解决方法是手动调用Vue.js的数组变异方法,来更新数组的顺序。具体实现方法如下: 1. 在Vue组件中引入Sortable.js库。 ```javascript import Sortable from 'sortablejs' ``` 2. 在组件的mounted生命周期钩子中初始化Sortable.js实例,并传入需要排序的元素和配置项。 ```javascript mounted() { this.$nextTick(() => { this.sortable = new Sortable(this.$refs.list, { onEnd: this.sortHandler }) }) } ``` 其中,onEnd是Sortable.js的一个回调函数,当拖拽结束后会自动调用该函数。 3. 实现sortHandler方法,该方法会在拖拽结束后自动调用,用来更新数组的顺序。 ```javascript sortHandler(event) { const { newIndex, oldIndex } = event const item = this.list.splice(oldIndex, 1)[0] this.list.splice(newIndex, 0, item) } ``` 其中,newIndex和oldIndex分别表示拖拽结束时元素的新索引和旧索引。通过splice方法,将拖拽的元素从旧索引位置删除,再将其插入到新索引位置即可。 4. 在组件的beforeUnmount生命周期钩子中,销毁Sortable.js实例。 ```javascript beforeUnmount() { this.sortable.destroy() } ``` 完整代码示例: ```javascript <template> <div ref="list"> <div v-for="(item, index) in list" :key="item.id"> {{ item.text }} </div> </div> </template> <script> import Sortable from 'sortablejs' export default { data() { return { list: [ { id: 1, text: 'Item 1' }, { id: 2, text: 'Item 2' }, { id: 3, text: 'Item 3' }, { id: 4, text: 'Item 4' }, { id: 5, text: 'Item 5' } ], sortable: null } }, mounted() { this.$nextTick(() => { this.sortable = new Sortable(this.$refs.list, { onEnd: this.sortHandler }) }) }, beforeUnmount() { this.sortable.destroy() }, methods: { sortHandler(event) { const { newIndex, oldIndex } = event const item = this.list.splice(oldIndex, 1)[0] this.list.splice(newIndex, 0, item) } } } </script> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值