1.设置时区(timezone)

方式一 修改/etc/localtime文件

/etc/localtime定义了系统时区

在/usr/share/zoneinfo下存放有系统编译好的时区文件,可以使用zdump 城市名查看相应地区时区,我们可以将时区文件链接到localtime

ln -sf /usr/share/zoneinfo/Asia/Chongqing /etc/localtime

方式二 修改TZ环境变量

最简单的方法就是tzselect命令,按提示一步步选择即可。注意,此方式会override localtime文件


2.设置本地时间

系统时钟是系统当前使用的时间,用date查看设置

date -s "11/26/2013 9:57:30"           //设置时间

date                                                       //查看时间

硬件时钟是server BIOS保存的时间,用hwclock查看设置

hwclock --set --date "11/26/2013 10:00:00"      //设置硬件时钟

hwclock –s                                           //将硬件时钟同步到系统时钟

hwclock –w                                          //将系统时钟同步到硬件时钟


3.设置NTP Server

http://www.pool.ntp.org 是NTP的官网,这里可以找到就近的NTP Server,推荐国家授时中心的ip 210.72.145.44,3.cn.pool.ntp.org,2.asia.pool.ntp.org

NTP Server的配置文件时/etc/ntp.conf,修改其中的授权ntp server,取消#fudge  127.127.1.0 stratum 10的注释,修改stratum 10为stratum 3

若要配置为本地NTP Server,使用127.127.1.0作为server

ntpdate 3.cn.pool.org       //手动执行下同步(推荐),注意此步骤要在开启ntpd服务前执行,因为nptdate和nptd都使用123端口

service ntpd start          //启动服务

chkconfig --level 345 ntpd on       //加入自启动

记得打开防火墙的 tcp 123

使用ntpq或ntpstat查询同步状态


4.设置NTP Client

关闭ntpd服务

添加计划任务,每两小时更新系统时钟并同步到硬件时钟

vi /etc/crontab

0 */2 * * * /usr/sbin/ntpdate 192.192.192.113; /sbin/hwclock –w