ntp服务器的搭建(内网时钟服务器的搭建) 您所在的位置:网站首页 windows设置时钟服务器 ntp服务器的搭建(内网时钟服务器的搭建)

ntp服务器的搭建(内网时钟服务器的搭建)

2023-09-22 02:58| 来源: 网络整理| 查看: 265

前言

环境:centos 7.9 同步时间是一个很重要的事,特别是对于一些企业生产数据而言,时间的准确性非常重要,前面我们同步时间都是通过ntpdate命令结合crontab任务计划来实现的,但是在企业生产环境中,不可能说每台服务器都去同步网络上的时钟服务器,更何况企业的服务器往往都是内网环境,连上外网的机会都没有,这时就需要我们搭建一台内网时间服务器,这样内网环境的每台服务器就能来同步时间服务器的时间了,而这台时间服务器要能连外网,因为它本身也需要去外网同步网络上的时间服务器。

ntp服务的安装

要搭建一台内网时间服务器,首先要能让服务器连接外网,其次才是安装ntp服务,一般来说ntp服务系统已经自带了,如果没有就需要安装ntp服务,如下:

[root@master conf]# yum install -y ntp #安装ntp服务 配置文件ntp.conf

安装完ntp服务之后,需要编辑ntp服务的配置文件,如下:

[root@master ~]# grep -v '#' /etc/ntp.conf driftfile /var/lib/ntp/drift restrict default nomodify notrap nopeer noquery restrict 127.0.0.1 #保持默认即可 restrict ::1 restrict 192.166.1.0 mask 255.255.0.0 nomodify notrap #这句是新加的,表示允许内网其它机器同步本机时间 server 0.centos.pool.ntp.org iburst #0.centos.pool.ntp.org是centos官方时钟服务器的域名 server 1.centos.pool.ntp.org iburst server cn.pool.ntp.org iburst server ntp.aliyun.com iburst #一般设置成国内的网络ntp服务器,可以写域名或IP地址 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitor 启动 ntp服务

修改完配置文件就可以启动ntp服务了,如下:

[root@master ~]# systemctl start ntpdate.service #启动ntp服务 [root@master ~]# systemctl enable ntpdate.service #设置开机自启

启动ntp服务之后,以后ntp就会自动的去同步网络上的时间了。

至此,内网ntp服务器搭建完成,内网环境的其他服务器需要同步时间,直接就同步内网ntp服务器即可,使用命令ntpdate命令结合crontab计划任务定时同步即可,如下:

*/5 * * * * /usr/sbin/ntpdate 192.168.1.120 &>/dev/null 总结 1、[root@master ~]# yum install -y ntp #安装内网ntp服务器,ntp服务器要去同步网络时间,所以要连外网 2、[root@master ~]# vim /etc/ntp.conf #修改配置文件,开放权限让内网其他服务器可以链接自己,修改网络时间源的地址 3、[root@master ~]# systemctl start ntpd #启动ntp服务 4、[root@master ~]# systemctl enable ntpd #设置开机自启ntp服务,以后ntp服务会自动的定时去同步网络时间服务器 5、[root@master ~]# crontab -e #内网其他服务器编辑计划任务,定时同步内网ntp服务器 */5 * * * * /usr/sbin/ntpdate 192.168.1.120 &>/dev/null


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有