- 下载zookeeper
https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
- 创建目录
[root@localhost /]# cd /
[root@localhost /]# mkdir soft
- 把文件上传到服务器然后解压
[root@localhost soft]# ls
zookeeper-3.4.14.tar.gz
[root@localhost soft]# tar zookeeper-3.4.14.tar.gz
- 移动到/usr/local目录下
[root@localhost soft]# mv zookeeper-3.4.14.tar.gz /usr/local/zookeeper/
- 创建数据目录
[root@localhost zookeeper]# cd /usr/local/zookeeper
[root@localhost zookeeper]# mkdir data
- 配置zoo.cfg
[root@localhost zookeeper]# cd conf
[root@localhost conf]# cp zoo_sample.cfg zoo.cfg
[root@localhost conf]# vi zoo.cfg
它默认的配置文件是zoo_sample.cfg,你得复制一份并且命名为zoo.cfg,我们在zoo.cfg里面修改配置即可
先把dataDir=/tmp/zookeeper注释,然后将下面两行代码添加到文件末尾,我这里一台机器所以只配server.1
dataDir=/usr/local/zookeeper/data
server.1=localhost:2888:3888
客户端连接默认端口为2181
- 创建myid文件
[root@localhost conf]# cd ../data
[root@localhost data]# touch myid
[root@localhost data]# echo "1">>myid
=====================================多台服务配置 start============================================
如果你是配置安装多台机器,那zoo.cfg的配置就是:
dataDir=/usr/local/zookeeper/data
server.1=192.168.1.91:2888:3888
server.2=192.168.1.92:2888:3888
server.3=192.168.1.93:2888:3888
再拷贝zookeeper到另外两台机器
[root@localhost data]# scp -r /usr/local/zookeeper root@192.168.1.92:/usr/local/
[root@localhost data]# scp -r /usr/local/zookeeper root@192.168.1.93:/usr/local/
中间会要求输入密码,分别输入你另外两台机器的密码就行了
修改myid文件
192.168.1.92的myid内容改为2
[root@localhost zookeeper]# cd /usr/local/zookeeper/data
[root@localhost data]# echo "2">myid
192.168.1.93的myid内容改为3
[root@localhost zookeeper]# cd /usr/local/zookeeper/data
[root@localhost data]# echo "3">myid
=====================================多台服务配置 end============================================
- 开启2888、3888、2181端口
[root@localhost data]# firewall-cmd --zone=public --add-port=2888/tcp --permanent
[root@localhost data]# firewall-cmd --zone=public --add-port=3888/tcp --permanent
[root@localhost data]# firewall-cmd --zone=public --add-port=2181/tcp --permanent
- 重启防火墙
[root@localhost data]# firewall-cmd --reload
- 启动
[root@localhost bin]# /usr/local/zookeeper/bin/zkServer.sh start
如果输出以下内容,表示启动成功
ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
查看状态
[root@localhost data]# /usr/local/zookeeper/bin/zkServer.sh status
如果你是启动多台服务,其中一台服务会被自动选举为leader了
- 客户端连接
[root@localhost zookeeper]# /usr/local/zookeeper/bin/zkCli.sh -server localhost:2181
推荐文章