1. 程式人生 > >centos7同步網路時間並修改時區

centos7同步網路時間並修改時區

安裝ntpdate工具
# yum -y install ntp ntpdate

設定系統時區為上海
# timedatectl set-timezone Asia/Shanghai 

設定系統時間與網路時間同步
# ntpdate 0.asia.pool.ntp.org
# ntpdate 1.asia.pool.ntp.org
# ntpdate 2.asia.pool.ntp.org  # 我使用是  2.asia.pool.ntp.org
# ntpdate 3.asia.pool.ntp.org

vi /etc/crontab   編輯時間配置檔案每個2天同步一次

# * */48* * * ntpdate 2.asia.pool.ntp.org

將系統時間寫入硬體時間
# hwclock --systohc


強制系統時間寫入CMOS中防止重啟失效
# hwclock -w  或     clock -w

如果沒有安裝ntp伺服器,剛需要先執行以下命令:
# yum install ntp #安裝ntp伺服器

4、/sbin/hwclock --systohc   #設定硬體時間和系統時間一致並校準