不灭的焱

革命尚未成功,同志仍须努力下载JDK17

作者:Albert.Wen  添加时间:2018-08-25 18:58:34  修改时间:2024-04-30 22:01:45  分类:Linux软件安装/参数优化  编辑

1、下载

http://zookeeper.apache.org/releases.html

当前stable版是zookeeper-3.4.13

3、解压

tar –xzvf  ./zookeeper-3.4.13.tar.gz

解压文件到 "/alidata/server/zookeeper/zookeeper-3.4"

4、复制 conf 目录下的 zoo_sample.cfg,并命名为 zoo.cfg

5、修改 zoo.cfg 配置文件

# 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=/alidata/data/zookeeper
dataLogDir=/alidata/server/zookeeper/zookeeper-3.4/logs
# 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 
#2888,3888 are election port
server.1=zookeeper:2888:38888

其中,2888端口号是服务之间通信的端口,而3888是 zookeeper 与其他应用程序通信的端口,而zookeeper是在hosts中已映射了本机的IP。

initLimit:这个配置项是用来配置Zookeeper接受客户端(这里所说的客户端不是用户连接Zookeeper服务器的客户端,而是Zookeeper服务器集群中连接到 Leader 的 Follower 服务器)初始化连接时最长能忍受多少个心跳时间间隔数。当已经超过 10 个心跳的时间(也就是 tickTime)长度后 Zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败。总的时间长度就是 5*2000=10 秒。

syncLimit:这个配置项标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 2*2000=4 秒。

server.A=B:C:D:其中 A 是一个数字,表示这个是第几号服务器;B 是这个服务器的 ip 地址;C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同的端口号。

6、创建 dataDir 参数指定的目录(这里指的是“ /alidata/data/zookeeper”),并在目录下创建文件,命名为“myid”。

7、编辑“myid”文件,并在对应的IP的机器上输入对应的编号。如在zookeeper上,“myid”文件内容就是1。由于本次只在单点上进行安装配置,所以只有一个server.1。若还有其他服务器,比如地址为192.168.1.102,则在 zoo.cfg 文件中还需加入 server.2=192.168.1.102:2888:3888。那么myid文件在192.168.1.102服务器上的内容就是2。至此,如果是多服务器配置,就需要将 zookeeper-3.4 目录拷贝到其他服务器,然后按照上述的方法修改myid。

8、在 /etc/profile 文件中设置PATH

vim  /etc/profile
export ZOOKEEPER_HOME=/alidata/server/zookeeper/zookeeper-3.4
export PATH=$ZOOKEEPER_HOME/bin:$PATH
export PATH

 

安装完毕!启动搞搞

1、启动

cd /alidata/server/zookeeper/zookeeper-3.4/bin 
./zkServer.sh start

2、输入 jps 命令查看进程

[root@CentOS-A  zookeeper-3.4]# jps

25729 Startup
21970 Startup
25059 Startup
25477 Startup
1557 Application
25366 QuorumPeerMain
28727 Jps
21401 Startup
24827 Startup
27326 JobXAgent

其中,QuorumPeerMain是zookeeper进程,启动正常。

3、查看状态:

[root@CentOS-A zookeeper-3.4]# ./bin/zkServer.sh status

ZooKeeper JMX enabled by default
Using config: /alidata/server/zookeeper/zookeeper-3.4/bin/../conf/zoo.cfg
Mode: standalone

4、启动客户端脚本:

./bin/zkCli.sh -server zookeeper:2181

5、停止zookeeper进程:

./bin/zkServer.sh stop

 

 

 参考:

http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html