zookeeper依赖于jdk,请自行安装
1.下载安装包
1)进入安装目录
cd /home/install/
2)获取下载地址
打开下载网址:https://archive.apache.org/dist/zookeeper/zookeeper-3.6.1/
选择第一个包,然后右键复制链接地址。
3)下载
执行wget+复制的链接地址下载安装包
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.6.1/apache-zookeeper-3.6.1-bin.tar.gz
2.安装
1)创建和解压至安装目录
mkdir /usr/local/zookeeper
tar -xvf /home/install/apache-zookeeper-3.6.1-bin.tar.gz -C /usr/local/zookeeper/
2)拷贝样本配置为主配置
进入配置目录,赋值拷贝样本文件
cd /usr/local/zookeeper/apache-zookeeper-3.6.1/conf/
cp zoo_sample.cfg zoo.cfg
3)修改配置
创建数据存储目录与日志目录
mkdir /usr/local/zookeeper/apache-zookeeper-3.6.1/dataDir
mkdir /usr/local/zookeeper/apache-zookeeper-3.6.1/dataLogDir
修改数据存储和日志目录
vim /usr/local/zookeeper/apache-zookeeper-3.6.1/conf/zoo.cfg
3.配置zookeeper环境变量
1)依赖JVM环境,所以JVM与zookeeper环境变量都要配置
vim /etc/profile
在尾部加入或修改以下
ZOOKEEPER_HOME=/usr/local/zookeeper/apache-zookeeper-3.6.1
PATH=$PATH:$ZOOKEEPER_HOME/bin
export PATH ZOOKEEPER_HOME PATH
2)生效
source /etc/profile
4.测试
1)启动
/usr/local/zookeeper/apache-zookeeper-3.6.1/bin/zkServer.sh start
2)连接
/usr/local/zookeeper/apache-zookeeper-3.6.1/bin/zkCli.sh
3)增删改查
5.开机启动
(1)编辑zookeeper.service文件
vim /usr/lib/systemd/system/zookeeper.service
加入如下内容
[Unit]
Description=zookeeper
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/zookeeper/apache-zookeeper-3.6.1/bin/zkServer.sh start
ExecReload=/usr/local/zookeeper/apache-zookeeper-3.6.1/bin/zkServer.sh restart
ExecStop=/usr/local/zookeeper/apache-zookeeper-3.6.1/bin/zkServer.sh stop
[Install]
WantedBy=multi-user.target
(2)生效
systemctl daemon-reload
(3)改变文件权限
chmod 777 /usr/lib/systemd/system/zookeeper.service
(4)systemctl开机启动zookeeper
systemctl enable /usr/lib/systemd/system/zookeeper.service
或
systemctl enable /usr/lib/systemd/system/zookeeper
(5)查看是否开机启动
systemctl is-enabled zookeeper.service
(6)systemctl取消开机启动
systemctl disable zookeeper.service