标签 同步时间 下的文章

说明:这两天突然不能使用了,但是酸酸正常,重装无效。

具体表现

1.网站的nginx日志

2019/02/09 14:57:38 [error] 3472#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.68.132.40, server: 域名, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:25534/", host: "域名"

2.v2ray日志

2019/02/09 14:59:47 127.0.0.1:50462 rejected  v2ray.com/core/proxy/vmess/encoding: invalid user

搜索了下,可能和系统时间有关。

3.查看时间
date
显示的时间果然不对,快了2分钟。

同步时间

适用于 debian

apt-get install -y ntp
vi /etc/ntp.conf #修改为下面几行
server 0.debian.pool.ntp.org iburst dynamic
server 1.debian.pool.ntp.org iburst dynamic
server 2.debian.pool.ntp.org iburst dynamic
server 3.debian.pool.ntp.org iburst dynamic
/etc/init.d/ntp restart #重启

强制 NTP 重新同步
如果 ntpdate 不可用,可以尝试以下方式让 ntpd 强制同步:

systemctl stop ntpsec
ntpd -gq  # 允许大时间偏移并同步
systemctl start ntpsec

-g 选项允许 NTP 服务器调整大偏差时间(默认不超过 1000 秒)。
-q 选项让它在同步后退出,而不是作为守护进程运行。

centos 同步时间

在 CentOS 中同步时间可以使用 chrony 或 ntp 服务。CentOS 7 及以上推荐使用 chrony,而 CentOS 6 主要使用 ntp。

使用 chrony(CentOS 7/8)

1. 安装 chrony(如果未安装)
yum install -y chrony

2. 启动 chronyd 服务并设置开机自启
systemctl start chronyd
systemctl enable chronyd

3. 手动同步时间
chronyc sources -v  # 查看 NTP 服务器状态
chronyc tracking     # 查看系统时间跟踪状态

4. 立即同步
chronyc makestep

5. 验证同步后的时间
date