centos7設(shè)置時(shí)區(qū),時(shí)間+時(shí)間同步的三種方式
1.centos7設(shè)置時(shí)區(qū)
1.1查看當(dāng)前時(shí)區(qū):
timedatectl
1.2查看時(shí)間命令:
date
1.3選擇時(shí)區(qū)命令
[root@localhost test]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
1) Africa
2) Americas
3) Antarctica
4) Arctic Ocean
5) Asia
6) Atlantic Ocean
7) Australia
8) Europe
9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 5
Please select a country.
1) Afghanistan 18) Israel 35) Palestine
2) Armenia 19) Japan 36) Philippines
3) Azerbaijan 20) Jordan 37) Qatar
4) Bahrain 21) Kazakhstan 38) Russia
5) Bangladesh 22) Korea (North) 39) Saudi Arabia
6) Bhutan 23) Korea (South) 40) Singapore
7) Brunei 24) Kuwait 41) Sri Lanka
8) Cambodia 25) Kyrgyzstan 42) Syria
9) China 26) Laos 43) Taiwan
10) Cyprus 27) Lebanon 44) Tajikistan
11) East Timor 28) Macau 45) Thailand
12) Georgia 29) Malaysia 46) Turkmenistan
13) Hong Kong 30) Mongolia 47) United Arab Emirates
14) India 31) Myanmar (Burma) 48) Uzbekistan
15) Indonesia 32) Nepal 49) Vietnam
16) Iran 33) Oman 50) Yemen
17) Iraq 34) Pakistan
#? 9
Please select one of the following time zone regions.
1) Beijing Time
2) Xinjiang Time
#? 1
The following information has been given:
China
Beijing Time
Therefore TZ='Asia/Shanghai' will be used.
Local time is now: Thu May 11 17:50:40 CST 2023.
Universal Time is now: Thu May 11 09:50:40 UTC 2023.
Is the above information OK?
1) Yes
2) No
#? 1
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.
Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai
設(shè)置timezone的時(shí)區(qū)
sudo timedatectl set-timezone 'Asia/Shanghai'
或者
echo "Asia/Shanghai" > /etc/timezone
2.設(shè)置時(shí)間
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
3.使用NTP服務(wù)時(shí)間同步
3.1安裝ntp
yum -y install ntp
3.2啟動(dòng)ntp服務(wù)
systemctl start ntpd
systemctl enable ntpd
3.3查看ntp服務(wù)
systemctl status ntpd
3.4修改ntp.conf文件
vim /etc/ntp.conf
3.5重啟服務(wù)
systemctl restart ntpd
3.6檢查同步狀態(tài)
3.7執(zhí)行硬件時(shí)間向軟件時(shí)間同步
hwclock -w
3.8查看當(dāng)前時(shí)間
date
4.使用ntpdate同步
4.1最簡(jiǎn)單的方法,讓所有集群中的主機(jī)跟某個(gè)時(shí)間服務(wù)器的 時(shí)間同步,執(zhí)行 ntpdate 時(shí)間服務(wù)器。
ntpdate ntp1.aliyun.com
不過(guò),這種方法不好.ntpdate同步時(shí)間是跳躍的,這將導(dǎo)致文件時(shí)間標(biāo)記,監(jiān)控?cái)?shù)據(jù)的紊亂. 而且ntpdate只運(yùn)行一次就結(jié)束,即只同步一次.所以即使我們要寫(xiě)這樣寫(xiě) vi /etc/crontab文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-445254.html
* * * * root /usr/sbin/ntpdate ntp1.aliyun.com && /sbin/hwclock -w
4.2執(zhí)行硬件時(shí)間向軟件時(shí)間同步
hwclock -w
4.3查看時(shí)間是否正確
date
5.使用chrony服務(wù)時(shí)間同步
5.1安裝chrony
yum -y install chrony
5.2啟動(dòng)chrony服務(wù)
systemctl enable --now chronyd
5.3查看chrony狀態(tài)
systemctl status chronyd
5.4修改配置文件
grep server /etc/chrony.conf
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-445254.html
5.5重啟服務(wù)
systemctl restart chronyd
5.6檢查時(shí)間同步狀態(tài)
chronyc sources
5.7硬件時(shí)間向系統(tǒng)時(shí)間同步
hwclock -w
5.8查看時(shí)間是否正確
date
6.手動(dòng)修改時(shí)間
6.1修改時(shí)間方法
date -s "你想設(shè)置的時(shí)間"
6.2按格式輸出時(shí)間
date "+%Y-%m-%d %H:%M:%S"
6.3設(shè)置時(shí)區(qū)
timedatectl set-timezone Asia/Shanghai
6.4 查看
timedatectl list-timezones |grep Shanghai
到了這里,關(guān)于centos7設(shè)置時(shí)區(qū),時(shí)間+時(shí)間同步的三種方式的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!