{"id":1858,"date":"2011-10-23T10:50:08","date_gmt":"2011-10-23T02:50:08","guid":{"rendered":"http:\/\/www.jpuyy.com\/blog\/?p=1858"},"modified":"2017-05-25T18:15:27","modified_gmt":"2017-05-25T10:15:27","slug":"change-time-zone-and-use-ntpdate","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=1858","title":{"rendered":"linux\u65f6\u533a\u7684\u4fee\u6539\u53ca\u4f7f\u7528ntpdate\u540c\u6b65\u65f6\u95f4"},"content":{"rendered":"<p>\u65f6\u95f4\u5bf9linux\u6765\u8bf4\u5341\u5206\u91cd\u8981\uff0c\u5f88\u591a\u4efb\u52a1\u8981\u6c42\u65f6\u95f4\u51c6\u786e<\/p>\n<p>\u65f6\u533a\u7684\u4fee\u6539<\/p>\n<p>\u67e5\u770b\u5f53\u524d\u65f6\u533a<\/p>\n<pre># date -R<\/pre>\n<p>\u901a\u8fc7\u5982\u4e0b\u547d\u4ee4\uff0c\u4ea4\u4e92\u5f0f\u95ee\u7b54\u6765\u8bbe\u7f6e\u65f6\u533a<\/p>\n<pre># tzselect<\/pre>\n<p>\u8fd9\u65f6\u4f1a\u663e\u793a\u51fa\u6765\u9009\u62e9\u56fd\u5bb6\u548c\u5730\u533a\uff0c\u9009\u597d\u540e\u63d0\u793a\u4f60<\/p>\n<p>You can make this change permanent for yourself by appending the line<br \/>\nTZ=&#8217;Asia\/Shanghai&#8217;; export TZ<br \/>\nto the file &#8216;.profile&#8217; in your home directory; then log out and log in again.<\/p>\n<p>\u60f3\u8981\u6c38\u4e45\u6539\u53d8\u5c31\u5199\u5230\u4f60\u7684.profile\u91cc\uff0c\u6216\/etc\/profile\u5168\u5c40\u6587\u4ef6\u4e2d\u3002<\/p>\n<pre>TZ='Asia\/Shanghai'; export TZ<\/pre>\n<p>Here is that TZ value again, this time on standard output so that you<br \/>\ncan use the \/usr\/bin\/tzselect command in shell scripts:<br \/>\nAsia\/Shanghai<\/p>\n<p>\u6216\u8005\u4f7f\u6240\u6709\u7528\u6237\u7684\u65f6\u533a\u6539\u53d8<\/p>\n<pre>echo \"TZ='Asia\/Shanghai'\" &gt;&gt; \/etc\/environment<\/pre>\n<p>\u5bf9\u4e8e centos 6\uff0c\u7528\u5982\u4e0b\u65b9\u6cd5\u66f4\u6539\u65f6\u533a<\/p>\n<pre>cp \/etc\/localtime \/etc\/localtime.old\r\nln -nfs \/usr\/share\/zoneinfo\/Asia\/Shanghai \/etc\/localtime\r\nls -lh \/etc\/localtime\r\ndate<\/pre>\n<p>\u8fd8\u6709\u4e00\u4e2a\u5730\u65b9\u5982\u679c\u80fd\u6539\u4e5f\u8981\u6539\u4e00\u4e0b<\/p>\n<pre>vi \/etc\/sysconfig\/clock\r\nZONE=\"Asia\/Shanghai\"<\/pre>\n<p>\u5bf9\u4e8e centos7\uff0c\u7a0d\u5fae\u65b9\u4fbf\u4e00\u4e9b\uff0c\u539f\u7406\u4e00\u6837<br \/>\n\u67e5\u770b timezones<\/p>\n<pre>\r\n[root@localhost ~]# timedatectl list-timezones\r\n[root@localhost ~]# ls -l \/etc\/localtime \r\nlrwxrwxrwx. 1 root root 38 8\u6708   1 2014 \/etc\/localtime -> ..\/usr\/share\/zoneinfo\/America\/New_York\r\n[root@localhost ~]# date\r\n2015\u5e74 02\u6708 24\u65e5 \u661f\u671f\u4e8c 22:08:35 EST<\/pre>\n<p>\u8bbe\u7f6e timezone<\/p>\n<pre>[root@localhost ~]# timedatectl set-timezone Asia\/Shanghai\r\n[root@localhost ~]# date \r\n2015\u5e74 02\u6708 25\u65e5 \u661f\u671f\u4e09 11:09:14 CST\r\n[root@localhost ~]# ls -l \/etc\/localtime \r\nlrwxrwxrwx. 1 root root 35 2\u6708  25 11:09 \/etc\/localtime -> ..\/usr\/share\/zoneinfo\/Asia\/Shanghai<\/pre>\n<p>\u63a5\u4e0b\u6765\uff0c\u66f4\u65b0\u7cfb\u7edf\u65f6\u95f4\u4e3aInternet\u65f6\u95f4\uff0c\u6743\u6839\u4e3aroot\u7528\u6237\u3002<\/p>\n<p>\u5148\u5b89\u88c5ntpdate\u5e76\u4e0e0.cn.pool.ntp.org\u540c\u6b65\u65f6\u95f4:<\/p>\n<pre>apt-get install ntpdate\r\nntpdate 0.cn.pool.ntp.org<\/pre>\n<p>\u7cfb\u7edf\u65f6\u949f\u4e0e\u786c\u4ef6\u65f6\u949f\u540c\u6b65\uff1a<\/p>\n<pre># hwclock --systohc<\/pre>\n<p>\u4e0a\u9762\u547d\u4ee4\u4e2d\uff0c<code>--systohc<\/code>\uff0c\u7b80\u5199\u4e3a -w \u8868\u793aSYStem clock to Hardware Clock\uff1b<br \/>\n\u540c\u7406<code>--hctosys<\/code>\uff0c\u7b80\u5199\u4e3a -s \u8868\u793aHardware Clock to SYStem clock\uff0c\u4e0d\u8fc7\u6211\u7684\u7406\u89e3\u662f\u7cfb\u7edf\u65f6\u95f4\u66f4\u65b0\u540e\u628a\u786c\u4ef6\u65f6\u949f\u5237\u65b0\u7684\u60c5\u51b5\u4e3a\u6b63\u7edf\u3002<\/p>\n<p>\u4e3a\u4fdd\u8bc1\u65f6\u95f4\u7684\u51c6\u786e\u6027\uff0c\u628a\u65f6\u95f4\u540c\u6b65\u5199\u5165\u5230cron\u91cc\uff0c\u6bcf\u5c0f\u65f6\u628a\u5f53\u524d\u7cfb\u7edf\u65f6\u95f4\u4e0eInternet\u65f6\u95f4\u540c\u6b65\uff0c\u6bcf\u5929\u628a\u7cfb\u7edf\u65f6\u95f4\u4e0e\u786c\u4ef6\u65f6\u95f4\u540c\u6b65\u3002<\/p>\n<pre>* *\/1 * * * \/usr\/sbin\/ntpdate 0.cn.pool.ntp.org &gt;\/dev\/null\r\n0 0 * * * \/sbin\/hwclock -w &gt;\/dev\/null<\/pre>\n<p>Linux\u65f6\u949f\u4ecb\u7ecd\uff1a<\/p>\n<p>Linux\u673a\u5668\u91cc\u6709\u4e24\u4e2a\u65f6\u949f\uff0c\u4e00\u4e2a\u662f\u786c\u4ef6\u65f6\u949f\uff08CMOS\u65f6\u949f\uff09\uff0c\u4e00\u4e2a\u662f\u5185\u6838\u65f6\u949f\u3002\u786c\u4ef6\u65f6\u949f\u662f\u7535\u6c60\u9a71\u52a8\u7684\uff0c\u901a\u8fc7\u4e13\u95e8\u7684\u82af\u7247\u5de5\u4f5c\u3002\u53ef\u4ee5\u901a\u8fc7BIOS\u8bbe\u7f6e\u5c4f\u6216\u4e00\u4e9b\u7cfb\u7edf\u547d\u4ee4\uff08\u5982hwclock\uff09\u8fdb\u884c\u8bbe\u7f6e\u3002\u5185\u6838\u65f6\u949f\u662f\u7531\u5185\u6838\u7ef4\u62a4\u7684\uff0c\u542f\u52a8\u65f6\u4ece\u786c\u4ef6\u8bfb\u53d6\u65f6\u95f4\uff0c\u4e4b\u540e\u72ec\u7acb\u8fd0\u884c\u3002<\/p>\n<p>RTC\uff08Real Time Clock\uff09<\/p>\n<p>\u5373Linux\u5b9e\u65f6\u7684\u65f6\u949f\u9a71\u52a8\uff0c\u901a\u5e38\u5b83\u4eec\u88ab\u5d4c\u5728\u8ba1\u7b97\u673a\u7684\u82af\u7247\u4e2d\uff0c\u4e5f\u6709\u4e00\u4e9b\u662f\u5728\u4e3b\u677f\u4e0a\u4f7f\u7528Motorola MC146818\uff08\u6216clone\uff09\u5b9e\u73b0\u7684\u3002\u8be5\u786c\u4ef6\u8bbe\u5907\u53ef\u6620\u5c04\u5230\/dev\/rtc\uff0c\u4f9broot\u7f16\u7a0b\u8bbf\u95ee\u3002<\/p>\n<p>NTP\uff08Network time protocol\uff09<\/p>\n<p>NTP\u4e3a\u4e00\u79cd\u7f51\u7edc\u65f6\u95f4\u534f\u8bae\uff0c\u662f\u4e00\u79cd\u786e\u4fdd\u7f51\u7edc\u4e0a\u7684\u4e3b\u673a\u8c03\u6574\u65f6\u95f4\u7684\u65b9\u6cd5\u3002\u5f88\u591a\u5730\u65b9\u90fd\u4f1a\u63d0\u4f9bNTP\u670d\u52a1\u5668\u3002<\/p>\n<p>\u5e38\u7528 ntp \u670d\u52a1\u5668<\/p>\n<pre>ntpupdate.tencentyun.com<\/pre>\n<p>CentOS 7 \u66f4\u65b0\u65f6\u95f4<br \/>\n1. timedatectl \u67e5\u770b\u5f53\u524d\u540c\u6b65\u60c5\u51b5\uff0c\u5982\u679c\u6ca1\u5f00\uff0c\u5f00\u542f<\/p>\n<pre> timedatectl set-ntp 1 <\/pre>\n<p>check \u65f6\u95f4<br \/>\ndatetimectl \u663e\u793a<\/p>\n<pre>\r\n     NTP enabled: yes\r\nNTP synchronized: yes\r\n<\/pre>\n<p>2. \u5982\u679c\u662f\u7269\u7406\u673a\uff0c\u5c06\u65f6\u95f4\u5237\u5165 hardware<\/p>\n<p>hwclock &#8211;systohc<\/p>\n<p>check \u786c\u4ef6\u65f6\u95f4<\/p>\n<pre>hwclock<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u65f6\u95f4\u5bf9linux\u6765\u8bf4\u5341\u5206\u91cd\u8981\uff0c\u5f88\u591a\u4efb\u52a1\u8981\u6c42\u65f6\u95f4\u51c6\u786e \u65f6\u533a\u7684\u4fee\u6539 \u67e5\u770b\u5f53\u524d\u65f6\u533a # date -R \u901a\u8fc7\u5982\u4e0b\u547d\u4ee4\uff0c\u4ea4\u4e92\u5f0f\u95ee\u7b54\u6765\u8bbe\u7f6e\u65f6\u533a # tzselect \u8fd9\u65f6\u4f1a\u663e\u793a\u51fa\u6765\u9009\u62e9\u56fd\u5bb6\u548c\u5730\u533a\uff0c\u9009\u597d\u540e\u63d0\u793a\u4f60 You can make this change permanent for yourself by appending the line TZ=&#8217;Asia\/Shanghai&#8217;; export TZ to the file &#8216;.profile&#8217; in your home directory; then log out and log in again. \u60f3\u8981\u6c38\u4e45\u6539\u53d8\u5c31\u5199\u5230\u4f60\u7684.profile\u91cc\uff0c\u6216\/etc\/profile\u5168\u5c40\u6587\u4ef6\u4e2d\u3002 TZ=&#8217;Asia\/Shanghai&#8217;; export TZ Here is that TZ value again, this time on standard output [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[23],"class_list":["post-1858","post","type-post","status-publish","format-standard","hentry","category-linux","tag-summary"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/1858","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1858"}],"version-history":[{"count":23,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/1858\/revisions"}],"predecessor-version":[{"id":8146,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/1858\/revisions\/8146"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1858"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1858"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}