zookeeper集群搭建
备注: 最少三个节点,建议单数个节点,以3.4.8版本为例,依赖java环境
- 配置主机名和IP映射(nameserver)
vim /etc/hosts
添加以下配置信息:192.168.58.145 zookeeper145 192.168.58.146 zookeeper146 192.168.58.147 zookeeper147
source /etc/hosts
刷新配置 - 下载
zookeeper
安装包zookeeper-3.4.8.tar.gz
- 解压
tar -zxvf zookeeper-3.4.8.tar.gz -C /usr/local && cd .. && mv zookeeper-3.4.8 zookeeper && cd zookeeper
- 配置环境变量
vim /etc/profile
添加配置如下:export PATH=$PATH:/usr/local/bin export JAVA_HOME=/usr/java/jdk1.7.0_79 export CLASSPATH=.:%JAVA_HOME%/lib/dt.jar:%JAVA_HOME%/lib/tools.jar export ZOOKEEPER_HOME=/usr/local/zookeeper export PATH=$PATH:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin
source /etc/profile
- 修改
zookeeper
配置文件cd /usr/local/zookeeper/conf && mv zoo_sample.cfg zoo.cfg && vim zoo.cfg
修改数据存放地址dataDir=/usr/local/zookeeper/data
添加配置信息如下:server.0=zookeeper145:2888:3888 server.1=zookeeper146:2888:3888 server.2=zookeeper147:2888:3888
- 配置服务器标识
创建数据存放文件夹
data
,并data
下新建myid
服务器标识文件cd /usr/local/zookeeper && mkdir data && vim myid
配置内容:0 //该值对应着修改`zookeeper`配置文件`conf`中的`zoo.cfg`中的`server`后数值(每个节点对应)
- 每个节点重复以上方法配置
- 启动
zookeeper
cd /usr/local/zookeeper/bin
启动zkServer.sh start
(每个节点都需要启动)
状态zkServer.sh status
关闭zkServer.sh stop
- 进入
zookeeper
终端cd /usr/local/zookeeper/bin
zkCli.sh
即可进入终端
作者:逐暗者 (转载请注明出处)