Table of Contents
在CentOS 7 上安装Zookeeper集群
Home php教程 php手册 在CentOS 7 上安装Zookeeper集群

在CentOS 7 上安装Zookeeper集群

Jun 13, 2016 am 08:47 AM
android

在CentOS 7 上安装Zookeeper集群

测试机上需要安装java软件
$ rpm -qa|grep java
$ sudo yum install -y java-1.8.0-openjdk.x86_64
$ java -version
openjdk version "1.8.0_65"
OpenJDK Runtime Environment (build 1.8.0_65-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)

1、创建用户:bjrenrui0001~0003
sudo groupadd zookeeper
sudo useradd -g zookeeper zookeeper
echo "zookeeper@1234"|sudo passwd zookeeper —stdin

2、创建工作目录
bjrenrui0001:
sudo mkdir /yanfa/mq
sudo ln -s /yanfa/mq /mq
sudo chown -R dreamjobs.dreamjobs /mq

bjrenrui0002~0003:
sudo mkdir mq
sudo chown dreamjobs.dreamjobs mq
sudo ln -s /home/backupfile/mq /mq
sudo chown dreamjobs.dreamjobs mq

1. 单机模式(Standalone mode)
下载,解压
cd /mq
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.7/zookeeper-3.4.7.tar.gz
tar zxvf zookeeper-3.4.7.tar.gz -C /mq
ln -s /mq/zookeeper-3.4.7 zookeeper

启动
默认就是单机模式
cd /mq/zookeeper/
cp ./conf/zoo_sample.cfg ./conf/zoo.cfg
sh ./bin/zkServer.sh start

防火墙开启2181端口

检查服务状态:
[dreamjobs@bjrenrui0001 bin]$ sh zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /mq/zookeeper/bin/../conf/zoo.cfg
Mode: standalone

使用java 客户端连接ZooKeeper
./bin/zkCli.sh -server 127.0.0.1:2181
然后就可以使用各种命令了,跟文件操作命令很类似,输入help可以看到所有命令。

关闭
sh bin/zkServer.sh stop

2 分布式模式(Replicated mode)
在生产环境中,要配置成分布式模式,才能发挥威力。
ZooKeeper集群一般被称为ZooKeeper ensemble(集成),或者 quorum(法定人数).

准备3台机器

假设有三台机器,hostname和ip对应关系是:
192.168.100.200 bjrenrui0001
192.168.100.201 bjrenrui0002
192.168.100.202 bjrenrui0003

ZooKeeper不存在明显的master/slave关系,各个节点都是服务器,leader挂了,会立马从follower中选举一个出来作为leader.
由于没有主从关系,也不用配置SSH无密码登录了,各个zk服务器是自己启动的,互相之间通过TCP端口来交换数据。

创建日志和数据目录:
bjrenrui0001~0003
cd /mq/zookeeper
mkdir -p zookeeperdatadir/{logs,data}

修改bjrenrui0001的配置文件conf/zoo.cfg:
[dreamjobs@bjrenrui0001 conf]$ grep -vE '^($|#)' zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/mq/zookeeper/zookeeperdatadir/data
dataLogDir=/mq/zookeeper/zookeeperdatadir/logs
clientPort=2181
server.1=bjrenrui0001:2888:3888
server.2=bjrenrui0002:2888:3888
server.3=bjrenrui0003:2888:3888
修改完后拷贝到 bjrenrui0002,以及 bjrenrui0003上

myid文件:
要在每台机器的dataDir下,新建一个myid文件,里面存放一个数字,用来标识当前主机
bjrenrui0001: echo "1" >> /mq/zookeeper/zookeeperdatadir/data/myid
bjrenrui0002: echo "2" >> /mq/zookeeper/zookeeperdatadir/data/myid
bjrenrui0003: echo "3" >> /mq/zookeeper/zookeeperdatadir/data/myid

每台机器上启动zookeeper服务:
bjrenrui0001: sh /mq/zookeeper/bin/zkServer.sh start
bjrenrui0002: sh /mq/zookeeper/bin/zkServer.sh start
bjrenrui0003: sh /mq/zookeeper/bin/zkServer.sh start
每台机器上停止zookeeper服务:
bjrenrui0001: sh /mq/zookeeper/bin/zkServer.sh stop
bjrenrui0002: sh /mq/zookeeper/bin/zkServer.sh stop
bjrenrui0003: sh /mq/zookeeper/bin/zkServer.sh stop
因为3个节点的启动是有顺序的,所以在陆续启动三个节点的时候,前面先启动的节点连接未启动的节点的时候会报出一些错误,可以忽略。

防火墙开启2181端口:
sudo vi /etc/sysconfig/iptables
-A INPUT -p tcp -s 192.168.100.0/24 -j ACCEPT
sudo systemctl restart iptables.service

查看状态
[dreamjobs@bjrenrui0001 conf]$ gmbjyf.sh bjyfnbserver "cat /mq/zookeeper/zookeeperdatadir/data/myid"
bjrenrui0001
1
bjrenrui0002
2
bjrenrui0003
3
$ gmbjyf.sh bjyfnbserver "sh /mq/zookeeper/bin/zkServer.sh restart"
bjrenrui0001
ZooKeeper JMX enabled by default
Using config: /mq/zookeeper/bin/../conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /mq/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
ZooKeeper JMX enabled by default
Using config: /mq/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
bjrenrui0002
ZooKeeper JMX enabled by default
Using config: /mq/zookeeper/bin/../conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /mq/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
ZooKeeper JMX enabled by default
Using config: /mq/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
bjrenrui0003
ZooKeeper JMX enabled by default
Using config: /mq/zookeeper/bin/../conf/zoo.cfg
ZooKeeper JMX enabled by default
Using config: /mq/zookeeper/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
ZooKeeper JMX enabled by default
Using config: /mq/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper … STARTED

$ gmbjyf.sh bjyfnbserver "sh /mq/zookeeper/bin/zkServer.sh status"
bjrenrui0001
ZooKeeper JMX enabled by default
Using config: /mq/zookeeper/bin/../conf/zoo.cfg
Mode: follower
bjrenrui0002
ZooKeeper JMX enabled by default
Using config: /mq/zookeeper/bin/../conf/zoo.cfg
Mode: leader
bjrenrui0003
ZooKeeper JMX enabled by default
Using config: /mq/zookeeper/bin/../conf/zoo.cfg
Mode: follower

使用java客户端连接ZooKeeper集群
找一台机器,解压zookeeper压缩包,不用配置,就可以使用java客户端连接ZooKeeper集群中的任意一台服务器了。
$ sh /mq/zookeeper/bin/zkCli.sh -server bjrenrui0001:2181
$ sh /mq/zookeeper/bin/zkCli.sh -server bjrenrui0002:2181
$ sh /mq/zookeeper/bin/zkCli.sh -server bjrenrui0003:2181
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades Sep 12, 2024 pm 12:23 PM

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

Samsung Galaxy S25 Ultra leaks in first render images with rumoured design changes revealed Samsung Galaxy S25 Ultra leaks in first render images with rumoured design changes revealed Sep 11, 2024 am 06:37 AM

OnLeaks has now partnered with Android Headlines to provide a first look at the Galaxy S25 Ultra, a few days after a failed attempt to generate upwards of $4,000 from his X (formerly Twitter) followers. For context, the render images embedded below h

IFA 2024 | TCL\'s NXTPAPER 14 won\'t match the Galaxy Tab S10 Ultra in performance, but it nearly matches it in size IFA 2024 | TCL\'s NXTPAPER 14 won\'t match the Galaxy Tab S10 Ultra in performance, but it nearly matches it in size Sep 07, 2024 am 06:35 AM

Alongside announcing two new smartphones, TCL has also announced a new Android tablet called the NXTPAPER 14, and its massive screen size is one of its selling points. The NXTPAPER 14 features version 3.0 of TCL's signature brand of matte LCD panels

Vivo Y300 Pro packs 6,500 mAh battery in a slim 7.69 mm body Vivo Y300 Pro packs 6,500 mAh battery in a slim 7.69 mm body Sep 07, 2024 am 06:39 AM

The Vivo Y300 Pro just got fully revealed, and it's one of the slimmest mid-range Android phones with a large battery. To be exact, the smartphone is only 7.69 mm thick but features a 6,500 mAh battery. This is the same capacity as the recently launc

Samsung Galaxy S24 FE billed to launch for less than expected in four colours and two memory options Samsung Galaxy S24 FE billed to launch for less than expected in four colours and two memory options Sep 12, 2024 pm 09:21 PM

Samsung has not offered any hints yet about when it will update its Fan Edition (FE) smartphone series. As it stands, the Galaxy S23 FE remains the company's most recent edition, having been presented at the start of October 2023. However, plenty of

New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades Sep 12, 2024 pm 12:22 PM

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

Xiaomi Redmi Note 14 Pro Plus arrives as first Qualcomm Snapdragon 7s Gen 3 smartphone with Light Hunter 800 camera Xiaomi Redmi Note 14 Pro Plus arrives as first Qualcomm Snapdragon 7s Gen 3 smartphone with Light Hunter 800 camera Sep 27, 2024 am 06:23 AM

The Redmi Note 14 Pro Plus is now official as a direct successor to last year'sRedmi Note 13 Pro Plus(curr. $375 on Amazon). As expected, the Redmi Note 14 Pro Plus heads up the Redmi Note 14 series alongside theRedmi Note 14and Redmi Note 14 Pro. Li

Motorola Razr 50s shows itself as possible new budget foldable in early leak Motorola Razr 50s shows itself as possible new budget foldable in early leak Sep 07, 2024 am 09:35 AM

Motorola has released countless devices this year, although only two of them are foldables. For context, while most of the world has received the pair as the Razr 50 and Razr 50 Ultra, Motorola offers them in North America as the Razr 2024 and Razr 2

See all articles