ZooKeeper单节点搭建
目录
Zookeeper运行需要java环境,需要安装jdk。
0.1 安装openjdk
yum install java-1.8.0-openjdk
yum install java-1.8.0-openjdk-devel
0.2 下载最新稳定版的 Zookeeper
wget https://www.apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
0.3 解压
tar zxf zookeeper-3.4.14.tar.gz
将解压文件夹移动至/usr/local/zookeeper
自己想放哪放哪
mv zookeeper-3.4.14 /usr/local/zookeeper
0.4 配置
进入zookeeper的conf目录下,找到zoo_sample.cfg
文件。将zoo_sample.cfg
文件备份,并重命名为zoo.cfg。修改配置
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
的位置生成,所以我们要修改为指定路径。
if [ "x${ZOO_LOG_DIR}" = "x" ]
then
ZOO_LOG_DIR="$ZOOBINDIR/../log"
fi
0.5 启动
进入bin目录,执行启动命令
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启动完成。
0.6 添加到systemctl
vi /usr/lib/systemd/system/zookeeper.service
[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