Zookeeper單機版安裝
GitHub地址:https://github.com/RobertoHuang
-
下載
Zookeeper
-
解壓
Zookeeper
安裝包# tar -zxvf zookeeper-3.4.8.tar.gz
-
配置
Zookeeper
文件及日誌目錄-
創建保存文件及日誌的目錄
# mkdir data # mkdir logs
-
修改
Zookeeper
的配置文件-
將
zookeeper-3.4.8/conf
目錄下的zoo_sample.cfg
文件拷貝一份命名爲爲zoo.cfg
# cp zoo_sample.cfg zoo.cfg
-
編輯
zoo.cfg
將zookeeper
的dataDir
和dataLogDir
指向之前創建好的文件及日誌目錄# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/opt/zookeeper/data dataLogDir=/opt/zookeeper/logs # the port at which the clients will connect clientPort=2181 server.1=localhost:2888:3888
-
在
dataDir
下創建myid
文件(編輯myid
文件並在對應的IP
的機器上輸入對應的編號)# echo 1 > myid
-
-
-
添加
Zookeeper
環境變量配置(修改/etc/profile
添加如下配置),並使環境變量配置生效ZOOKEEPER_HOME=/opt/zookeeper/zookeeper-3.4.8 export PATH=$ZOOKEEPER_HOME/bin:$PATH
# source /etc/profile
-
啓動並測試
Zookeeper
# 啓動Zookeeper zkServer.sh start # 查看Zookeeper狀態 zkServer.sh status # 服務器輸出信息 tail -500f zookeeper.out # 停止zookeeper zkServer.sh stop
-
設置
Zookeeper
服務開機啓動-
在
/etc/rc.d/init.d
添加可執行文件zookeeper
# 切換到/etc/rc.d/init.d/目錄下 # cd /etc/rc.d/init.d # 創建zookeeper文件 # touch zookeeper # 將zookeeper修改爲可執行文件 # chmod +x zookeeper # 編輯文件,在zookeeper裏面輸入如下內容 #!/bin/bash #chkconfig:2345 20 90 #description:zookeeper #processname:zookeeper export JAVA_HOME=/opt/java/jdk1.8.0_91 export PATH=$JAVA_HOME/bin:$PATH case $1 in start) su root /opt/zookeeper/zookeeper-3.4.8/bin/zkServer.sh start;; stop) su root /opt/zookeeper/zookeeper-3.4.8/bin/zkServer.sh stop;; status) su root /opt/zookeeper/zookeeper-3.4.8/bin/zkServer.sh status;; restart) su root /opt/zookeeper/zookeeper-3.4.8/bin/zkServer.sh restart;; *) echo "require start|stop|status|restart";; esac
-
這個時候我們就可以用
service zookeeper start/stop
來啓動停止Zookeeper
服務了 -
使用命令把
zookeeper
添加到開機啓動任務中# chkconfig zookeeper on # chkconfig --add zookeeper
-
添加完成之後接這個使用
chkconfig --list
來看看我們添加的zookeeper
是否在裏面 -
如果上面的操作都正常的話,你就可以重啓你的
Linux
服務器了
-