centos修改时区并同步时间

查看服务器时间及所在时区

[root@localhost ~]# date -R
Fri, 07 Dec 2018 04:38:28 -0500

修改时区

先使用 tzselect 根据提示选择所在地区,最终生成时区

You can make this change permanent for yourself by appending the line
	TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

然后编辑 /etc/profile 文件,添加 TZ='Asia/Shanghai'; export TZ,编辑完成后保存,运行 source /etc/profile

再次使用 date -R 查看时间

Fri, 07 Dec 2018 17:42:28 +0800

同步时间

安装 ntpdate

[root@localhost ~]# yum install ntpdate -y

前往 http://www.ntp.org.cn 查询可用的NTP服务,同步时间

[root@localhost ~]# ntpdate cn.ntp.org.cn

如同步出现错误 no server suitable for synchronization found,可尝试使用

[root@localhost ~]# ntpdate -u cn.ntp.org.cn

或者将域名改为ip

原文地址:https://www.cnblogs.com/wenhui92/p/10084269.html