分布式系統方案中,集群主機數量到達一定程度後,如果還是單獨的乙個乙個遠端登陸配置會變得十分棘手。推薦兩種方案:1.使用clustershell軟體配置分組,只需要在一台主機上統一的傳送指令,其他主機都會執行,十分便捷。2.有時候啟動的命令列一大堆,可以自己寫shell去管理所有集群機子上。1.首先建立自定義的指令碼script.s**件
vim /home/script.sh
2.編寫指令碼內容
wq!儲存後,賦予可執行許可權:輸入#!/bin/bash
echo "hello shell!"
chmod +x /home/script.sh
再次檢視script.sh 就會變成深色,代表這是可執行的
示例編寫zookeeper啟動shell
解釋:#!/bin/bash
#在 /etc/hosts加入對於集群的host ip,shell中小**包裹代表陣列,陣列元素之間用空格分開
host=
(storm1 storm2 storm3 storm4 storm5)
#echo 輸出執行的資訊
echo
"start zookeeper"
#for 迴圈遍歷執行所有的集群主機
for i in$do
#需要配置ssh免密登入
ssh$
"source /etc/profile;cd /tmp/zookeeper/datalog/&&nohup zkserver.sh start >/dev/null 2>&1 &"
#如果某一台需要單獨啟動點東西,可以通過if then 去處理
if(($i==0))
;then
echo
"第乙個與眾不同"
fi#if的end標準為 fi
#echo "i=$i host[$i]=$"
#for迴圈的結束標誌為done
done
示例編寫kafka啟動shell
示例編寫storm啟動shell#!/bin/bash
host=
(storm1 storm2 storm3 storm4 storm5)
#在 /etc/hosts加入對於集群的host ip
echo
"start kafka"
for i in$do
#這裡沒有用到環境變數,應為kafka預設配置下需要指定server.properties的路徑path=/home/storm$[$i+1]/distribute/kafka
echo
"nohup $path/bin/kafka-server-start.sh -daemon $path/config/server.properties >/dev/null 2>&1 &"
ssh$
"nohup $path/bin/kafka-server-start.sh -daemon $path/config/server.properties >/dev/null 2>&1 &"
#echo "i=$i host[$i]=$"
done
這裡需要第乙個主機為nimbus並且啟動ui則只需要加個判斷即可。#!/bin/bash
host=
(storm1 storm2 storm3 storm4 storm5)
echo
"start storm"
for i in$do
ssh$
"source /etc/profile;nohup storm supervisor >/tmp/storm/storm.log 2>&1 &"
ssh$
"source /etc/profile;nohup storm lo**iewer >/tmp/storm/storm.log 2>&1 &"
if(($i==0))
;then
echo
"start nimbus……"
ssh$
"source /etc/profile;nohup storm nimbus >/tmp/storm/storm.log 2>&1 &"
echo
"start storm ui"
ssh$
"source /etc/profile;nohup storm ui >/tmp/storm/storm.log 2>&1 &"
fi#echo "i=$i host[$i]=$"
done
編寫Linux的shell指令碼
把一些有關聯的linux命令,或者一組完成某一特定功能的linux命令,存放在了乙個檔案中,把這個檔案稱之為shell指令碼,該指令碼真正被稱之為shell指令碼,需要具備這麼幾個特點 需要能夠被bash能夠執行,就相當於在windows的可執行檔案.exe 需要為該指令碼提供乙個標識 在檔案的開頭...
linux 簡單shell指令碼編寫
前幾天學習了一些shell指令碼編寫,今天把它記下來。下面的指令碼是修改電腦的ip位址 子網掩碼 閘道器。bin bash 這句話是指定指令碼的直譯器是bash read p please input ipaddr ip read p這個語句就是通過鍵盤讓自己輸入要輸入的內容 read p plea...
shell編寫總結
有時需要在乙個字串變數中定義乙個命令並預先包含乙個變數名,在使用時再轉換成變數名,此時可通過eval命令來達到目的.cmd eval echo value value hello cmd 執行echo hello 輸出 hello shell指令碼開發中,輸出的語句盡量不出現在標準輸出,除非是少數的...