1. 程式人生 > >zookeeper怎麼用ssh指令碼啟動

zookeeper怎麼用ssh指令碼啟動

使用shell指令碼啟動zookeeper

步驟:

採用shell指令碼啟動zookeeper,首先新建檔案start.sh
寫入內容(rh1 rh2 rh3 分別是主機名。此處需要ssh):#!/bin/sh
echo “start zkServer…”
for i in rh1 rh2 rh3
do
ssh $i “/usr/local/zookeeper3.4/bin/zkServer.sh start”
done
寫好後儲存,加上執行許可權:chmod u+x start.sh
執行:./start.sh看見啟動成功了,有輸出。但是輸入jps檢視的時候,會發現沒有QuorumPeerMain 程序。說明沒有啟動成功。

分析原因

首先知道互動式shell和非互動式shell、登入shell和非登入shell是有區別的
在登入shell裡,環境資訊需要讀取/etc/profile和~ /.bash_profile, ~/.bash_login, and ~/.profile按順序最先的一個,並執行其中的命令。除非被 —noprofile選項禁止了;在非登入shell裡,環境資訊只讀取 /etc/bash.bashrc和~/.bashrc
手工執行是屬於登陸shell,指令碼執行資料非登陸shell,而我的linux環境配置中只對/etc/profile進行了jdk1.6等環境的配
置,所以指令碼執行/usr/local/zookeeper3.4/bin/zkServer.sh start 啟動zookeeper失敗了

解決方法

把profile的配置資訊echo到.bashrc中 cat /etc/profile >> ~/.bashrc
在/zookeeper/bin/zkEnv.sh的中開始位置新增 export JAVA_HOME=/usr/local/jdk1.6(就像hadoop中對hadoop-env.sh的配置一樣)

採用
shell指令碼
啟動zookeeper,首先新建檔案start.sh
寫入內容(rh1 rh2 rh3 分別是主機名。此處需要ssh):#!/bin/sh
echo “start zkServer就可以了。