【转】Debian/Ubuntu 时区和自动校时设置

上次自己设置了自动校正时间,过段时间发现时间还是不对。比正常时间晚了12h。后来想到是时区设置错了,就百度了下,找到篇文章,解决了我的问题。我直接cp文章中的代码,因为我是上海时区。下面是转载文章:

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

一、设置服务器时区

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

1
tzselect
1
2
3
cat >>~/.profile<<EOF
TZ='Asia/Shanghai'; export TZ
EOF
1
2
rm -rf /etc/localtime
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

二、设置时间同步服务器

方法一:ntpdate 方式
1
2
3
4
5
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 方式
1
2
3
4
apt-get install -y ntpd #安装
vim /etc/ntp.conf #添加下面一行
server cn.pool.ntp.org
/etc/init.d/ntp restart #重启

以下适用于 debian

1
2
3
4
5
6
7
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 #重启

参考资料:

1. http://people.ubuntu.com/~happyaron/ubuntu-docs-test/lucid/serverguide/zh_CN/NTP.html
2. http://www.cyberciti.biz/faq/debian-ubuntu-linux-install-ntpd/
3. http://e-boy.cn/artical/view/84303/

原文地址 : http://wangyan.org/blog/debian-timezone-ntp.html

转载于:https://www.cnblogs.com/heybob/p/4718982.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值