CentOS 7 安装 Zookeeper

zookeeper安装先需要jdk环境

zk下载地址:http://mirror.bit.edu.cn/apache/zookeeper/

wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.6.1/apache-zookeeper-3.6.1-bin.tar.gz
tar xvzf apache-zookeeper-3.6.1-bin.tar.gz
mv apache-zookeeper-3.6.1-bin /usr/local/zookeeper
cp /usr/local/zookeeper/conf/zoo_sample.cfg /usr/local/zookeeper/conf/zoo.cfg

mkdir /usr/local/zookeeper/data
mkdir /usr/local/zookeeper/logs
vi /usr/local/zookeeper/conf/zoo.cfg
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/logs

启动:
/usr/local/zookeeper/bin/zkServer.sh start

查看状态
/usr/local/zookeeper/bin/zkServer.sh status

查看已启动的zookeeper服务:
/usr/local/zookeeper/bin/zkCli.sh

iptables -I INPUT -p tcp --dport 2181 -j ACCEPT
service iptables save
添加自动启动
vi /lib/systemd/system/zookeeper.service
[Unit]
Description=ZooKeeper Service
After=network.target
After=syslog.target

[Service]
Type=forking
Environment=ZOO_LOG_DIR=/usr/local/zookeeper/logs
Environment=PATH=/usr/local/jdk1.8.0_261/bin:/usr/local/jdk1.8.0_261/jre/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/bin
User=root
Group=root
ExecStart=/usr/local/zookeeper/bin/zkServer.sh start /usr/local/zookeeper/conf/zoo.cfg
ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop /usr/local/zookeeper/conf/zoo.cfg
ExecReload=/usr/local/zookeeper/bin/zkServer.sh restart /usr/local/zookeeper/conf/zoo.cfg
Restart=on-failure

[Install]
WantedBy=multi-user.target


systemctl daemon-reload
systemctl start zookeeper
systemctl status zookeeper
systemctl enable zookeeper
启动时失败,log:
java.io.IOException: Failed to bind to /0.0.0.0:8080
解决:
vi /usr/local/zookeeper/conf/zoo.cfg
admin.serverPort=8081