ubuntu搭建内部NTP服务器

来源:互联网 发布:黄瓜打避孕药 知乎 编辑:程序博客网 时间:2024/06/05 04:26

NTP服务器是用于网络时间同步的服务器,通常它是作为一个中继服务器,从上层服务器获取时间,然后将时间同步给其它机器。

1. 安装

在ubuntu平台上,直接安装ntp包即可

sudo apt-get install ntp

2. 启动服务

ubuntu上默认安装后就会启动ntp服务,在修改配置项后需要手动重启服务

sudo /etc/init.d/ntp restart

3. 配置服务

ntp服务的配置文件为/etc/ntp.conf,通常需要配置的属性如下:

# Specify one or more NTP servers.# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for# more information.#server 0.ubuntu.pool.ntp.org#server 1.ubuntu.pool.ntp.org#server 2.ubuntu.pool.ntp.org#server 3.ubuntu.pool.ntp.org# Use Ubuntu's ntp server as a fallback.#server ntp.ubuntu.com

此处配置上层ntp服务器地址,在ntp服务启动后,会先从这些服务器获取基准时间,如果都连不上,则ntp服务不会正常工作。此处希望ntp服务以本机时间作为基准,所以将所有的server全部注释。

# If you want to provide time to your local subnet, change the next line.# (Again, the address is an example only.)broadcast 10.0.161.255

此处配置ntp服务为当前网络提供时间同步服务,填写当前网络的广播地址。

广播地址可以通过ifconfig命令获取:

snow@snow-desktop:~$ ifconfigeth0      Link encap:以太网  硬件地址 d0:27:88:39:3f:da            inet 地址:10.0.161.90  广播:10.0.161.255  掩码:255.255.255.0          inet6 地址: fe80::d227:88ff:fe39:3fda/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  跃点数:1          接收数据包:112448 错误:0 丢弃:0 过载:0 帧数:0          发送数据包:54230 错误:0 丢弃:0 过载:0 载波:0          碰撞:0 发送队列长度:1000           接收字节:61800432 (61.8 MB)  发送字节:9700151 (9.7 MB)

注意修改配置文件后需要重启ntp服务后配置才会生效。

0 0
原创粉丝点击