假设现在有三台linux主机:
172.16.1.104
172.16.1.105
172.16.1.106
方法1、使用NTP服务器同步:
[[email protected]~]# vi /etc/ntp.conf //编辑NTP配置文件
在图示位置加入红色框选中内容
[[email protected]~]# service ntpd start //启动NTP服务
[[email protected]~]# ntpdate 172.16.1.104 //设置105主机时间与104同步
会有显示:25 Oct 14:20:21 ntpdate[3407]: adjust time server 172.16.1.104offset -0.002740 sec
[[email protected]~]# ntpdate 172.16.1.104 //设置106主机时间与104同步
会有显示:25 Oct 14:20:21 ntpdate[3407]: adjust time server 172.16.1.104offset -0.002740 sec
此时105、106主机的时间就与104主机完全同步了
方法2、使用系统时间与BIOS时间同步:
方法1我试了一下,当一天之后服务器经过多次重启好像时间又有了误差
我们还可以将系统时间同步到BIOS时间,因为每次开机的时候,系统会重新由 BIOS 将时间读出来,所以,BIOS 才是重要的时间依据。
[[email protected]~]# hwclock -r //查看现有BIOS时间linux系统时间同步,默认为-r参数
2018年11月27日 星期二 17时19分51秒 -0.019817 seconds
[[email protected]~]# hwclock -w //同步BIOS时钟,强制把系统时间写入CMOS
[[email protected]~]# hwclock --systohc //设置BIOS时间和系统时间一致
另外两个主机都执行这个操作linux运维招聘,这样应该就不变了
方法3、使用系统时间与网络时间同步:
当然这是多主机时间同步的方法之一,还可以都同步网络时间(上海时间)linux系统时间同步linux课程,但是那样需要网络
[[email protected]~]# yum -y install ntp //安装ntp服务
[[email protected]~]# ntpdate -u ntp.api.bz //使系统时间同步上海时间
[[email protected]~]#/10* /usr/sbin/ntpdate &>/dev/null //写入定时任务同步时间
[[email protected]~]#service crond restart //重启定时任务服务
[[email protected]~]# date //查看时间是否同步
另外两个主机重复以上操作
补充说明: ntpdate -u ntp.api.bz 命令中的ntp.api.bz 指NTP服务器(上海),也可换成:
210.72.145.44:中国国家授时中心的官方服务器,但这个我试了一下,没连接上
:美国
:复旦
:微软公司授时主机(美国)
:台警大授时中心(中国台湾)
也可参考这个链接:linux 永久设置时间同步方法_51CTO博客_linux同步时间
两台linux机器时间同步-jonelaw-ChinaUnix博客