您的位置:首页 > 编程语言 > PHP开发

NTP时间同步设置

2016-01-08 12:20 639 查看
服务器端:

apt-get install ntp

vi ./etc/ntp.conf 

# Use Ubuntu's ntp server as a fallback.
<span style="color:#3333ff;">server 127.127.1.0 ibusrt</span>

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify
restrict -6 default kod notrap nomodify

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1


127.127.1.0 表示ntp本机ip

打开防火墙123端口

iptables -t filter -A INPUT -p udp --destination-port 123 -j ACCEPT

重启服务

service ntp restart

客户端

apt-get install ntp

vi /etc/ntp.conf  

# Use Ubuntu's ntp server as a fallback.
<span style="color:#3333ff;">server 10.0.0.20 iburst</span>

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify
restrict -6 default kod notrap nomodify

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1


其中10.0.0.20 是服务器的内网IP
ntpdate 10.0.0.20 可时间同步

或者启动服务service ntp restart

ntpq -p

date查看时间是否同步。

遇到的问题。客户机上时间一直不同步,后来发现是时区的问题。

使用tzselect修改时区报错。

$tzselect

选择时区,这里选择5,13,1 然后查看date没变。

如果报错

/usr/bin/tzselect: line 171: /home/test/iso3166.tab: No such file or directory

/usr/bin/tzselect: time zone files are not set up correctly

参考http://www.ithao123.cn/content-7792857.html修改成功。

vim / usr/bin/select 

把${TZDIR=`pwd`} 修改为: ${TZDIR=/usr/share/zoneinfo}

vi .profile

添加 TZ='Asia/Hong_Kong'; export TZ  

然后soucre .profile

再date 查看修改成功。

修改系统时间 date -s 12:34:56
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: