Linux Zookeeper installation with video

Crazy maker culture circle Java [one hundred million concurrent high flow chat room] actual combat series [ blog park entrance total ]

+ Interview Interview essential essential basis for high concurrency books [ Netty Zookeeper Redis high concurrency combat ]


Crazy maker culture circle high concurrency environment video, one after another on-line:

  • Windows Redis installed (with video)
  • Linux Redis installed (with video)
  • Windows Zookeeper installation (with video)
  • Linux Zookeeper installation (with video)
  • RabbitMQ offline installation (video tape)
  • Nacos installation (video tape)
  • ElasticSearch installation with video

Small video and tools needed to Baidu network disk link , see the crazy maker culture circle high concurrency community blog

What is pseudo trunked mode 1

In a learning environment, if no extra server, there will be three ZooKeeper nodes are installed on the local machine, so that the dummy title trunked mode.
While, the dummy pattern only facilitate the development of the cluster, common test, try not for production environments. From a learning perspective, if understand the installation and configuration of a pseudo-cluster model, in a production environment installation and configuration method, also roughly the same.

Before installing ZooKeeper, need to schedule a pseudo-cluster node number, ZooKeeper nodes have the following requirements:
(1) ZooKeeper cluster nodes must be the base.
why? ZooKeeper cluster, the need for a master node, called the leader node. leader node of the cluster through regular elections, elected from all nodes. Regular elections is a very important one: Quantity available nodes> The total number of nodes / 2. If it is an even number of nodes, it does not satisfy this rule may occur.
(2) ZooKeeper cluster of at least three.
ZooKeeper node can be a normal start-up and service. However, ZooKeeper service node, can not be called a cluster, its reliability greatly reduced, just as learning to use. Under normal circumstances, to build ZooKeeper cluster, we need at least three nodes.

Here, as a case study, on the local machine, planning to build a pseudo-cluster node 3. In fact, when activated, to start two nodes, Zookeeper can work properly.

2 Download and unzip

The first is to download. Provides a lot of mirror Download in apache's official website, then find the corresponding version, the latest is 3.4.13.

http://mirrors.cnnic.cn/apache/ZooKeeper/ZooKeeper-3.4.13/ZooKeeper-3.4.13.tar.gz

Crazy maker culture circle network disk, already the prepared installation package can also be directly downloaded

mkdir -p  /work/zookeeper/zooKeeper-3.4.13
tar  -zxvf  /work/zookeeper/zooKeeper-3.4.13.tar.gz   -C   /work/zookeeper/zooKeeper-3.4.13

3 install Zookeeper

The first step in installing a cluster, the installation directory, created two directories: log directory, data directory.

mkdir -p  /work/zookeeper/zooKeeper-3.4.13/data

mkdir -p   /work/zookeeper/zooKeeper-3.4.13/logs

Enter /work/zookeeper/zooKeeper-3.4.13/conf directory, zoo_sample.cfg copy of the document name to zoo.cfg.

cp zoo_sample.cfg zoo.cfg

4 zoo.cfg modify configuration files

Zoo.cfg modify profile settings log directory, data directory, the client connection port configuration, the pseudo cluster nodes

dataDir=/work/zookeeper/zookeeper_01/data

dataLogDir=/work/zookeeper/zookeeper_01/logs

clientPort=2181


server.1=192.168.71.82:2881:3881

server.2=192.168.71.82:2882:3882

server.3=192.168.71.82:2883:3883

Present the two catalogs setting options are as follows:


dataDir=/work/zookeeper/zookeeper_01/data

dataLogDir=/work/zookeeper/zookeeper_01/logs

(1)dataDir:数据目录选项,配置为前面准备的数据目录。myid文件,处于此目录下。
(2) dataLogDir:日志目录选项, 配置为前面准备的日志目录。如果没有设置该参数,默认将使用和dataDir相同的设置。

clientPort = 2181 的介绍如下:

clientPort: 表示client客户端连接ZooKeeper集群中的节点的端口号。在生成环境的集群中,不同的节点,处于不同的机器,端口号一般都相同,便于记忆和使用。由于这里是伪集群模式,所以,三个节点集中在一台机器上,所以3个端口号,配置为不一样。
clientPort:一般设置为2181。伪集群下,不同的节点,clientPort不能相同,可以按照编号,进行累加。

集群节点信息的配置,示例如下:

server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890

节点信息,需要配置集群中所有节点的 (id)编号、IP、端口。在“.cfg”配置文件中,可以按照这样的格式进行配置,每一行都代表一个节点。一个节点格式为:

server.id=host:port:port

在ZooKeeper集群中,每个节点都需要感知到整个集群是哪些节点组成,所以,每一个配置文件,都需要配置全部的节点。

总体来说,配置节点的时候,注意四点:
(1)不能有相同id的节点,需要确保每个节点的myid文件中的id值不同;
(2)每一行 “server.id=host:port:port”中的id值,需要与所对应节点的数据目录下的myid中的id值,保持一致;
(3)每一个配置文件,都需要配置全部的节点信息。不仅仅是配置自己的那份,而是需要所有节点的id、ip、端口配置。
(4)每一行 “server.id=host:port:port”中,需要配置两个端口。前一个端口为通信端口(如示例中的2888)用于节点之间的通讯使用,后一个端口为选主端口(如上的3888)用于选举 leader主节点使用。
(5)在伪集群的模式下,每一行记录,相同的端口必须修改都不一样,主要是避免端口冲突。在分布式集群模式下,由于不同节点的ip不同,每一行记录,可以端口相同。

5 创建myid文件文件

在data目录下,为每一个节点,创建一个id文件。每一个节点,需要有一个记录节点id 的文本文件,文件名为myid。myid文件的特点如下:
(1)myid文件的唯一作用,是记录(伪)节点的编号;
(2)myid文件是一个文本文件,文件名称为myid;
(3)myid文件内容为一个数字,表示节点的编号;
(4)myid文件中,只能有一个数字,不能有其他的内容;
(5)myid文件的存放位置,默认处于数据目录下面。

ZooKeeper对id的值,有何要求呢?
首先,myid文件中id的值,只能是一个数字,即一个节点的编号ID;
其次,id的范围是1~255,表示集群最多的节点个数为255个。

6 复制节点

将zooKeeper-3.4.13 复制三份分别取名为zookeeper_01和zookeeper_02和zookeeper_03。第三份可以复制也可以不复制。

cp  /work/zooKeeper/zooKeeper-3.4.13   /work/zooKeeper/zookeeper_01

cp  /work/zooKeeper/zooKeeper-3.4.13   /work/zooKeeper/zookeeper_02

cp  /work/zooKeeper/zooKeeper-3.4.13   /work/zooKeeper/zookeeper_03

并且在每一份的配置文件中,修改正确的路径,端口号、以及myid 文件的编号。

比如 /work/zookeeper_02的/conf/zoo.cfg的配置项,修改如下。

dataDir=/data/zookeeper/zookeeper_02/data

dataLogDir=/data/zookeeper/zookeeper_02/logs

clientPort=2182

server.1=192.168.71.82:2881:3881

server.2=192.168.71.82:2882:3882

server.3=192.168.71.82:2883:3883

比如 /work/zookeeper_02/data/myid的数字,也需要对应修改为2。

7.启动

分别进入启动三台服务。至少2台。

/work/zookeeper/zookeeper-01/bin/zkServer.sh start

/work/zookeeper/zookeeper-02/bin/zkServer.sh start

10.启动完成后,查看服务状态。

/work/zookeeper/zookeeper-02/bin/zkServer.sh  status

8 设置开机启动

在开机启动命令文件中,加入两行,命令如下:

vim /etc/rc.local 

加入两行,如下:


/usr/bin/su  - root  -c   "/work/zookeeper/zookeeper-01/bin/zkServer.sh start"
/usr/bin/su  - root  -c   "/work/zookeeper/zookeeper-02/bin/zkServer.sh start"

具体,请关注 Java 高并发研习社群博客园 总入口


最后,介绍一下疯狂创客圈:疯狂创客圈,一个Java 高并发研习社群博客园 总入口

疯狂创客圈,倾力推出:面试必备 + 面试必备 + 面试必备 的基础原理+实战 书籍 《Netty Zookeeper Redis 高并发实战

img


疯狂创客圈 Java 死磕系列

  • Java (Netty) 聊天程序【 亿级流量】实战 开源项目实战

  • Netty 源码、原理、JAVA NIO 原理
  • Java 面试题 一网打尽
  • 疯狂创客圈 【 博客园 总入口 】


Guess you like

Origin www.cnblogs.com/crazymakercircle/p/12006500.html