Linux集群时间同步(Ubuntu) [操作系统入门]

编程

在配置hadoop集群时,时间同步是必须要做的,否则会出现各种意想不到的问题。

hadoop102 为 ntp server,hadoop103以及hadoop104 为ntp client(即需要同步时间机器)

1.全部机器都要安装ntp以及ntpdate

sudo apt-get install ntp

sudo apt-get install ntpdate

2.关闭所有的机器的ntp,每个机器执行命令 一下命令

sudo service ntp stop 

查看ntp状态

sudo service ntp status

3.修改ntp server即hadoop102的/etc/ntp.conf文件

sudo vim /etc/ntp.conf

相关条文解释,参考https://www.cnblogs.com/xwdreamer/p/3448773.html

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift

# Leap seconds definition provided by tzdata

leapfile /usr/share/zoneinfo/leap-seconds.list

# Enable thisif you want statistics to be logged.

#statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats

filegen loopstats file loopstats type day enable

filegen peerstats file peerstats type day enable

filegen clockstats file clockstats type day enable

# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board

# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for

# more information.

pool 0.ubuntu.pool.ntp.org iburst

pool 1.ubuntu.pool.ntp.org iburst

pool 2.ubuntu.pool.ntp.org iburst

pool 3.ubuntu.pool.ntp.org iburst

# Use Ubuntus ntp server as a fallback.

pool ntp.ubuntu.com

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for

# details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>

# might also be helpful.

#

# Note that "restrict" applies to both servers and clients, so a configuration

# that might be intended to block requests from certain clients could also end

# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but dont allow configuration.

restrict -4default kod notrap nomodify nopeer noquery limited

restrict -6default kod notrap nomodify nopeer noquery limited

# Local users may interrogate the ntp server more closely.

restrict 127.0.0.1

restrict ::1

# Needed for adding pool entries

restrict source notrap nomodify noquery

# Clients fromthis (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 dothis only if you trust everybody on the network!

#disable auth

#broadcastclient

改为如下后保存:

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift

# Leap seconds definition provided by tzdata

leapfile /usr/share/zoneinfo/leap-seconds.list

# Enable this if you want statistics to be logged.

#statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats

filegen loopstats file loopstats type day enable

filegen peerstats file peerstats type day enable

filegen clockstats file clockstats type day enable

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board

# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for

# more information.

#pool 0.ubuntu.pool.ntp.org iburst

#pool 1.ubuntu.pool.ntp.org iburst

#pool 2.ubuntu.pool.ntp.org iburst

#pool 3.ubuntu.pool.ntp.org iburst

# Use Ubuntu‘s ntp server as a fallback.

#pool ntp.ubuntu.com

server 127.127.1.0

fudge 127.127.1.0 stratum 10

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for

# details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>

# might also be helpful.

#

# Note that "restrict" applies to both servers and clients, so a configuration

# that might be intended to block requests from certain clients could also end

# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but dont allow configuration.

restrict -4default kod notrap nomodify nopeer noquery limited

restrict -6default kod notrap nomodify nopeer noquery limited

# Local users may interrogate the ntp server more closely.

restrict 127.0.0.1

restrict ::1

# Needed for adding pool entries

restrict source notrap nomodify noquery

# Clients from this (example!) subnet have unlimited access, but only if

# cryptographically authenticated.

restrict 192.168.123.0 mask 255.255.255.0 nomodify notrap

# 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

4.对ntp server (hadoop102)执行命令,开启服务

sudo service ntp start

5.同步时间(除hadoop102的其他机器都要执行)

sudo ntpdate hadoop102

6 在除hadoop102的其他机器,将同步时间的命令放在crontab中(切换到root用户下操作)

*/10 * * * * /usr/sbin/ntpdate hadoop102

每十分钟更新一次

相关错误:

 no server suitable for synchronization found

http://www.blogjava.net/spray/archive/2008/07/10/213964.html

Ubuntu 时间设置

https://www.cnblogs.com/qiumingcheng/p/12210629.html

 

Linux 集群时间同步(Ubuntu)

以上是 Linux集群时间同步(Ubuntu) [操作系统入门] 的全部内容, 来源链接: utcz.com/z/518418.html

回到顶部