1.有外网的主机,应同步时间同步服务器,这个去网上能搜到很多。启用代理服务的私网地址再同步到连接到外网的服务器或网关。例:

ntpdate 1.cn.pool.ntp.org
clock -w   #同步时间至硬件(将当前系统时间写入CMOS中去)等同--systohc
#clock –s 以硬件时间为准同步时间至系统时间,等同--hctosys

2.修改时间同步配置文件

centos 6:

vim /etc/ntp.conf    #找到server区域添加如下
server 1.cn.pool.ntp.org iburst
#server pool.ntp.org iburst

centos 7:

vim chrony.conf
server 1.cn.pool.ntp.org iburst

https://www.cnblogs.com/panwenbin-logs/p/8384340.html

3.设置为开机启动

centos 6

chkconfig ntpd on

centos 7

systemctl enable chronyd

如需把utc时间改为cst(+8区)时间:

1、vi /etc/sysconfig/clock   #编辑文件

ZONE="Asia/Shanghai"
UTC=false              #设置为false,硬件时钟不于utc时间一致
ARC=false

2、ln -sf /usr/share/zoneinfo/Asia/Shanghai    /etc/localtime    #linux的时区设置为上海


tips:如果想改为UTC时间只需删除/etc/localtime 

3、ntpdate asia.pool.ntp.org    #对准时间,需要先安装ntp服务器 yum install ntp
4、/sbin/hwclock --systohc   #设置硬件时间和系统时间一致并校准


mysql中时间相差13或14小时的解决办法:

mysql> set global time_zone = '+08:00'; 
或者修改 `my.cnf` 文件,在 `[mysqld]` 节下增加 `default-time-zone = '+08:00'`

附:设置时区方法

  1. tzselect 命令,输入后交互更改

  2. centos 7系统 设置方法

    timedatectl set-timezone Asia/Shanghai