RHEL7安装部署ZooKeeper

时间:2022-02-06 08:27:32

转载请注明出处:jiq•钦's technical Blog - 季义钦

 

文章说明:

分布式注册中心(链接)需要安装的组件包含两个部分:

1、注册中心服务(Zookeeper)

2、网站(Tomcat服务器) 

此文档摘自分布式注册中心安装部署的Part-1


安装环境:

[root@localhost etc]# cat/etc/redhat-release

RedHat Enterprise Linux Server release 7.0 (Maipo)

[root@localhost etc]# uname -a

Linuxlocalhost.localdomain 3.10.0-123.el7.x86_64 #1 SMP Mon May 5 11:16:57 EDT 2014x86_64 x86_64 x86_64 GNU/Linux

[root@localhost etc]#

备注:CentOS预计也一样


一、安装JDK

Tomcat服务器的运行和Zookeeper服务的运行都依赖于JRE。

 

二、安装Zookeeper

步骤1:解压

[root@localhost uRegister]# tar –zxvf  zookeeper-3.4.8.tar.gz

 

步骤2:创建数据和日志存放目录

[root@localhost uRegister]# mkdir zkData zkLog

 

步骤3:创建/uRegister/zookeeper-3.4.8/conf/zoo.cfg配置文件

[root@localhost conf]#touch zoo.cfg

内容如下:

dataDir=/uRegister/zkData

dataLogDir=/uRegister/zkLog

clientPort=2181

tickTime=2000


步骤4:打开防火墙端口

[root@localhost bin]# firewall-cmd --add-port=2181/tcp --permanent

success

[root@localhost bin]# firewall-cmd --reload

success 

 

步骤5:启动

启动Zookeeper服务命令:

[root@localhost bin]# ./zkServer.sh start

ZooKeeper JMX enabled by default

Using config:/uRegister/zookeeper-3.4.8/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

 

用jps名录看Zookeeper服务QuorumPeerMain是否在运行:

[root@localhost bin]# jps

13103 Jps

13065 QuorumPeerMain

10899 Bootstrap

 

还可以查看Zookeeper服务运行状态:

[root@localhost bin]# ./zkServer.sh status

ZooKeeper JMX enabled by default

Using config:/uRegister/zookeeper-3.4.8/bin/../conf/zoo.cfg

Mode: standalone

 

停止Zookeeper服务的命令是:

[root@localhost bin]# ./zkServer.sh stop

ZooKeeper JMX enabled by default

Using config: /uRegister/zookeeper-3.4.8/bin/../conf/zoo.cfg

Stopping zookeeper ... STOPPED

[root@localhost bin]#


步骤6:测试连接:

[root@localhost bin]# ./zkCli.sh -server 192.104.103.170:2181

Connecting to 192.104.103.170:2181

2016-03-24 09:27:26,562 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.8--1,built on 02/06/2016 03:18 GMT

2016-03-24 09:27:26,565 [myid:] - INFO [main:Environment@100] - Client environment:host.name=localhost

2016-03-24 09:27:26,565 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.7.0_51

2016-03-24 09:27:26,568 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=OracleCorporation

2016-03-24 09:27:26,568 [myid:] - INFO [main:Environment@100] - Clientenvironment:java.home=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.51-2.4.5.5.el7.x86_64/jre

2016-03-24 09:27:26,568 [myid:] - INFO [main:Environment@100] - Clientenvironment:java.class.path=/uRegister/zookeeper-3.4.8/bin/../build/classes:/uRegister/zookeeper-3.4.8/bin/../build/lib/*.jar:/uRegister/zookeeper-3.4.8/bin/../lib/slf4j-log4j12-1.6.1.jar:/uRegister/zookeeper-3.4.8/bin/../lib/slf4j-api-1.6.1.jar:/uRegister/zookeeper-3.4.8/bin/../lib/netty-3.7.0.Final.jar:/uRegister/zookeeper-3.4.8/bin/../lib/log4j-1.2.16.jar:/uRegister/zookeeper-3.4.8/bin/../lib/jline-0.9.94.jar:/uRegister/zookeeper-3.4.8/bin/../zookeeper-3.4.8.jar:/uRegister/zookeeper-3.4.8/bin/../src/java/lib/*.jar:/uRegister/zookeeper-3.4.8/bin/../conf:

2016-03-24 09:27:26,568 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

2016-03-24 09:27:26,568 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp

2016-03-24 09:27:26,569 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>

2016-03-24 09:27:26,569 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux

2016-03-24 09:27:26,569 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64

2016-03-24 09:27:26,569 [myid:] - INFO [main:Environment@100] - Clientenvironment:os.version=3.10.0-123.el7.x86_64

2016-03-24 09:27:26,569 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root

2016-03-24 09:27:26,569 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root

2016-03-24 09:27:26,569 [myid:] - INFO [main:Environment@100] - Clientenvironment:user.dir=/uRegister/zookeeper-3.4.8/bin

2016-03-24 09:27:26,571 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=192.104.103.170:2181sessionTimeout=30000watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@511bfc28

Welcome to ZooKeeper!

2016-03-24 09:27:26,604 [myid:] - INFO [main-SendThread(192.104.103.170:2181):ClientCnxn$SendThread@1032] -Opening socket connection to server 192.104.103.170/192.104.103.170:2181. Willnot attempt to authenticate using SASL (unknown error)

2016-03-24 09:27:26,614 [myid:] - INFO [main-SendThread(192.104.103.170:2181):ClientCnxn$SendThread@876] -Socket connection established to 192.104.103.170/192.104.103.170:2181,initiating session

JLine support is enabled

2016-03-24 09:27:26,638 [myid:] - INFO [main-SendThread(192.104.103.170:2181):ClientCnxn$SendThread@1299] -Session establishment complete on server 192.104.103.170/192.104.103.170:2181,sessionid = 0x153a639b4560000, negotiated timeout = 30000

 

WATCHER::

 

WatchedEvent state:SyncConnected type:None path:null

[zk: 192.104.103.170:2181(CONNECTED) 0] ls /

[zookeeper]

[zk: 192.104.103.170:2181(CONNECTED) 1]