linux设置三台机时间同步,linux配置ntp时间同步,与zookeeper的安装

一、linux配置ntp时间同步

(一)确认ntp的安装,保证安装好ntp

1、查看ntp是否存在

rpm –qa | grep ntp

2、如果出现则删除原有的ntp(如果没有出现,此步省略)

yum –y remove ntpdate-....

3、下载ntp

yum –y install ntp

(二)配置ntp文件

1、修改所有节点的/etc/ntp.conf

vi /etc/ntp.conf

打开之后是这个样子,然后添加两行代码

restrict 192.168.6.3 nomodify notrap nopeer noquery //当前节点IP地址

restrict 192.168.6.2 mask 255.255.255.0 nomodify notrap //集群所在网段的网关(Gateway),子网掩码(Genmask)

920f1dd224886673f76c80a88e326120.png

网关不知道可以用cmd命令查找ipconfig

ac71caffb5b2a8b61ade1c81ad584d4a.png

2、选择一个作为主节点,修改其/etc/ntp.conf

注:选择作为主节点的机器不一定是hadoop的主节点,这可以随意自定,但是选择之前要去查看作为主节点的机器时间是否正确,输入date查看。

如果集群机器时间都不正确可以选择一台进行修改:date -s 填写当前的时间

把原先server注掉,在server部分下面添加如下语句

server 127.127.1.0

Fudge 127.127.1.0 stratum 10 ---每10秒更新一次

3、剩下的机器,修改其/etc/ntp.conf

把原先server注掉,在server部分下面添加如下语句

server 192.168.222.121 --当前主机ip地址

Fudge 192.168.222.121 stratum 10--当前主机ip地址

45135d649ecaf876ea7b7baf9cfe5b4c.png

(三)启动ntp服务、查看状态

1、启动ntp服务

service ntpd start

2、查看ntp服务器有无和上层ntp连通

ntpstat

然后可以输入date进行查看

3、查看ntp服务器与上层ntp的状态

ntpq -p

c9c2b1cebfcea49b3c359e38df2473ad.png

(四)还可以通过配置设置配置文件让硬件与系统时间同步

vim /etc/sysconfig/ntpd

-----------------------

# 增加内容如下(让硬件时间与系统时间一起同步)

SYNC_HWCLOCK=yes

重新启动ntpd

service ntpd status

service ntpd start

chkconfig ntpd on

其他机器配置

crontab -e

----------------

*/10 * * * * /usr/sbin/ntpdate hadoop2

二、zookeeper的安装

安装须知

1.单机不能配置zookeeper

2.配置zookeeper不能配置双数台,只能配置三台、五台这样的hadoop集群。

1、将安装包拖放在相应的位置,解压到想要的文件夹

解压命令:tar -zxvf zookeeper-3.4.6.tar.gz -C /opt

这里是解压到/opt目录下的

为了方便还可以进行改名操作:mv zookeeper-3.4.6/ zookpr

2、修改配置文件

进入zookpr/conf文件夹中,配置zoo.cfg文件

注:里面可能没有zoo.cfg文件此时需要修改文件名,也可以选择复制一份。

# The number of milliseconds of each tick

tickTime=2000

maxClientCnxns=0

# The number of ticks that the initial

# synchronization phase can take

initLimit=50

# The number of ticks that can pass between

# sending a request and getting an acknowledgement

syncLimit=5

# the directory where the snapshot is stored.

# do not use /tmp for storage, /tmp here is just

# example sakes.

dataDir=/opt/hadoop/zookprdata--这值修改数据存放的地方,可以不做修改,但是建议改到hadoop下面

# the port at which the clients will connect

clientPort=2181

# the maximum number of client connections.

# increase this if you need to handle more clients

#maxClientCnxns=60

#

# Be sure to read the maintenance section of the

# administrator guide before turning on autopurge.

#

# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance

#

# The number of snapshots to retain in dataDir

#autopurge.snapRetainCount=3

# Purge task interval in hours

# Set to "0" to disable auto purge feature

#autopurge.purgeInterval=1

server.1=hadoop101:2888:3888 --hadoop101是主机名

server.2=hadoop102:2888:3888

server.3=hadoop103:2888:3888

8e4a0c6f61949a0bb1ed6e34ea05e4f2.png

将配置文件改名,并传输到其他机器的相应位置

mv zoo_sample.cfg zoo.cfg --将配置文件改名

scp zoo.cfg root@192.168.222.122:/opt/zookpr/conf/ --将改名后的配置文件传输到其他机器相应的位置,并删除其他文件原有的文件

rm -rf zoo_sample.cfg --删除其他机器上原有的文件

刚刚在配置文件的时候设置了数据存放位置要在hadoop下新建相应的文件夹

cd /opt/hadoop --进入hadoop文件,这里的hadoop是被改过名字的

mkdir zookprdata -新建zookeeper数据存放位置

进入zookprdata中,新建myid文件

cd zookprdata/ --进入zookprdata文件夹

vi myid --新建myid文件

在其中写入刚刚配置文件中server后配置的server.的数。

c3ecef56b7cc2c049a1d227da240262e.png

对应机器是几就写几

4e45e8b46f55b4e4828399b92d259cc9.png

3、 启动zookeeper

在各zookeeper节点上运行zkServer.sh start。

cd /opt/zookpr--进入zookpr

./bin/zkServer.sh start --启动zookpr

tail zookeeper.out--查看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值