linux多主机时间同步方法

假设现在有三台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.104 offset -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.104 offset -0.002740 sec

 

此时105、106主机的时间就与104主机完全同步了

方法2、使用系统时间与BIOS时间同步:

方法1我试了一下,当一天之后服务器经过多次重启好像时间又有了误差

我们还可以将系统时间同步到BIOS时间,因为每次开机的时候,系统会重新由 BIOS 将时间读出来,所以, BIOS 才是重要的时间依据。

[[email protected] ~]# hwclock -r            //查看现有BIOS时间,默认为-r参数

2018年11月27日 星期二 17时19分51秒  -0.019817 seconds

[[email protected] ~]# hwclock -w            //同步BIOS时钟,强制把系统时间写入CMOS

[[email protected] ~]# hwclock --systohc      //设置BIOS时间和系统时间一致

另外两个主机都执行这个操作,这样应该就不变了

方法3、使用系统时间与网络时间同步:

当然这是多主机时间同步的方法之一,还可以都同步网络时间(上海时间),但是那样需要网络

[[email protected] ~]# yum -y install ntp               //安装ntp服务

[[email protected] ~]# ntpdate -u ntp.api.bz         //使系统时间同步上海时间

[[email protected] ~]# /10 * /usr/sbin/ntpdate asia.pool.ntp.org &>/dev/null       //写入定时任务同步时间

[[email protected] ~]# service crond restart              //重启定时任务服务

[[email protected] ~]# date                                  //查看时间是否同步

另外两个主机重复以上操作

补充说明: ntpdate -u ntp.api.bz 命令中的 ntp.api.bz 指NTP服务器(上海),也可换成:

                    210.72.145.44:中国国家授时中心的官方服务器,但这个我试了一下,没连接上

                    time.nist.gov:美国

                    ntp.fudan.edu.cn:复旦

                    time.windows.com :微软公司授时主机(美国)

                    asia.pool.ntp.org:台警大授时中心(中国台湾)

也可参考这个链接:http://blog.51cto.com/arm2012/1977075

猜你喜欢

转载自blog.csdn.net/qq_28903377/article/details/84550050
今日推荐