欢迎来访~

搭建NTP服务器实现自动同步时间

实验环境
CentOS 6.5
NTP服务端:hello2099.com   IP:192.168.1.13
NTP客户端:hello2299.com   IP:192.168.1.14
 
1.服务端安装NTP
yum install ntp
 
2.配置NTP

vim /etc/ntp.conf
增加或修改以下红色部分配置命令:
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
 
driftfile /var/lib/ntp/drift
 
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
 
# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1
restrict 192.168.1.0 mask 255.255.255.0
restrict 202.120.2.101
 
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
 
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (https://www.pool.ntp.org/join.html).
server 202.120.2.101
server 127.127.1.0
fudge 127.127.1.0
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
 
#broadcast 192.168.1.255 autokey        # broadcast server
#broadcastclient                        # broadcast client
#broadcast 224.0.1.1 autokey            # multicast server
#multicastclient 224.0.1.1              # multicast client
#manycastserver 239.255.254.254         # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
# Enable public key cryptography.
#crypto
 
includefile /etc/ntp/crypto/pw
 
# Key file containing the keys and key identifiers used when operating
 
 
3.启动并查看NTP服务
service ntpd start                   #启动NTP服务
chkconfig ntpd on                  #设置开机自启动
netstat -anutp | grep 123       #查看NTP的端口
 
4.查看NTP服务状态
ntpstat                                      #查看ntp服务器有无和上层连通
ntpq -p                                      #查看ntp服务器与上层ntp服务器的状态

服务端配置完成,NTP状态正常。
 
5.客户端安装NTP服务,NTP同步时间
yum install ntp
ntpdate 192.168.1.13
客户端同步服务端时间成功。
 
由于虚拟机是采用桥接上网,物理机也可以同步成功。
 
 
近期比较忙,等有空了再附加以下内容,先列出来。
附1:ntpdate和cron的使用
附2:linux的时间、时区的配置
附3:配置NTP时常见错误

 

 

赞(0)
可附来源转载:一只北极熊 » 搭建NTP服务器实现自动同步时间

富强、民主、文明、和谐、自由、平等、公正、法治、爱国、敬业、诚信、友善