Linux安装Zookeeper

4,732 阅读2分钟

Zookeeper可以作为分布式集群开发,本文是基于Centos7环境下安装的Zookeeper,具体步骤如下文所示:

(1)下载Zookeeper,这里下载的是zookeeper-3.4.10.tar.gz,可以使用Linux的wget命令,也可以下载好安装包,将其上传至Linux环境中;下载的网址为:

http://apache.fayea.com/zookeeper/

(2)将其解压到/usr/local路径下,解压的命令如下:

tar -zxvf zookeeper-3.4.10.tar.gz

(3)配置环境变量:使用命令

vi /etc/profile

查看profile文件的内容,在内容中添加如下语句:

在文件末尾添加此段内容: -- 开始和--中间的一段.(注意,尽量保持环境变量名全大写,下划线隔开. 保持规范) -- 开始

export ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.10
export PATH=$PATH:$ZOOKEEPER_HOME/bin

-- 结束

(4)进入到zookeeper-3.4.10的conf文件夹下,使用如下命令:

cd /usr/local/zookeeper-3.4.10/conf/

(5)将zoo.sample.cfg拷贝出一份出来,将文件名强制zoo.cfg,使用如下命令:

cp zoo_sample.cfg zoo.cfg

(6)使用如下命令对zoo.cfg文件内容进行编辑,

vi zoo.cfg 

-- 按i进入编辑模式. 修改完成之后, esc退出编辑模式, 大写字母Z双击即可保存.

在其后面添加zookeeper的文件路径和日志路径,其内容如下:

#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=/tmp/zookeeper -- 这里要设置一下文件路径 路径必须存在,不存在的话就新建一个呗

dataLogDir=/tmp/zookeeper/log -- 日志路径 路径必须存在,不存在的话就新建一个呗

#the port at which the clients will connect

clientPort=2181 -- 如果是多机器的话,在clientPort处添加服务器的ip

#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.

#zookeeper.apache.org/doc/current…

#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

(7)进入到zookeeper的bin目录下,

cd /usr/local/zookeeper-3.4.10/bin/

(8)启动zookeeper的命令为:

./zkServer.sh start

如果成功,显示的内容如下:

JMX enabled by default Using config: /usr/local/zookeeper-3.4.10/bin/../conf/zoo.cfg Starting zookeeper ... STARTED

(9)查看zookeeper的状态,检测其是否启动,使用如下命令:

./zkServer.sh status

输出的内容如下: JMX enabled by default Using config: /usr/local/zookeeper-3.4.10/bin/../conf/zoo.cfg Mode: standalone (10)停止zookeeper的话,在bin目录下,运行如下命令:

./zkServer.sh stop

停止运行zookeeper; 本文到此,zookeeper的安装就算结束了。 如果本文侵权,请联系作者删除