栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Linux系统时间同步

Linux系统时间同步

Linux系统时间同步

文章目录

Linux系统时间同步

一、第一步:搭建用于时间同步的服务器

1.1 先安装npt模块:`sudo yum -y install ntp`1.2 写配置文件`/etc/npt.conf`1.3 启动ntp服务 二、第二步:在需要同步时间服务器上进行时间同步

2.1 执行同步命令2.2 执行命令的时候遇到的一个问题2.3 将时间同步部署成定时任务

一、第一步:搭建用于时间同步的服务器

在一台时间比较准确的服务器上,启动ntpd服务,比如这台时间比较精确的服务ip为11.225.118.166。

1.1 先安装npt模块:sudo yum -y install ntp 1.2 写配置文件/etc/npt.conf

sudo vi /etc/npt.conf

driftfile /var/lib/ntp/drift

restrict default nomodify notrap nopeer noquery

restrict 127.0.0.1

#  10.114.57.0 代表允许时间同步的服务器ip
restrict 10.114.57.0 mask 255.255.255.0 nomodify notrap
server 127.127.1.0

includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

disable monitor
tinker panic 0
1.3 启动ntp服务
-- 查看状态
sudo systemctl status ntpd
-- 启动nptd
sudo systemctl start ntpd
二、第二步:在需要同步时间服务器上进行时间同步

该需要时间同步的服务ip应该以10.114.57开头。

2.1 执行同步命令
sudo ntpdate 11.225.118.166
-- 或者
sudo /usr/sbin/ntpdate 11.225.118.166
2.2 执行命令的时候遇到的一个问题

遇到的一个问题描述如下:

20 Jan 10:16:31 ntpdate[95320]: the NTP socket is in use,exiting

解决方案:

sudo lsof -i:123

sudo kill -9 进程id

然后继续执行同步命令
2.3 将时间同步部署成定时任务

crontab -e

# 同步时间,每隔十五分钟同步一次
*/15 * * * * bash /root/importShells/run_sync_time.sh

/root/importShells/run_sync_time.sh 内容如下:

#!/bin/bash

current_month=$(date "+%Y%m")
current_day=$(date "+%Y%m%d")

logfilename=sync_time_${current_day}.log
mkdir -p /root/importShells/logs/${current_month}

log_file_path=/root/importShells/logs/${current_month}/${logfilename}

bash /root/importShells/time_sync.sh 1>>${log_file_path} 2>>${log_file_path}

/root/importShells/time_sync.sh的内容如下:

#!/bin/bash

/usr/sbin/ntpdate 11.225.118.166
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/710298.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号