ntp服务端安装
root@ubuntu:/# sudo apt-get install ntp
修改配置文件
root@ubuntu:/# vi /etc/ntp.conf
# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust
# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255
# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines. Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient
#Changes recquired to use pps synchonisation as explained in documentation:
#http://www.ntp.org/ntpfaq/NTP-s-config-adv.htm#AEN3918
#server 127.127.8.1 mode 135 prefer # Meinberg GPS167 with PPS
#fudge 127.127.8.1 time1 0.0042 # relative to PPS for my hardware
#server 127.127.22.1 # ATOM(PPS)
#fudge 127.127.22.1 flag3 1 # enable PPS API
restrict 10.1.40.0 mask 255.255.255.0 nomodify
文件最后添加restrict 10.1.40.0 mask 255.255.255.0 nomodify 主要是允许能同步的服务器所在的内部网段
ntp客户端安装
root@ubuntu:/# sudo apt-get install ntpdate
同步时间
root@ubuntu:/# ntpdate 10.1.37.77
修改时区
先查看当前系统时间
root@ubuntu:/# date -R
1.运行tzselect
root@ubuntu:/# tzselect
出现如下错误
root@ubuntu:/#tzselect
/usr/bin/tzselect: line 180: /usr/share/zoneinfo/iso3166.tab: No such file or directory
/usr/bin/tzselect: time zone files are not set up correctly
需要安装
root@ubuntu:/# apt-get install tzdata
root@ubuntu:~# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, "coord", or "TZ".
1) Africa
2) Americas
3) Antarctica
4) Asia
5) Atlantic Ocean
6) Australia
7) Europe
8) Indian Ocean
9) Pacific Ocean
10) coord - I want to use geographical coordinates.
11) TZ - I want to specify the time zone using the Posix TZ format.
#? 4
Please select a country whose clocks agree with yours.
1) Afghanistan 18) Iraq 35) Pakistan
2) Antarctica 19) Israel 36) Palestine
3) Armenia 20) Japan 37) Philippines
4) Azerbaijan 21) Jordan 38) Qatar
5) Bahrain 22) Kazakhstan 39) Russia
6) Bangladesh 23) Korea (North) 40) Saudi Arabia
7) Bhutan 24) Korea (South) 41) Singapore
8) Brunei 25) Kuwait 42) Sri Lanka
9) Cambodia 26) Kyrgyzstan 43) Syria
10) China 27) Laos 44) Taiwan
11) Cyprus 28) Lebanon 45) Tajikistan
12) East Timor 29) Macau 46) Thailand
13) Georgia 30) Malaysia 47) Turkmenistan
14) Hong Kong 31) Mongolia 48) United Arab Emirates
15) India 32) Myanmar (Burma) 49) Uzbekistan
16) Indonesia 33) Nepal 50) Vietnam
17) Iran 34) Oman 51) Yemen
#? 10
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.
Selected time is now: Thu Jan 6 10:11:52 CST 2022.
Universal Time is now: Thu Jan 6 02:11:52 UTC 2022.
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
2.复制文件到/etc目录下
root@ubuntu:~# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
3.再次查看时间date -R,已经修改为北京时间
root@ubuntu:~# date -R
Thu, 06 Jan 2022 10:16:59 +0800