ZooKeeper单节点搭建

Zookeeper运行需要java环境,需要安装jdk。

text

yum install java-1.8.0-openjdk
yum install java-1.8.0-openjdk-devel

shell

wget https://www.apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz

bash

tar zxf zookeeper-3.4.14.tar.gz

将解压文件夹移动至/usr/local/zookeeper

自己想放哪放哪

shell

mv zookeeper-3.4.14 /usr/local/zookeeper

进入zookeeper的conf目录下,找到zoo_sample.cfg文件。将zoo_sample.cfg文件备份,并重命名为zoo.cfg。修改配置

text

clientPort=2181
dataLogDir=/usr/local/zookeeper/logs
dataDir=/usr/local/zookeeper/data
tickTime=2000
initLimit=5
syncLimit=2
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=60

修改一下zkEnv.sh脚本,zk启动后会有一个zookeeper.out文件,这个文件随着时间会越来越大,默认会在执行zkServer.sh的位置生成,所以我们要修改为指定路径。

shell

if [ "x${ZOO_LOG_DIR}" = "x" ]
then
    ZOO_LOG_DIR="$ZOOBINDIR/../log"
fi

进入bin目录,执行启动命令

bash

sh zkServer.sh start

ZooKeeper JMX enabled by default
Using config: /usr/zookeeper/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

Zookeeper启动完成。

bash

vi /usr/lib/systemd/system/zookeeper.service

text

[Unit]
Description=Zookeeper Service
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/local/java/
ExecStart=/usr/local/zookeeper/bin/zkServer.sh start
ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop
ExecReload=/usr/local/zookeeper/bin/zkServer.sh restart
PIDFile=/tmp/zookeeper/zookeeper_server.pid
[Install]
WantedBy=multi-user.target

相关内容