分布式zookeeper安装

1、下载zookeeper到/usr/hadoop目录下,解压
官网:http://zookeeper.apache.org/releases.html#download

tar -zxvf zookeeper*

2、修改conf/zoo_sample.cfg为zoo.cfg,内容为以下,只改了最后4行,添加的4个节点。

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# 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=/usr/hadoop/zookeeper-3.4.12/data
# 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=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
server.4=slave3:2888:3888

关于zoo.cfg配置

a.在集群模式下,集群中每台机器都需要感知到整个集群是由哪几台机器组成的,在配置文件中,可以按照这样的格式进行配置,每一行都代表一个机器配置:server.id=host:port:port,

其中,id被称为 Server ID,用来标识该机器在集群中的机器序列号。同时,在每台Zookeeper机器上,我们都需要在数据目录(即dataDir参数指定的那个目录)下创建一个myid文件,该文件只有一行内容,并且是一个数字,即对应于每台机器的Server ID 数字。

b.在Zk的设计中,集群中所有机器上的zoo.cfg文件的内容都应该是一致的。因此最好使用svn或是git把此文件管理起来,确保每个机器都能共享到一份相同的配置。

c.上面也提到了,myid文件中只有一个数字,即一个Server ID。例如,server.1的myid文件内容就是”1”。注意,清确保每个服务器的myid文件中的数字不同,并且和自己所在机器的zoo.cfg中server.id=houst:port:port的id一致。另外,id的范围是1~255。

d.参数的意义:
tickTime:默认值为3000,单位是毫秒(ms),可以不配置。参数tickTime用于配置Zookeeper中最小时间单元的长度,很多运行时的时间间隔都是使用tickTime的倍数来表示的。例如,Zk中会话的最小超时时间默认是2*tickTime。
dataDir:该参数无默认值,必须配置。参数dataDir用于配置Zookeeper服务器存储快照文件的目录。
clientPort:参数clientPort用于配置当前服务器对外的服务端口,客户端会通过该端口和Zk服务器创建连接,一般设置为2181。
initLimit:该参数默认值:10,表示是参数tickTime值的10倍,必须配置,且为正整数。该参数用于配置Leader服务器等待Follower启动,并完成数据同步的时间。Follower服务器在启动过程中,会与Leader建立连接并完成对数据的同步,从而确定自己对外提高服务的起始状态。leader服务器允许Follower在initLimit时间内完成这个工作。
syncLimit:该参数默认值:5,表示是参数tickTime值的5倍,必须配置,且为正整数。该参数用于配置Leader服务器和Follower之间进行心跳检测的最大延时时间。在Zk集群运行的过程中,Leader服务器会与所有的Follower进行心跳检测来确定该服务器是否存活。如果Leader服务器在syncLimit时间内无法获取到Follower的心跳检测响应,那么Leader就会认为该Follower已经脱离了和自己的同步。
server.id:该参数无默认值,在单机模式下可以不配置。该参数用于配置组成Zk集群的机器列表,其中id即为Server ID,与每台服务器myid文件中的数字相对应。同时,在该参数中,会配置两个端口:第一个端口用于指定Follower服务器与Leader进行运行时通信和数据同步时所使用的端口,第二个端口测专门用于进行Leader选举过程中的投票通信。

3、在zookeeper目录下创建data文件夹,并添加myid(内容为:1)文件,这个1对应的是配置文件里面:server.1=master:2888:3888,server.id

mkdir data

echo "1" >myid

3、将内容分发到其它节点,同时修改data文件夹下myid为对应的id,如slave1里面id为2,slave2里面id为3,如此推类。

scp -rq /usr/hadoop/zookeeper-3.4.12/ root@slave1:/usr/hadoop/
scp -rq /usr/hadoop/zookeeper-3.4.12/ root@slave2:/usr/hadoop/
scp -rq /usr/hadoop/zookeeper-3.4.12/ root@slave3:/usr/hadoop/

4、启动zookeeper,每一个节点都要,进入zookeeper的bin目录下:
第一次启动建议用以下命令,启动时输入日志,毕竟第一次很可能是不成功的
A:带日志启动,日志也会输出到bin目录下zookeeper.out文件里面

./zkServer.sh start-foreground

B、查看状态

[root@slave1 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/hadoop/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: follower

C、正常启动

[root@slave1 bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/hadoop/zookeeper-3.4.12/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

5、jps发现6036 QuorumPeerMain已经启动

[root@slave1 bin]# jps
6036 QuorumPeerMain
3125 SecondaryNameNode
6426 Jps
4013 NodeManager
3039 DataNode

ok,感谢党

猜你喜欢

转载自blog.csdn.net/lglglgl/article/details/80724938