planet-lab平臺的佈置

   最近需要把國家自然基金項目趕快結題,所以導師也催的緊.正好自己也在研究網格和高性能計算,所以老闆就把部署planet-lab環境的任務交給我.鄙人英語很爛,所以花了很長時間的去讀指導書.最後基本上搞定,但是還有問題,希望網友們能給我點解答.(planet-lab一般供給高校做研究)
    以hello_world爲例,來詳細介紹如何佈置環境.
需要的軟件 Python 2.3 or higher 可以訪問的目錄,並且這個目錄也可被web服務器訪問 該web服務器需要裝php4.1 or higher 部署步驟 在planet-lab的主頁上註冊一個email帳號,並且需要PI(管理員)分配給你一個slice(抽象的). 生成訪問planet-lab上所有可用節點的公鑰私鑰.用$ssh-keygen -t rsa -f ~/.ssh/id_rsa 然後把.ssh/id_rsa.pub上傳到planet-lab上你的賬戶的key中 把planet-lab上所有的節點加入到你的slice中,可以在瀏覽器的地址欄中輸入:http://comon.cs.princeton.edu/status/tabulator.cgi?table=table_nodeviewshort&format=nameonly&persite=1&
select='resptime>0',
把結果存儲到nodes.txt中,假設所有的操作都在~/planetlab/hello_world目錄下 把節點加入到你的slice中,可以在工作目錄下輸入python腳本$ python
>>> import xmlrpclib
>>> api_server = /
... xmlrpclib.ServerProxy('https://www.planet-lab.org/PLCAPI/')
>>>
>>> auth = {}
>>> auth['Username'] = "user" <-- 用你自己的email帳號替代                                          >>> auth['AuthString'] = "pass" <-- 用你自己的帳號密碼替代
>>> auth['AuthMethod'] = "password"
>>>
>>> node_list = [line.strip() for line in open("nodes.txt")]
>>>
>>> api_server.AddSliceToNodes(auth, /
... "你的slice名稱", node_list)
安裝部署作業的軟件codeploy,具體可參看安裝手冊(跟一般安裝軟件步驟相同,注意:在最後可能運行軟件時找不到multiquery命令的錯誤提示,這就要你給codeploy搞好環境變量) 如果你所安裝的機器正好是一臺web服務器,那你就可直接跳過這步;否則,你就要配置你這臺機器,使它變成一臺web服務器(安裝apache,如果你不知道是否安裝,你可用rpm -qa|grep httpd來查看) 在你的工作目錄下建立一個可被寫的文件phonehome.txt,並輸入命令$ touch phonelog.txt
$ chmod 666 phonelog.txt                        在你的可被web訪問的目錄下,存儲一下文件phonehome.php phonelog.php 和phonehome.py文件                                                                                                                 <?                                    
### phonelog.php
header('Content-type: application/vnd.google-earth.kml+xml');
header('Content-disposition: attachment;
filename="hello_world.kml"');
echo '<?xml version="1.0" encoding="UTF-8"?>' . "/n";
echo '<kml xmlns="http://earth.google.com/kml/2.0">' ."/n";
echo '<Document>' . "/n";
$phonelog = file("phonelog.txt");
foreach ($phonelog as $entry) {
$fields = explode("/t", trim($entry));
if ($fields[4] == "None" || $fields[5] == "None") continue;
?>
<Placemark>
<Snippet><?= htmlspecialchars($fields[3]) ?></Snippet>
<name><?= htmlspecialchars($fields[1]) ?></name>
<LookAt>
<longitude><?= $fields[5] ?></longitude>
<latitude><?= $fields[4] ?></latitude>
<range>1000000</range>
</LookAt>
<visibility>1</visibility>
<Point>
<extrude>1</extrude>
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>
<?= $fields[5] . "," . $fields[4] ?>,0
</coordinates>
</Point>
</Placemark>
<? }
?>
</Document>
</kml>                                                                                                                                               <?
### phonehome.php
if (isset($_GET['reset'])) {
$phonelog = fopen("phonelog.txt", "w");
fclose($phonelog);
echo "Cleared Phone Log.";
die();
}
if (!isset($_POST['site_id'])) die;
$existinglog = file("phonelog.txt");
foreach ($existinglog as $entry) {
$f = explode("/t", trim($entry));
if ($f[0] == $_POST['site_id']) die;
}
$phonelog = fopen("phonelog.txt", "a");
fwrite($phonelog, $_POST['site_id'] . "/t" . $_POST['name'] .
"/t" . $_POST['login_base'] . "/t" . $_POST['url'] .
"/t" . $_POST['latitude'] . "/t" . $_POST['longitude'] .
"/n");
fclose($phonelog);
?>                                                                                                                                                                                                    #!/usr/bin/python
### phonehome.py
### Hello World demonstration script
phonehome_url = "http://www.your.url/~username/hw_demo/phonehome.php"<這個用你的可訪問目錄的url來代替,hw_demo就是這三個文件存放位置>
import sys, urllib, xmlrpclib, socket
api_server = xmlrpclib.ServerProxy('https://www.planet-lab.org/PLCAPI/')
auth = {}
auth['AuthMethod'] = "anonymous"
auth['Role'] = "user"
hostname = socket.gethostname()
query = api_server.GetNodes(auth,
{'hostname': hostname}, ['site_id'])
site_id = query[0]['site_id']
site_info = api_server.GetSites(auth,
{'site_id': site_id}, ['site_id', 'name', 'url',
'latitude', 'longitude', 'login_base'])
site_info = urllib.urlencode(site_info[0])
urllib.urlopen(phonehome_url, site_info)
最後來運行下./codeploy ~/public_html/helloworld /
http://www.your.url/~username/helloworld/ hello(注意:這個要跟你的存放目錄和具體url有關,不要盲目照寫)
注意,在連接節點時,可能每連一個節點,它就要你輸入passprase,很麻煩,我教你可以用下法:                        $eval `ssh-agent`                               $  ssh-add ~/.ssh/id_rsa     我的問題,我用ssh連接一個節點時,每次到了sending envirnment時就不走了,但我感覺應該連上了.請各位高手告訴我.

參考文獻:

hello_world.pdf 來源於planet-lab網站

 

 

我現在知道我爲什麼ssh不能正確連到nodes上了,因爲每個站點要兩臺機器連到planet-lab節點,才能工作.而我們機房裏有一臺機器不能被ping通,後來我看了planet-lab上的assistance tutorial才知道如何加入planet-lab裏的種種步驟和軟硬條件.還是挺麻煩的.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章