编程技术分享平台

网站首页 > 技术教程 正文

linux搭建时间服务器(linux)(linux配置时间服务器)

xnh888 2025-05-02 14:14:48 技术教程 17 ℃ 0 评论

1. 选择一台服务器作为时间服务器。使用root用户,查看服务器是否安装ntp服务

rpm -qa|grep ntp

没有安装的话使用yum install进行安装。

2. 修改文件 /etc/ntp.conf,一共修改三处内容:

3. ①将#去掉。并且将网段修改正确。

restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap

4. ②将以下4个server进行#注释掉

#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst

③最后添加俩句话:

server 127.127.1.0 #local clock
fudge 127.127.1.0 stratum 10

5. 编辑etc/sysconfig/ntpd文件

# Drop root to id 'ntp:ntp' by default.
SYNC_HWCLOCK=yes
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"

6. 启动ntpd服务,并且设置开机启动

systemctl start ntpd.service
systemctl enable ntpd.service

service ntpd restart
chkconfig ntpd on

8. 每个需要同步的子节点进行确认有没有ntp。如果没有的话就安装下。

9. root账户下在每个需要同步的子节点编写crontab任务(crontab -e)。这个任务的意义就是每10分钟和master01同步下服务器时间。

0-59/10 * * * * /usr/sbin/ntpdate master01.timer.cn

附:

1.作为时间服务器的节点的时间校准可以是人工指定(不与其他集群协作的情况下),也可以是跟其他组织的时间服务器同步

这里只说第二种情况。首先要确认当前服务器的时区

将时区设为上海

rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

然后通过定时任务,与阿里云的时间服务器 ntp1.aliyun.com 同步(方法同上面第10步,ntp1~ntp7)

2.不同操作系统之间也是可以做时间同步的。linux与windows之间同步是没问题的。

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表