0%

ZooKeeper单节点搭建

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

安装openjdk

1
2
yum install java-1.8.0-openjdk
yum install java-1.8.0-openjdk-devel

下载最新稳定版的 Zookeeper

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

解压

1
tar zxf zookeeper-3.4.14.tar.gz

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

自己想放哪放哪

1
mv zookeeper-3.4.14 /usr/local/zookeeper

配置

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

以下为默认配置,无需修改

1
2
3
4
5
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/tmp/zookeeper
clientPort=2181

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

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

启动

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

1
2
3
4
5
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启动完成。

添加到systemctl

1
vi /usr/lib/systemd/system/zookeeper.service
1
2
3
4
5
6
7
8
9
10
11
12
[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
-------------    本文结束  感谢您的阅读    -------------