当前位置: > Linux发行版 > Debian >

Debian/Ubuntu下时区和自动校时的设置

时间:2014-09-16 14:14来源:linux.it.net.cn 作者:it

NTP 是通过网络自动校时的一种 TCP/IP 协议。Debian/Ubuntu 中有两种方式实现时间同步:ntpdate 和 ntpd,前者为一天调整一次时间,后者 ntpd 为守护进程,可以持续不断地调整时间。
推荐使用 ntpd,它实际占用资源非常小。

一、设置服务器时区

如果是美国VPS,那么时区要首先设置,不然哪怕再精准的时间也是白搭。我一般使用 tzconfig 或 tzselect 工具来设置时区。
tzselect

cat >>~/.profile<<EOF
TZ='Asia/Shanghai'; export TZ
EOF

rm -rf /etc/localtime
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

二、设置时间同步服务器

方法一:ntpdate 方式
 

复制代码代码如下:
apt-get install -y ntpdate #安装
vim /etc/cron.daily/ntpdate #添加下面一行,每天同步。
ntpdate ntp.ubuntu.com cn.pool.ntp.org
chmod 755 /etc/cron.daily/ntpdate #修改权限
ntpdate -d cn.pool.ntp.org #立即同步时间

方法二:ntpd 方式
 

复制代码代码如下:
apt-get install -y ntpd #安装
vim /etc/ntp.conf #添加下面一行
server cn.pool.ntp.org
/etc/init.d/ntp restart #重启

以下适用于 debian
 

复制代码代码如下:
apt-get install -y ntp
vim /etc/ntp.conf #修改为下面几行
server 0.debian.pool.ntp.org iburst dynamic
server 1.debian.pool.ntp.org iburst dynamic
server 2.debian.pool.ntp.org iburst dynamic
server 3.debian.pool.ntp.org iburst dynamic
/etc/init.d/ntp restart #重启
(责任编辑:IT)
------分隔线----------------------------