NTP linux
2015年8月20日 星期四 shell
17:34 vim
[root@localhost Asia]# /usr/bin/tzselect 服務器
Please identify a location so that time zone rules can be set correctly. app
Please select a continent or ocean. ide
1) Africa this
2) Americas spa
3) Antarctica rest
4) Arctic Ocean orm
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.
#選擇時區
#? 11
Please enter the desired value of the TZ environment variable.
For example, GST-10 is a zone named GST that is 10 hours ahead (east) of UTC.
#鍵入CST+0中國時區
#UTC爲國際時區
CST+0
awk: cmd. line:5: warning: escape sequence `\.' treated as plain `.'
The following information has been given:
TZ='CST+0'
Therefore TZ='CST+0' will be used.
Local time is now: Thu May 12 18:13:06 CST 2016.
Universal Time is now: Thu May 12 18:13:06 UTC 2016.
Is the above information OK?
1) Yes
2) No
#? 1
You can make this change permanent for yourself by appending the line
TZ='CST+0'; 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:
CST+0
[root@localhost Asia]# /usr/bin/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: Fri May 13 02:13:32 CST 2016.
Universal Time is now: Thu May 12 18:13:32 UTC 2016.
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
[root@localhost Asia]# date
Thu May 12 18:13:40 CST 2016
[root@localhost Asia]# clock
Thu 12 May 2016 06:13:44 PM CST -0.396667 seconds
[root@localhost Asia]#
vi /etc/profile
export TZ='CST+0'
date -s 14:20:50
hwclock --show 或者
clock --show
設置硬件時間
hwclock --set --date="06/18/14 14:55" (月/日/年時:分:秒)或者# clock --set --date="06/18/14 14:55" (月/日/年時:分:秒)
硬件時鐘與系統時鐘同步:
# hwclock --hctosys 或者 # clock --hctosys hc表明硬件時間,sys表明系統時間,即用硬件時鐘同步系統時鐘
系統時鐘和硬件時鐘同步:
# hwclock --systohc或者# clock --systohc 即用系統時鐘同步硬件時鐘
修改配置文件來修改時區
#########服務器:#########
1、時間服務器端配置
修改配置文件vi /etc/ntp.conf
一、客戶端選擇
1)容許任何客戶端
restrict default nomodify
2)容許特定客戶端
restrict 192.168.18.0 mask 255.255.255.0 nomodify
server 192.168.0.84
*二選一
二、指定時間服務器
1)指定特定時間服務器,註釋掉默認server服務器
server time-b.nist.gov
2)開啓本地時間服務器,上述外網time-b.nist.gov失效時,內網充當時間服務器。
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
三、重啓時間服務
service ntpd restart
4、根據實際需求設置防火牆端口
udp 123
#########客戶端#########
1、linux客戶端
一、linux客戶端修改配置文件,註釋掉其它時間服務器,指定內網時間服務器,重啓ok。
vim /etc/ntp.conf
server x.x.x.x
二、客戶端校驗
ntpq -p查詢上級時間服務器
ntpstat 查詢狀態
ntpdate