怎么在linux上安装zookeeper

怎么在linux上安装zookeeper,第1张

Zookeeper是一个协调服务,可以用它来作为配置维护、名字服务、分布式部署;

下面,我来分享一下在Linux下安装Zookeeper的整个步骤,让大家少走弯路。

一、Zookeeper下载

[plain] view plain copy print?

[root@localhost 下载]# wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz  

--2016-01-15 23:15:57--  http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz  

正在解析主机 mirror.bit.edu.cn (mirror.bit.edu.cn)... 114.247.56.117

正在连接 mirror.bit.edu.cn (mirror.bit.edu.cn)|114.247.56.117|:80... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:11833706 (11M) [application/octet-stream]

正在保存至: “zookeeper-3.3.6.tar.gz”

100%[======================================================================================================================================================================================>] 11,833,706   171KB/s 用时 68s

2016-01-15 23:17:07 (170 KB/s) - 已保存 “zookeeper-3.3.6.tar.gz” [11833706/11833706])

二、解压

[html] view plain copy print?

[root@localhost deploy]# tar -zxvf /home/lk/下载/zookeeper-3.3.6.tar.gz

解压完之后,会在deploy文件夹下面得到一个zookeeper-3.3.6的文件夹

三、进入到conf目录

[plain] view plain copy print?

[root@localhost deploy]# cd /opt/deploy/zookeeper-3.3.6/conf

四、拷贝zoo_samle.cfg为zoo.cfg

[plain] view plain copy print?

[root@localhost conf]# cp zoo_sample.cfg zoo.cfg

五、编辑zoo.cfg文件

[plain] view plain copy print?

[root@localhost conf]# vi zoo.cfg

修改为:

[html] view plain copy print?

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

dataDir=/usr/zookeeper

dataLogDir=/usr/zookeeper/log

# the port at which the clients will connect

clientPort=2181

server.1=192.168.32.129:2888:3888

六、设置环境变量

[plain] view plain copy print?

[root@localhost conf]# export ZOOKEEPER_INSTALL=/opt/deploy/zookeeper-3.3.6

[root@localhost conf]# export PATH=$PATH:$ZOOKEEPER_INSTALL/bin

七、启动

[plain] view plain copy print?

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

JMX enabled by default

Using config: /opt/deploy/zookeeper-3.3.6/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

[root@localhost bin]#

八、测试zookeeper

[plain] view plain copy print?

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

如果是本地连接,那么不需要 -server 192.168.32.129:2181,默认是本地

注意:如果出现拒绝连接,请检查如下:

1、防火墙是否关闭  systemctl stop firewalld

2、需要将192.168.32.129 映射到本地 /etc/hosts文件中,否则无法连接

解压zooke压缩包,并将conf文件夹下面的zoo_sample.cfg复制并改名为zoo.cfg

修改配置文件

配置环境变量

服务启动、客户端连接

删除缓存的version-2文件夹其实就是删除了已经create的节点,重启zookeeper就可以解决报错。

在每次新建一个节点时,一定要判断该节点(路径)是否存在,因为在ZooKeeper中路径使唯一的,所以当在该路径下已有节点时,继续往当前路径上新建节点就会报这个错。

在dataDir目录下创建myid并设置编号

A代表第几号服务器、B代表服务IP地址、C是服务器与集群Leader服务器交互数据的端口、D是万一集群的Leader服务器挂了,需要一个端口来重新进行选举。

查看zookeeper状态

如何启动zookeeper-3.3.6?

启动zookeeper-3.3.6的方法:下载安装配置zookeeper的服务器环境-创建文件-设置权限-编辑-重启即可。

具体步骤:

一、登陆linux服务器用cd 命令切换到/etc/rc.d/init.d/目录下。

二、touch zookeeper创建一个文件。

三、为文件添加可执行权限chmod +x zookeeper。

四、用vi zookeeper来编辑这个文件。

五、在zookeeper里面输入如下内容。

六、保存退出。

七、用service zookeeper start/stop来启动停止zookeeper服务。

八、使用chkconfig --add zookeeper命令吧zookeeper添加到开机启动里面。

九、使用chkconfig --list 来看看添加的zookeeper是否在里面。

十、重启即可。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/7205134.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-02
下一篇2023-04-02

发表评论

登录后才能评论

评论列表(0条)

    保存