如何在Ubuntu16和Ubuntu8上安装NTP服务器和客户端,互联网同步

如何在Ubuntu16和Ubuntu18上安装NTP服务器和客户端

第一修改时区

NTP服务器和客户端都设置统一的时区

首先输入date查看自己的时间时区,可以看到是UTC时区,如果是CST时区则可以跳过这个步骤:
然后输入tzselect,选择4 9 1 1 (具体情况具体选择,最后是的结果是
TZ=‘Asia/Shanghai’ CST )

输入1确认,执行TZ=‘Asia/Shanghai’; export TZ生效,并将这些指令写入.bashrc文件中,source一下,重启电脑,再次运行date可看到已经到了CST时区

root@VM-4-11-ubuntu:~# date
Sat May 28 22:19:29 CST 2022
root@VM-4-11-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) 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.
Selected time is now:	Sat May 28 22:19:59 CST 2022.
Universal Time is now:	Sat May 28 14:19:59 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
root@VM-4-11-ubuntu:~# TZ='Asia/Shanghai'; export TZ
root@VM-4-11-ubuntu:~# date
Sat May 28 22:24:09 CST 2022
root@VM-4-11-ubuntu:~# 

第二 设置服务器

在服务端安装相关软件

sudo apt-get install ntp
/etc/init.d/ntp start

然后配置系统的UFW防火墙,以使传入的连接可以通过UDP端口号123访问NTP服务器
以sudo身份运行以下命令以打开端口123以接收传入流量:

sudo apt install ufw
sudo ufw allow from any to any port 123 proto udp

显示如下,表明配置成功

在这里插入图片描述

第三设置客户端

1.客户端安装ntp

sudo apt-get install ntpdate
ntpdate 192.168.33.200  //服务器地址ip

2.客户端定时更新
上述指令是一次性更新,如果我们想要让客户端定期去更新维护,则需要用到crontab指令

sudo vi /etc/crontab
30 08 * * * root /usr/sbin/ntpdate 192.168.33.200  #表示每天8:30自动执行ntpdate指令,与服务器时间同步
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_14910065

你的支持是我最大的努力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值