如果要grep 一份文件裡面的字串,而這字串有包含tab這種分隔符號,
可以用[^I]來表示他
ex: 要查詢 doc.txt 中"I love you" (中間以tab分隔開) 這種字串
可用 $ cat doc.txt | grep 'I[^I]love[^I]you'
2014年10月31日 星期五
2014年10月12日 星期日
Put Data into Remote HBase by using Linux Bash Script
1. Start a TCP listening Server on 192.168.0.7:5002,
and cast received info to HBase Shell
start_colleciton.sh
while true;
do nc -l 192.168.0.7 5002
done | hbase shell
do nc -l 192.168.0.7 5002
done | hbase shell
[程式意義]
nc -l : 會在 IP:192.168.0.7 開啟一個 port:5002,來 listen 任何發送到此 port的TCP封包,
(若使用 nc -lu 則是 listen UDP 封包)
while true; ... do ... done : 因為TCP處理一次後就會關掉,必須加上此指令來持續接收,
| hbase shell : 將 nc 指令 listen到的訊息(HBase Shell Operations) 丟給 hbase shell做
--------------------------------------------------------------------------------------------------------------------
2. Send Info to Server
tcollector.sh
#!/bin/bash
set -e
while true;
do awk -v now=`date +%s` \
'{ print "put " $1", " now", " $2", " $3}' HBase_Info
sleep 15
done | nc -w 30 192.168.0.7 5002
set -e
while true;
do awk -v now=`date +%s` \
'{ print "put " $1", " now", " $2", " $3}' HBase_Info
sleep 15
done | nc -w 30 192.168.0.7 5002
[程式意義]
set -e : 檢查 pipe執行( | ) 如果其中有例外則結束整個 pipe
awk -v now=`date +%s` \
'{ print "put " $1", " now", " $2", " $3}' HBase_Info
- 設定變數 now 為現在時間(date+%s ==> 取到秒)
- 將HBase_Info 此檔案內容一行一行讀出,
第一欄為 $1= 'hiveTableonHB'
第二欄為 $2= 'cf:time'
第三欄為 $3= 'test'
nc -w 30 192.168.0.7 5002 : 將上述awk 指令中 print 的 內容傳送到 192.168.0.7:5002上
HBase_Info
'hiveTableonHB' 'cf:time' 'test'
--------------------------------------------------------------------------------------------------------------------
[RESULT]
1.8.7-p357 :004 > scan 'hiveTableonHB'
ROW COLUMN+CELL
1413177758 column=cf:time, timestamp=1413177976111, value=test
1413180302 column=cf:time, timestamp=1413180310949, value=test
1413180317 column=cf:time, timestamp=1413180324753, value=test
6 row(s) in 0.0270 seconds
2013年4月9日 星期二
ssh using sudo without password
[MOTIVATION]
Sometimes we want to use ssh command to remote machine for some operations,
but it's inconvenient that we need to key the password for "sudo" command.
Especially when we need to create a shell script. We can't key the password directly on it.
[METHOD]
Step:
1. On the remote machine, execute
$sudo visudo
and add following line at the end( Change "hadoop" to your username)
hadoop ALL=(ALL) NOPASSWD: ALL
and Ctrl + X to leave
type Y
press ENTER to save and leave
2. Return and try
$ ssh -t user@hostname "sudo ls"
for example
$ ssh -t hadoop@192.168.100.1 "sudo ls"
If you did it right, it just doesn't need to key the password again!
(And we could use it on shell script directly ~)
[note]
Why we use "-t" for ssh here is that it may cause:
sudo: no tty present and no askpass program specified
[REFERENCE]
http://jeromejaglale.com/doc/unix/ubuntu_sudo_without_password
http://superuser.com/questions/117870/ssh-execute-sudo-command
Sometimes we want to use ssh command to remote machine for some operations,
but it's inconvenient that we need to key the password for "sudo" command.
Especially when we need to create a shell script. We can't key the password directly on it.
[METHOD]
Step:
1. On the remote machine, execute
$sudo visudo
and add following line at the end( Change "hadoop" to your username)
hadoop ALL=(ALL) NOPASSWD: ALL
and Ctrl + X to leave
type Y
press ENTER to save and leave
2. Return and try
$ ssh -t user@hostname "sudo ls"
for example
$ ssh -t hadoop@192.168.100.1 "sudo ls"
If you did it right, it just doesn't need to key the password again!
(And we could use it on shell script directly ~)
[note]
Why we use "-t" for ssh here is that it may cause:
sudo: no tty present and no askpass program specified
[REFERENCE]
http://jeromejaglale.com/doc/unix/ubuntu_sudo_without_password
http://superuser.com/questions/117870/ssh-execute-sudo-command
2012年11月12日 星期一
Ubuntu 網路速度限制
當需要去限制Ubuntu的網路其 上傳/下載 的速度時
可透過 Wondershaper 這個工具
安裝:
sudo apt-get install wondershaper
使用:
sudo wondershaper [link type] [download speed(kbps)] [upload speed(kbps)]
ex:
sudo wondershaper eth0 512 64
這樣 eth0的網路連線 下載速度上限就為512Kbps 上傳速度上限為 64 Kbps
[Reference]
Wondershaper流量監控工具
[分享] 在面板顯示上傳下載流量 [論壇 - Ubuntu基本設定]
可透過 Wondershaper 這個工具
安裝:
sudo apt-get install wondershaper
使用:
sudo wondershaper [link type] [download speed(kbps)] [upload speed(kbps)]
ex:
sudo wondershaper eth0 512 64
這樣 eth0的網路連線 下載速度上限就為512Kbps 上傳速度上限為 64 Kbps
[Reference]
Wondershaper流量監控工具
[分享] 在面板顯示上傳下載流量 [論壇 - Ubuntu基本設定]
2012年6月10日 星期日
ignore the yes/no checking while ssh connect first time
[Problem]
當每回第一次連線到一個新的ip/host時總會產生以下的訊息:
此時就又必須在輸入一次" yes"才會完成連線
那假若不想輸入yes就直接連線進去可用以下方法
[Method]
在 ~/.ssh/ 中新創一份檔案叫 config
然後在config中加入
Host 192.168.1.1
儲存.
而之後若是第一次作ssh連線到192.168.1.1的host時,
就不會在出現以上的訊息, 也不用在輸入yes就可直接進入連線
[Note]
適用情況之一:
假設像是hadoop這種大規模數量的node建置時,
master必須先把authorized_keys scp給每個slave, 但手動每次的scp太花費時間,
當寫成shell script時又會卡在上述問題的詢問上,
此時就可先在master的~/.ssh/config 上利用Method加入所有slave
當每回第一次連線到一個新的ip/host時總會產生以下的訊息:
user@host:$ ssh 192.168.1.1
The authenticity of host '192.168.1.1 (192.168.1.1)' can't be established.
ECDSA key fingerprint is c7:16:8b:55:c8:39:24:5a:db:cd:e9:79:8c:24:59:39.
Are you sure you want to continue connecting (yes/no)?
The authenticity of host '192.168.1.1 (192.168.1.1)' can't be established.
ECDSA key fingerprint is c7:16:8b:55:c8:39:24:5a:db:cd:e9:79:8c:24:59:39.
Are you sure you want to continue connecting (yes/no)?
此時就又必須在輸入一次" yes"才會完成連線
那假若不想輸入yes就直接連線進去可用以下方法
[Method]
在 ~/.ssh/ 中新創一份檔案叫 config
然後在config中加入
Host 192.168.1.1
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null儲存.
而之後若是第一次作ssh連線到192.168.1.1的host時,
就不會在出現以上的訊息, 也不用在輸入yes就可直接進入連線
[Note]
適用情況之一:
假設像是hadoop這種大規模數量的node建置時,
master必須先把authorized_keys scp給每個slave, 但手動每次的scp太花費時間,
當寫成shell script時又會卡在上述問題的詢問上,
此時就可先在master的~/.ssh/config 上利用Method加入所有slave
2012年6月6日 星期三
VirtualBox install on ubuntu
VirualBox 要安裝在 ubuntu上非常簡單
[Version]
Ubuntu 12.04
VirtualBox
[Steps]
1. Download VirtualBox package
2. sudo apt-get install dkms
3. sudo dpkg -i VirtualBox-3.2_4.1.16_Ubuntu_karmic_i386.deb
4. 要開啟virtualbox也很簡單, 只要在terminal上執行 virtualbox
就會開啟圖形介面
[Reference]
https://www.virtualbox.org/manual/ch02.html#idp12629648
[Version]
Ubuntu 12.04
VirtualBox
[Steps]
1. Download VirtualBox package
2. sudo apt-get install dkms
3. sudo dpkg -i VirtualBox-3.2_4.1.16_Ubuntu_karmic_i386.deb
就會開啟圖形介面
[Reference]
https://www.virtualbox.org/manual/ch02.html#idp12629648
Virtualbox-Build multiple VMs cross mutiple physical servers
[Motivation]
當想模擬數十台甚至數百台VM所組成的cluster時, 單一實體server會受限於cpu數量以及memory大小, 而無法建立如此多台VM, 所以必須跨連到其他實體的servers, 此時VM又該如何佈署及設置網路?
[Virtual Machine]
本篇使用的是VirtualBox4.1版
[Physical Machine]
HP ProLiant DL380 G6 (2core, 20G mem, 500G hd ) X 3
各自OS為 Ubuntu 12.04
[Method]
1. Install virtualbox at each physical servers 在各個server上安裝virtualbox
參考:http://lifenote332.blogspot.tw/2012/06/virtualbox-install-on-ubuntu.html
2. Start Virtualbox and Create a new VM 新增一個新VM
a. 設定[名稱], 選擇[作業系統]及[版本]
(在此的名稱與VM內的OS完全沒關, 只是Virtualbox辨識用)
b. 設定[記憶體大小] (在這設1G)
c. 啟動硬碟-->選擇[新建硬碟]
d. 檔案類型-->選擇[VDI]
e. 存放裝置選擇詳細資料-->選擇[動態配置]
f. 虛擬磁碟檔案位置-->選擇(即將創造的vdi檔的存放位置), 大小-->選擇(在此設成50G)
g. 完成建立
3. Set two network interface cards for the VM 給予此VM兩張網卡
a. NAT(Network Address Translation):
概念:模擬自身就是本台實體server(Host OS), 以便對外連線, 但會使得實體server無法偵測到自己(此VM即Guest OS), 也因此無法連線到其他實體server上的VM
功用:便利此VM上網作些更新或下載的動作
b. Bridge
概念:模擬自身與本台實體server(Host OS)存在於同一個Hob or Router底下,使得實體server能偵測得到自己, 因此在其他實體server上的VM也同樣的設定下, 可偵測到彼此
功用:讓VM不僅可在本台實體server上互連, 也可與其他台實體server上的VM互連
4. Install OS and set network configuration on the VM 安裝OS及設定網路
a. 在此安裝linux OS(Ubuntu 11.10)
b. 網路設定的部份, 選擇[編輯連線], 因為先前給予了兩張網卡所以會有兩個連線, 而連線對映的設置應為:
I. 裝置的MAC Address : (eth0) 即為給予的NAT網卡 --> IPv4設定 :自動(DHCP)
II. 裝置的MAC Address : (eth1) 即為給予的Bridge網卡 --> IPv4設定 :手動(manual)
address : 192.168.X.X(X表示自行設置, 在此設成192.168.123.1)
mask: 255.255.X.X(在此設成255.255.255.0)
gateway: 192.168.X.254(在此設成192.168.123.254, 網路上似乎常用254)
DNS server: (同gateway)
a. 執行:vboxmanage clonvdi old.vdi new.vdi
便會產生新的vdi來開啟新的VM
b. 執行:vboxmanage internalcommands sethduuid new.vdi
因為有可能新舊兩個VM的uuid重複導致Virtualbox無法去開啟, 所以需在給new.vdi一個隨機的新uuid
a. 再次實行2. , 只是到2. c.時, 選擇[使用現有硬碟], 然後選取要使用的vdi檔
(因為在"啟動硬碟"此步驟時, virtualbox會建立一個新VM的資料夾, 我習慣先把要開啟的vdi檔先移到此然後在選取開啟, 這樣新VM的資料夾就對應新vdi, 比較方便管理)
b. 執行3.
c. 執行4. , 但不用在裝OS(因為已經有了), 只需調整網卡的部份及IP
(IP一樣設成192.168.X.X)
d. 修改hostname, 執行:sudo gedit /etc/hostname 修改完要重開VM
(不要跟其他VM重複, 自己容易辨識的就行)
重複5., 6. 即可佈署大量的VM
[Recommendation]
A. 假設想要所有VM都裝一些相同套件(ex. hadoop and Java)或設定, 可在一開始建第一個VM就都先下載安裝好, 如此複製此VM所產生的vdi也會具有相同的套件安裝
B. 想建立ssh免密碼連線, 可以先在第一台VM做好自己連自己的免密碼
C. 若想建立一個大型互連的cluster, 在host設定上為了減少麻煩, 可在第一台VM先設置好
/etc/hosts, 將想要互連的host全部設進去, 之後的VM建立就不用在一個個去修改hosts
D. 當每次新建好一個VM時(就是網卡及hostname等全部設好),
1. 先ssh 到先前已經建好的VM, 若OK則表示Bridge設置沒問題
2. 然後開啟網頁瀏覽器, 若能正常開啟連外網頁, 則表示NAT沒問題
[延伸]
X. 曾經想過, 若VMs分佈在很多台physical machines上時, 控管每個VM要不斷轉換去使用各個physical machine, 這樣顯得很麻煩, 後來有找到一套軟體可以在單一一台server上就可去連到各個physical machine上的VM, 叫做"RemoteBox", 不過在嘗試使用下, 雖確實可以連到各台的VMs, 但卻無法開啟該VM的視窗畫面, 這點尚未突破
RemoteBox官網:
remotebox.knobgoblin.org.uk/downloads.cgi
[Reference]
多台實體machine建VM hadoop cluster
http://changyy.pixnet.net/blog/post/25612440-%5Blinux%5D-%E5%AE%89%E8%A3%9D-hadoop-0.20.1-multi-node-cluster-@-ubuntu-9.1
remotebox相關介紹
http://www.openfoundry.org/index.php?option=com_content&task=view&id=8319&Itemid=40
vboxmanage 指令doc
http://www.virtualbox.org/manual/ch08.html#vboxmanage-clonevm
vboxmanage clonevdi指令介紹
http://lbt95.pixnet.net/blog/post/30970746-%5Bvirtualbox%5D-%E4%BD%BF%E7%94%A8vboxmanage-%E8%A4%87%E8%A3%BD%E5%87%BA%E7%AC%AC%E4%BA%8C%E5%80%8B%E4%BD%9C%E6%A5%AD%E7%B3%BB%E7%B5%B1
virtualbox 網卡type介紹
http://www.wretch.cc/blog/mk99/22949462
當想模擬數十台甚至數百台VM所組成的cluster時, 單一實體server會受限於cpu數量以及memory大小, 而無法建立如此多台VM, 所以必須跨連到其他實體的servers, 此時VM又該如何佈署及設置網路?
[Virtual Machine]
本篇使用的是VirtualBox4.1版
[Physical Machine]
HP ProLiant DL380 G6 (2core, 20G mem, 500G hd ) X 3
各自OS為 Ubuntu 12.04
[Method]
1. Install virtualbox at each physical servers 在各個server上安裝virtualbox
參考:http://lifenote332.blogspot.tw/2012/06/virtualbox-install-on-ubuntu.html
2. Start Virtualbox and Create a new VM 新增一個新VM
a. 設定[名稱], 選擇[作業系統]及[版本]
(在此的名稱與VM內的OS完全沒關, 只是Virtualbox辨識用)
b. 設定[記憶體大小] (在這設1G)
c. 啟動硬碟-->選擇[新建硬碟]
d. 檔案類型-->選擇[VDI]
e. 存放裝置選擇詳細資料-->選擇[動態配置]
f. 虛擬磁碟檔案位置-->選擇(即將創造的vdi檔的存放位置), 大小-->選擇(在此設成50G)
g. 完成建立
3. Set two network interface cards for the VM 給予此VM兩張網卡
a. NAT(Network Address Translation):
概念:模擬自身就是本台實體server(Host OS), 以便對外連線, 但會使得實體server無法偵測到自己(此VM即Guest OS), 也因此無法連線到其他實體server上的VM
功用:便利此VM上網作些更新或下載的動作
b. Bridge
概念:模擬自身與本台實體server(Host OS)存在於同一個Hob or Router底下,使得實體server能偵測得到自己, 因此在其他實體server上的VM也同樣的設定下, 可偵測到彼此
功用:讓VM不僅可在本台實體server上互連, 也可與其他台實體server上的VM互連
4. Install OS and set network configuration on the VM 安裝OS及設定網路
a. 在此安裝linux OS(Ubuntu 11.10)
b. 網路設定的部份, 選擇[編輯連線], 因為先前給予了兩張網卡所以會有兩個連線, 而連線對映的設置應為:
I. 裝置的MAC Address : (eth0) 即為給予的NAT網卡 --> IPv4設定 :自動(DHCP)
II. 裝置的MAC Address : (eth1) 即為給予的Bridge網卡 --> IPv4設定 :手動(manual)
address : 192.168.X.X(X表示自行設置, 在此設成192.168.123.1)
mask: 255.255.X.X(在此設成255.255.255.0)
gateway: 192.168.X.254(在此設成192.168.123.254, 網路上似乎常用254)
DNS server: (同gateway)
5. Clone VDI 複製vdi
當一個VM建好時, 他所有的設定都包成了一個vdi檔, 當然也可以複製此vdi來開啟另一個新的VM, 使其具備與原始的VM有同樣的設定, 但無法直接複製, 必須透過VirtualBox上的指令a. 執行:vboxmanage clonvdi old.vdi new.vdi
便會產生新的vdi來開啟新的VM
b. 執行:vboxmanage internalcommands sethduuid new.vdi
因為有可能新舊兩個VM的uuid重複導致Virtualbox無法去開啟, 所以需在給new.vdi一個隨機的新uuid
6. Deploy new VM 開始佈署VM
複製好的vdi, 可在本機開啟成新的VM, 亦可透過scp傳給其他台實體server 來開啟新的VMa. 再次實行2. , 只是到2. c.時, 選擇[使用現有硬碟], 然後選取要使用的vdi檔
(因為在"啟動硬碟"此步驟時, virtualbox會建立一個新VM的資料夾, 我習慣先把要開啟的vdi檔先移到此然後在選取開啟, 這樣新VM的資料夾就對應新vdi, 比較方便管理)
b. 執行3.
c. 執行4. , 但不用在裝OS(因為已經有了), 只需調整網卡的部份及IP
(IP一樣設成192.168.X.X)
d. 修改hostname, 執行:sudo gedit /etc/hostname 修改完要重開VM
(不要跟其他VM重複, 自己容易辨識的就行)
重複5., 6. 即可佈署大量的VM
[Recommendation]
A. 假設想要所有VM都裝一些相同套件(ex. hadoop and Java)或設定, 可在一開始建第一個VM就都先下載安裝好, 如此複製此VM所產生的vdi也會具有相同的套件安裝
B. 想建立ssh免密碼連線, 可以先在第一台VM做好自己連自己的免密碼
C. 若想建立一個大型互連的cluster, 在host設定上為了減少麻煩, 可在第一台VM先設置好
/etc/hosts, 將想要互連的host全部設進去, 之後的VM建立就不用在一個個去修改hosts
D. 當每次新建好一個VM時(就是網卡及hostname等全部設好),
1. 先ssh 到先前已經建好的VM, 若OK則表示Bridge設置沒問題
2. 然後開啟網頁瀏覽器, 若能正常開啟連外網頁, 則表示NAT沒問題
[延伸]
X. 曾經想過, 若VMs分佈在很多台physical machines上時, 控管每個VM要不斷轉換去使用各個physical machine, 這樣顯得很麻煩, 後來有找到一套軟體可以在單一一台server上就可去連到各個physical machine上的VM, 叫做"RemoteBox", 不過在嘗試使用下, 雖確實可以連到各台的VMs, 但卻無法開啟該VM的視窗畫面, 這點尚未突破
RemoteBox官網:
remotebox.knobgoblin.org.uk/downloads.cgi
[Reference]
多台實體machine建VM hadoop cluster
http://changyy.pixnet.net/blog/post/25612440-%5Blinux%5D-%E5%AE%89%E8%A3%9D-hadoop-0.20.1-multi-node-cluster-@-ubuntu-9.1
remotebox相關介紹
http://www.openfoundry.org/index.php?option=com_content&task=view&id=8319&Itemid=40
vboxmanage 指令doc
http://www.virtualbox.org/manual/ch08.html#vboxmanage-clonevm
vboxmanage clonevdi指令介紹
http://lbt95.pixnet.net/blog/post/30970746-%5Bvirtualbox%5D-%E4%BD%BF%E7%94%A8vboxmanage-%E8%A4%87%E8%A3%BD%E5%87%BA%E7%AC%AC%E4%BA%8C%E5%80%8B%E4%BD%9C%E6%A5%AD%E7%B3%BB%E7%B5%B1
virtualbox 網卡type介紹
http://www.wretch.cc/blog/mk99/22949462
2012年5月20日 星期日
Virtualbox的VM開多cpu
想要在Virtualbox上已經建好設定好的VM(其實新開的也一樣), 增加大於一顆的cpu數量時,
發現無法開啟, 並出現以下錯誤:
重新於設定處去觀察, (設定值 > 系統 > 處理器)
會發現當cpu數量調成2顆以上時,
底下會有個警示說"未偵測到最佳值",
並且訊息顯示" 控制在虛擬機器中的虛擬CPU數, 您需要在您的主機系統支援硬體虛擬化以使用一個以上的CPU"
上網去找解:
1. 執行 sudo /etc/init.d/vboxdrv setup
重開virtualbox再去調cpu數時, 不再有"未偵測到最佳值"的警訊
但仍有錯誤訊息.
[Reference]
http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?post_id=88236
2. 後來發現主機要重新去調整Bios, 開啟CPU的虛擬功能(前提是本身主機板有提供此能力)
以自己電腦為例,
按delete 進Bios後 > 進階 > 監控 > CPU > Intel 虛擬化技術 > (原本關閉) 開啟
然後再進作業系統重新開啟virtualbox 後就可以了!
[Reference]
http://ckwsteven.pixnet.net/blog/post/29109830-virtualb o%8C%AF%E8%AA%A4%E8%A8%8A%E6%81%AF-vt-x-features-locked-or-unavailable-i
發現無法開啟, 並出現以下錯誤:
開啟虛擬機器 hdp1master 的工作階段失敗。
VT-x features locked or unavailable in MSR. (VERR_VMX_MSR_LOCKED_OR_DISABLED).
結果碼(&N): NS_ERROR_FAILURE (0x80004005)
元件: Console
介面: IConsole {1968b7d3-e3bf-4ceb-99e0-cb7c913317bb}
VT-x features locked or unavailable in MSR. (VERR_VMX_MSR_LOCKED_OR_DISABLED).
結果碼(&N): NS_ERROR_FAILURE (0x80004005)
元件: Console
介面: IConsole {1968b7d3-e3bf-4ceb-99e0-cb7c913317bb}
重新於設定處去觀察, (設定值 > 系統 > 處理器)
會發現當cpu數量調成2顆以上時,
底下會有個警示說"未偵測到最佳值",
並且訊息顯示" 控制在虛擬機器中的虛擬CPU數, 您需要在您的主機系統支援硬體虛擬化以使用一個以上的CPU"
上網去找解:
1. 執行 sudo /etc/init.d/vboxdrv setup
重開virtualbox再去調cpu數時, 不再有"未偵測到最佳值"的警訊
但仍有錯誤訊息.
[Reference]
http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?post_id=88236
2. 後來發現主機要重新去調整Bios, 開啟CPU的虛擬功能(前提是本身主機板有提供此能力)
以自己電腦為例,
按delete 進Bios後 > 進階 > 監控 > CPU > Intel 虛擬化技術 > (原本關閉) 開啟
然後再進作業系統重新開啟virtualbox 後就可以了!
[Reference]
http://ckwsteven.pixnet.net/blog/post/29109830-virtualb o%8C%AF%E8%AA%A4%E8%A8%8A%E6%81%AF-vt-x-features-locked-or-unavailable-i
Hangs when exiting ssh
在寫shell script檔時,有時會希望ssh到另一台叫他做事,
此時希望自己離開繼續執行下面未完的shell script, 而那一台繼續做事,
過往用 & 作背景處理的方式以不管用
ex: 連到adalab 然後要他 sleep 20sec, 而自己要能馬上離開作其他事例如pwd
ssh hdp1@adalab <<EOI
sleep20 &
exit
EOI
pwd
此時必須改成:
ssh hdp1@adalab <<EOI
sleep 20 </dev/null> /dev/null 2>&1 &
EOI
pwd
就完成了~
[Reference]
http://www.openssh.org/faq.html#3.10
此時希望自己離開繼續執行下面未完的shell script, 而那一台繼續做事,
過往用 & 作背景處理的方式以不管用
ex: 連到adalab 然後要他 sleep 20sec, 而自己要能馬上離開作其他事例如pwd
ssh hdp1@adalab <<EOI
sleep20 &
exit
EOI
pwd
此時必須改成:
ssh hdp1@adalab <<EOI
sleep 20 </dev/null> /dev/null 2>&1 &
EOI
pwd
就完成了~
[Reference]
http://www.openssh.org/faq.html#3.10
2012年5月17日 星期四
2012年5月13日 星期日
ECDSA host key for 'XXX' differs from the key for the IP address
之前在使用 ssh時碰到類似以下的問題:
Warning: the ECDSA host key for 'XXX' differs from the key for the IP address 'XXX'
Offending key for IP in /home/hadoop/.ssh/known_hosts:5
Matching host key in /home/hadoop/.ssh/known_hosts:7
Are you sure you want to continue connecting (yes/no)?
後來想到因為本機曾經連到過叫hdp2的vm, 但後來hdp2這個vm又重新創造過,
所以其實算是不同的機器, 但在本機的
/home/hadoop/.ssh/known_hosts
紀錄的是舊的hdp2資訊,
與現在連線的hdp2衝突,所以每次連線都在問是否要繼續連線.
解決方式:
將/home/hadoop/.ssh/known_hosts
刪掉,
重新ssh到hdp2時他就會問你要不要establish, yes後,
他似乎會在重建一個known_hosts
下次就不會在出現這個warning了
[Reference]
http://security.stackexchange.com/questions/10532/ecdsa-keys-changed-ssh-insecure-now
2012年4月25日 星期三
background execution
有時候會想不要等到第一個指令做完才執行第二個指令,
就必須讓第一個指令變成在backgroud 做,
方法很簡單, 只要在指令後面加上 & 就行了,
Example:
$ bin/hadoop jar hadoop-examples-<version>.jar grep input output 'g' &
此時這個hadoop job就會在background執行,
而不用等他做完就可以先執行下一個指令
就必須讓第一個指令變成在backgroud 做,
方法很簡單, 只要在指令後面加上 & 就行了,
Example:
$ bin/hadoop jar hadoop-examples-<version>.jar grep input output 'g' &
此時這個hadoop job就會在background執行,
而不用等他做完就可以先執行下一個指令
shell script - ssh and forwarding command
想說執行shell script file, 讓他自動ssh連線到另一台server
並執行一些指令如下:
---test.sh---
ssh user1@server1
mkdir testFolder
exit
---
但發現會停在連線過去的部份, 也就是只做了ssh user1@server1,
剩下的指令都不會自動作, 要自己再額外手打,
後來上網查了一些, 發現別人在作類似的事情時,
會在ssh 指令後面加上 <<EOI
及在exit 後面加上 EOI
然後嘗試:
---test.sh---
ssh user1@server1 <<EOI
mkdir testFolder
exit
EOI
---
就成功了!
原因尚待研究...
並執行一些指令如下:
---test.sh---
ssh user1@server1
mkdir testFolder
exit
---
但發現會停在連線過去的部份, 也就是只做了ssh user1@server1,
剩下的指令都不會自動作, 要自己再額外手打,
後來上網查了一些, 發現別人在作類似的事情時,
會在ssh 指令後面加上 <<EOI
及在exit 後面加上 EOI
然後嘗試:
---test.sh---
ssh user1@server1 <<EOI
mkdir testFolder
exit
EOI
---
就成功了!
原因尚待研究...
shell script - delay for a while
之前一直在想說寫shell script時要怎麼在指令間達到 delay的效果,
後來發現很簡單只要加
sleep (second)
就行了
ex:
想要執行pwd 10秒後再執行ifconfig
---test.sh---
pwd
sleep 10
ifconfig
---
後來發現很簡單只要加
sleep (second)
就行了
ex:
想要執行pwd 10秒後再執行ifconfig
---test.sh---
pwd
sleep 10
ifconfig
---
2012年3月11日 星期日
VM 架設參考
Xen
http://trac.nchc.org.tw/cloud/wiki/Xen_Lab1
但Ubuntu對 Xen提供的整合越來越少, 轉而去服務KVM
KVM
http://www.mpsstudio.org/2011/09/ubuntuhow-to-install-kvm-on-ubuntu-1004_13.html
http://bojack.pixnet.net/blog/post/29040863-%E3%80%90linux%E3%80%91%E5%9C%A8-ubuntu-11.04-%E4%B8%8A%E5%AE%89%E8%A3%9D-kvm
https://help.ubuntu.com/community/KVM (Ubuntu官網)
http://publib.boulder.ibm.com/infocenter/lnxinfo/v3r0m0/index.jsp?topic=%2Fliaai%2Fkvmadv%2Fkvmadvvirsh.htm (IBM官網)
[討論]
關於hadoop在虛擬化機器上的效率 (Taiwan Hadoop Forum)
http://trac.nchc.org.tw/cloud/wiki/Xen_Lab1
但Ubuntu對 Xen提供的整合越來越少, 轉而去服務KVM
KVM
http://www.mpsstudio.org/2011/09/ubuntuhow-to-install-kvm-on-ubuntu-1004_13.html
http://bojack.pixnet.net/blog/post/29040863-%E3%80%90linux%E3%80%91%E5%9C%A8-ubuntu-11.04-%E4%B8%8A%E5%AE%89%E8%A3%9D-kvm
https://help.ubuntu.com/community/KVM (Ubuntu官網)
http://publib.boulder.ibm.com/infocenter/lnxinfo/v3r0m0/index.jsp?topic=%2Fliaai%2Fkvmadv%2Fkvmadvvirsh.htm (IBM官網)
[討論]
關於hadoop在虛擬化機器上的效率 (Taiwan Hadoop Forum)
2012年3月8日 星期四
bash 檔中的 if else判斷式
[Reference]
sites.google.com/site/tiger2000/home
第二十四章 Shell Script
Testing 判斷式
sites.google.com/site/tiger2000/home
第二十四章 Shell Script
Testing 判斷式
Testing 判斷式通常與if-then-else一起互用, 以便發揮其效果. 先從一個最簡單的例子看起 :
$ cat myscript7
#!/bin/sh
if [ -f /etc/passwd ]; then
echo "/etc/passwd is a file"
else
echo "PANIC : /etc/passwd is not a file!!"
fi
先說明一下 [ -f /etc/passwd ] 這個最重要的部份, [ ] 裡面就是判斷式, 而這裡是判斷 /etc/passwd 是不是一個 file ?
由結果來看看是執行 then 下面的敘述, 或者執行 else 的敘述.
同時很重要一點是 底下這些敘述都是不正確的敘述, 會有錯誤產生喔 :
[-f /etc/passwd ] [-f 連在一起
[ -f /etc/passwd] passwd] 連在一起
[ -f/etc/passwd ] -f與/etc/passwd連在一起
這裡是一個雙重條件判斷的範例:
CONFIG=config.ini
if [ -e $CONFIG -a "`grep ^Mailer $CONFIG`" ]; then
SERVER_LIST=(`grep ^Mailer $CONFIG | cut -d= -f2 | sed 's/,/ /g'`)
SERVER_NUM=${#SERVER_LIST[@]}
else
echo "$CONFIG not found"
exit 2
fi
上述的範例有些複雜, 簡單的說它透過 -a (代表 and) 判斷是否同時滿足 -e $CONFIG 與 `grep ^Mailer $CONFIG?
所以另外一個 -o (寄是代表 or) 就會類似這樣了:
if [ -e $CONFIG -o "`grep ^Mailer $CONFIG`" ]; then
XXXXX (自己發揮)
fi
所以利用 [ ] 我們可以做出以下這些判斷, 這些也都很常用喔 !!
test true if ....
[ string1 = string2 ] string1 and string2 are equal
[ string1 != string2 ] string1 and string2 are not equal
[ string1 \< string2 ] string1 is lexically less than string2
(e.g. 'a' is less than 'b')
[ string1 \> string2 ] string1 is lexically greater than string2
(e.g. 'b' is greater than 'a')
[ -z string ] string is zero (e.g. a empty string)
[ -n string ] string is nonzero (e.g. a VAR string)
[ -e file ] file exists
[ -f file ] file is a file
[ -d file ] file is a directory
[ -c file ] file is a character device
[ -b file ] file is a block device
[ -p file ] file is a named pipe
[ -s file ] file is not empty
[ -k file ] file's sticky bit is set
[ -S file ] file is a socket
[ -L file ] file is a symbolic link
[ -r file ] file is readable by user
[ -w file ] file is writeable by user
[ -x file ] file is executeable by user
[ -O file ] file is owner by user
[ -G file ] file is group owned by a greoup
[ -u file ] file has its set user ID bit set
[ -g file ] file has its group user ID bit set
[ file1 -nt file2 ] file1 is newer than file2
[ file1 -ot file2 ] file1 is older than file2
[ file -ef file2 ] file1 is another name for file2
[ n1 -eq n2 ] true if integer n1 = integer n2
[ n1 -ne n2 ] true if integer n1 <> n2
[ n1 -gt n2 ] true if n1 > n2
[ n1 -ge n2 ] true if n1 >= n2
[ n1 -lt n2 ] true if n1 < n2
[ n1 -le n2 ] true if n1 <= n2
2012年2月13日 星期一
觀察系統資源運作--top
觀察CPU utility, Memory use... 等等
可以使用 top 指令
ex:
1. $top -d 1
-d: 表示資訊幾秒更新一次, 上述範例是一秒更新一次
2. $top
$1
top完後再按"1" 可以觀察各個單一CPU utility
可以使用 top 指令
ex:
1. $top -d 1
-d: 表示資訊幾秒更新一次, 上述範例是一秒更新一次
2. $top
$1
top完後再按"1" 可以觀察各個單一CPU utility
開關cpu 指令
Disable a CPU core on Ubuntu
1. cat /proc/cpuinfo
2. echo 0 | sudo tee /sys/devices/system/cpu/cpu1/online
關CPU1
3. echo 1 | sudo tee /sys/devices/system/cpu/cpu1/online
開CPU1
[Reference]
http://www.upubuntu.com/2011/09/how-to-disable-cpu-core-on-ubuntudebian.html
1. cat /proc/cpuinfo
2. echo 0 | sudo tee /sys/devices/system/cpu/cpu1/online
關CPU1
3. echo 1 | sudo tee /sys/devices/system/cpu/cpu1/online
開CPU1
[Reference]
http://www.upubuntu.com/2011/09/how-to-disable-cpu-core-on-ubuntudebian.html
訂閱:
文章 (Atom)