【轉】Debian/Ubuntu 時區和自動校時設置

上次本身設置了自動校訂時間,過段時間發現時間仍是不對。比正常時間晚了12h。後來想到是時區設置錯了,就百度了下,找到篇文章,解決了個人問題。我直接cp文章中的代碼,由於我是上海時區。下面是轉載文章:html

NTP 是經過網絡自動校時的一種 TCP/IP 協議。Debian/Ubuntu 中有兩種方式實現時間同步:ntpdate 和 ntpd,前者爲一天調整一次時間,後者 ntpd 爲守護進程,能夠持續不斷地調整時間。我的推薦使用 ntpd,它實際佔用資源是很小的。linux

1、設置服務器時區

若是是美國VPS,那麼時區要首先設置,否則哪怕再精準的時間也是白搭。我通常使用 tzconfig 或 tzselect 工具來設置時區。ubuntu

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

2、設置時間同步服務器

方法一: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 #重啓

如下適用於 debianvim

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 #重啓

參考資料:bash

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 網絡

相關文章
相關標籤/搜索