1. 程式人生 > >Linux下安裝ZooKeeper並且配置為開機啟動

Linux下安裝ZooKeeper並且配置為開機啟動

1.官網下載地址

2. 安裝

  • 建立資料及日誌目錄
cd zookeeper-3.5.2-alpha/
mkdir data
mkdir logs
  • 建立配置檔案
cd zookeeper-3.5.2-alpha/conf/
cp zoo_sample.cfg  zoo.cfg #拷貝配置檔案並改名為zoo.cfg
  • 修改zoo.cfg配置
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/zookeeper-3.5.2-alpha/data
dataLogDir=/opt/zookeeper-3.5.2-alpha/logs
clientPort=2181
  • 配置環境變數
 # 開啟環境配置
vim /etc/profile
 # 增加如下配置
export ZOOKEEPER_HOME=/opt/zookeeper-3.5.2-alpha
export PATH=$ZOOKEEPER_HOME/bin:$PATH
 # 生效配置
source /etc/profile

3.服務配置

  • cd /etc/init.d/目錄下,建立zookeeper檔案
vim zookeeper
  • 指令碼內容
#!/bin/bash

export JAVA_HOME=/opt/jdk1.8.0_111
export
PATH=$JAVA_HOME/bin:$PATH #chkconfig:2345 20 90 #description:zookeeper #processname:zookeeper case $1 in start) su root /opt/zookeeper-3.5.2-alpha/bin/zkServer.sh start;; stop) su root /opt/zookeeper-3.5.2-alpha/bin/zkServer.sh stop;; status) su root /opt/zookeeper-3.5.2-alpha/bin/zkServer.sh status;; restart) su root /opt/zookeeper-3.5
.2-alpha/bin/zkServer.sh restart;; *) echo "require start|stop|status|restart" ;; esac
  • 新增許可權
chmod +x zookeeper
  • 配置成服務
chkconfig --add zookeeper
  • 開機啟動
chkconfig zookeeper on
  • 啟動
service zookeeper start
  • 停止
service zookeeper stop
  • 重啟
service zookeeper restart
  • 狀態
service zookeeper status