因為手邊剛好在將 Lab 的機器虛擬化,所以最近正在玩 VMWare ESXi 4.0
基本上需求就是希望 VMWare ESXi 一開機,就可以自動啟動其中的幾個 VM
不過不知道是我關鍵字下的不對還是太簡單沒人討論,中文的搜尋結果竟然沒有我想要的
所以只好下了英文的關鍵字來搜尋,第二篇就是我要找的了
簡單來說就是在使用 VMWare vShere Client 登入之後的這個畫面
點選右上的「Properties」,接著在下面這個畫面
把底下屬於 Manual Startup 的 VM 按 Move UP 移到 Automatic Startup 裡面去就好。
另外,偷偷換了 blog 的 template。現在的 blogger 還真是漂亮+方便啊… 搭配 chrome 真的超強的。
呃,另外附上我 google 到的原文網頁
Life is not measured by the number of breaths we take, but by the moments that take our breath away. - Hilary Cooper
2010年6月1日
2009年12月8日
讓 USB 隨身碟同時可以安裝 Linux/Windows 7
身為一個專業的阿宅,每次安裝 OS 的時候總是要找光碟找半天,偏偏很多 Server、Notebook 都沒有光碟機,找學弟借也只是權宜之計。
剛好手邊有個 160G 的隨身碟,就打算來建立一個可以用 USB 開機且安裝 OS 的 USB 隨身硬碟。
我的需求「看似」很簡單,不過實際上 google 了很久倒是沒什麼解法…所以在解決了這個難題之後,特地把他記錄下來…
Require:
補上最後的 menu.lst
剛好手邊有個 160G 的隨身碟,就打算來建立一個可以用 USB 開機且安裝 OS 的 USB 隨身硬碟。
我的需求「看似」很簡單,不過實際上 google 了很久倒是沒什麼解法…所以在解決了這個難題之後,特地把他記錄下來…
Require:
開機時我可以選擇要使用哪一個 iso 檔案來開機
除了一般的 Unix-Like OS 之外,我還要能夠安裝 Windows 7
1. 單純 Unix-Like OS 的話很簡單,請直接 google BootMyISO 解決
2. 單純 Windows 7 的話也很簡單,請直接 /boot/bootsect X:,xcopy E: /s /e /f X:
X: 為 USB 隨身碟代號, E: 為光碟機代號
3. 如果沒這麼單純的話請往下看…
其實解法很簡單,我個人的步驟是
1. 請先把你的隨身碟格式化成 FAT32 (之後就不要再格式化囉,只格式化這一次)
3. 我把 Ubuntu lucid 10.04 dialy build 2009-12-07 的 iso 檔丟進去,並且依照上篇文章修改,並且確認可正常開機。
4. 接著參考 這篇文章 的後半段,從 Step 9 開始到 Step 11。
5. 這時候,隨身碟就只能用 Windows 7 開機,於是再重新用第二步的 BootMyISO 重新執行一次。
6. 重新把 Ubnutn 的 menu.list 寫入。
7. 加入給 Windows 7 用的 menu.lst
title Windows 7 64bit Ent
# find --set-root /pmagic-4.5.iso
# map /pmagic-4.5.iso (hd32)
# map --hook
# root (hd32)
chainloader /bootmgr
8. 我整個 menu.lst 是這樣
default 0
timeout 30
color cyan/blue white/blue
foreground ffffff
background 003f7dtitle Memtest86+
find --set-root /memtest86+-4.00.iso
map --mem /memtest86+-4.00.iso (hd32)
map --hook
root (hd32)
chainloader (hd32)title Windows 7 64bit Ent
chainloader /bootmgrtitle lucid-alternate-i386.iso
find --set-root /bootiso/lucid-alternate-i386.iso
map /bootiso/lucid-alternate-i386.iso (hd32)
map --hook
root (hd32)
chainloader (hd32)
9. 完成之後,這個隨身碟就可以拿去安裝 Ubuntu/Windows 7 了。
不過根據我測試的結果,舊一點的主機板雖然支援 USB-HDD 開機,但還是無法正常進去 Windows 7 的安裝畫面。不過我測了手邊的幾台電腦:X200、LS400、X61 都是可以正常進到 Windows 7 64bit 安裝畫面與 Ubuntu Lucid 10.04 的安裝畫面的。
P.S 我猜,如果確定你的隨身碟支援 USB-HDD 開機的話,也許可以跳過 1、2、3 步驟,等 Windows 7 的 bootmbr 寫進去後,在用 grub 覆蓋回來就好。
多重開機可以參考這篇:http://www.pendrivelinux.com/boot-multiple-iso-from-usb-multiboot-usb/補上最後的 menu.lst
default 0
timeout 30
color white/blue yellow/black
title Ubuntu Lucid 10.94 Desktop i386 Dialy Build 20091207
find --set-root /bootiso/lucid-desktop-i386.iso
map /bootiso/lucid-desktop-i386.iso (0xff)
map --hook
root (0xff)
kernel /casper/vmlinuz file=/cdrom/preseed/ubuntu.seed boot=casper iso-scan/filename=/bootiso/lucid-desktop-i386.iso quiet splash locale=zh_TW
initrd /casper/initrd.lz
boot
title Windows 7 64bit Ent
# find --set-root /pmagic-4.5.iso
# map /pmagic-4.5.iso (hd32)
# map --hook
# root (hd32)
chainloader /bootmgr
# boot
title Ubuntu Lucid 10.94 Alternate i386 Dialy Build 20091207
find --set-root /bootiso/lucid-alternate-i386.iso
map /bootiso/lucid-alternate-i386.iso (hd32)
map --hook
root (hd32)
chainloader (hd32)
title Memtest86+
find --set-root /bootiso/memtest86+-4.00.iso
map --mem /bootiso/memtest86+-4.00.iso (hd32)
map --hook
root (hd32)
chainloader (hd32)
title Reboot
reboot
title Shutdown
halt
2009年8月28日
Network Simulator:ns-2 安裝與基本操作 on Debian/Ubuntu
欸都,沒想到去年 training 之後,現在真的要開始用 ns-2 跑模擬了…
之前灌好的 macbook 不在我手邊,加上我也不想用筆電來跑模擬,
所以就找了一台 P4 的機器安裝 Ubuntu 9.10 alpha 4 來裝 ns-2
同時也在 vmware 上成功安裝在 debian 5.0 testing 的版本。
基本上這兩個 linux distribuction 安裝的步驟一模一樣(本是同根生…)
1. 這是我的 debian 版本
2. 下載 ns-2 allinone 的壓縮檔(我個人是偏好 cmdline 指令,當然也可以選擇從網頁瀏覽下載)
3. 解壓縮並進入 ns-allinone-2.34 的目錄
5. 如果安裝過程中出現下列這兩個情況
請安裝 libxmu-dev
請安裝 g++
6. 如果順利安裝好,就會看到下列的畫面
7. 請依照指示把這些路徑加到環境變數裡面
8. 請下載範例檔下來
點我下載
9. 執行測試
10. 跑完後目錄底下會多一個 out.tr 檔案,這時候就要採用 awk 來分析了,請先下載 awk 檔
點我下載
Leopard 版的安裝請參考之前寫的文章 Training:Network Simulator:ns-2 安裝與基本操作
2. 下載 ns-2 allinone 的壓縮檔(我個人是偏好 cmdline 指令,當然也可以選擇從網頁瀏覽下載)
wget http://downloads.sourceforge.net/project/nsnam/allinone/ns-allinone-2.34/ns-allinone-2.34.tar.gz?use_mirror=nchc
3. 解壓縮並進入 ns-allinone-2.34 的目錄
tar zxvf ns-allinone-2.34.tar.gz
cd ns-allinone-2.34
4. 安裝與編譯
./install
5. 如果安裝過程中出現下列這兩個情況
請安裝 libxmu-dev
sudo aptitude install libxmu-dev
請安裝 g++
sudo aptitude install g++
6. 如果順利安裝好,就會看到下列的畫面
7. 請依照指示把這些路徑加到環境變數裡面
vi ~/.bashrc
路徑
export NS_HOME=/home/chrisliu/ns-allinone-2.34
export PATH=$NS_HOME/ns-2.34:$NS_HOME/tcl8.4.18/unix:$NS_HOME/tk8.4.18/unix:$NS_HOME/bin:$PATH
export LD_LIBRARY_PATH=$NS_HOME/tcl8.4.18/unix:$NS_HOME/tk8.4.18/unix:$NS_HOME/otcl-1.13:$NS_HOME/lib:$LD_LIBRARY_PATH
export TCL_LIBRARY=$NS_HOME/tcl8.4.18/library
8. 請下載範例檔下來
點我下載
wget http://chrisliuqq.googlepages.com/example.tcl
9. 執行測試
ns example.tcl
10. 跑完後目錄底下會多一個 out.tr 檔案,這時候就要採用 awk 來分析了,請先下載 awk 檔
點我下載
wget http://chrisliuqq.googlepages.com/delay.awk
11. 執行 awk 來分析
awk -f delay.awk out.tr
Leopard 版的安裝請參考之前寫的文章 Training:Network Simulator:ns-2 安裝與基本操作
2008年7月30日
Training:Socket Programming on C#
教育訓練第二彈,下午的課程就是在教如何使用 .NET 架構寫一個 Socket 的程式。此範例是使用 C#。
所有程式碼可從這邊取得。
(不過程式碼有點亂…而且沒有加註解,請斟酌使用。)
Server 端
using System;
using System.Collections.Generic;
using System.Text;
// include Socket library
using System.Net;
using System.Net.Sockets;
namespace tcpServerStarter
{
class Program
{
static void Main(string[] args)
{
// 建立 tcpServer 物件並啟動 server
tcpServer server = new tcpServer(IPAddress.Any, 520);
server.startServer();
}
}
// tcpServer Class
public class tcpServer
{
IPAddress _ip; // 要 listen 的 ip
int _port; // 要 listen 的 port
bool _serverAlive = false; // 檢查 server 是否還存活
// tcpServer construtor
public tcpServer(IPAddress ip, int port)
{
this._ip = ip;
this._port = port;
}
// 啟動 server 的 method
public void startServer()
{
將 _serverAlive 的 flag 設為 true
_serverAlive = true;
try
{
// 建立一個 TcpListener 的物件,並且 listen 在 _ip 與 _port
TcpListener listen = new TcpListener(this._ip, this._port);
// 開始 listen
listen.Start();
// 如果 Server 還活著
while (_serverAlive)
{
// 取得由 TcpListener 得到的 TcpClient
TcpClient tcpClient = listen.AcceptTcpClient();
// 由 TcpClient 建立一個 NetworkStream
NetworkStream netStream = tcpClient.GetStream();
// 建立一個大小為 1024 的 byte 陣列來放收到的資料
byte[] reciBuffer = new byte[1024];
int count = 0;
// 將經由 Stream 讀取道的資料放入 readBuffer 中
// 並且將長度存到 count
while ((count = netStream.Read(readBuffer, 0, readBuffer.Length)) != 0)
{
// 將 byte 陣列轉成 string
string reciStr = System.Text.Encoding.UTF8.GetString(reciBuffer, 0, count);
Console.WriteLine("recieve data:" + reciStr);
// 傳出的字串 = 收到的字串
string sendStr = reciStr;
// 將 string 轉成 byte 陣列
byte[] sendBuffer = System.Text.Encoding.UTF8.GetBytes(sendStr);
// 將資料送出
netStream.Write(sendbuffer, 0, sendBuffer.Length);
Console.WriteLine("send data:" + sendstr);
}
}
}
catch { }
}
}
}
Client 端
建立 TextBox1、TextBox2、TextBox3、Button1
TextBox1 為要連接的 server ip
TextBox2 為要連接的 port
TextBox3 為從 server 收到的資料
Button1 為連接 server 的按鈕
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
// include Socket Library
using System.Net;
using System.Net.Sockets;
namespace tcpClient
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// 建立一個 TcpClient 物件連接到 ip, port
TcpClient client = new TcpClient(textBox1.Text, int.Parse(textBox2.Text));
// 由 TcpClient 建立一個 Stream
NetworkStream netStream = client.GetStream();
// 自訂要送出的資料為 123456
string sendMsg = "123456";
// 將字串轉為 byte 陣列
byte[] sendBuffer = System.Text.Encoding.UTF8.GetBytes(sendMsg);
// 送出給 server
netStream.Write(sendBuffer, 0, sendBuffer.Length );
// 建立一個大小為 1024 的 byte 陣列來放收到的資料
byte[] readBuffer = new byte[1024];
// 讀取從 server 來的資料並放到 readBuffer 中
netStream.Read(readBuffer, 0, readBuffer.Length);
// 將 byte 陣列轉為 string
string readStr = System.Text.Encoding.UTF8.GetString(readBuffer, 0, readBuffer.Length);
// 將讀取到的字串顯示在 textBox3
textBox3.Text = readStr;
}
}
}
Training:Network Simulator:ns-2 安裝與基本操作
因為學校暑期有舉行教育訓練,然後有請學長來講這個主題,就順便記下來啦~~
不過沒想到在 Leopard 上面也可以正常的跑~ 真是個好物啊!
「Cygwin on Windows」
1. 安裝 cygwin,請從 http://www.cygwin.com 下載。
2. 請安裝以下必要套件
3. 從 http://tinyurl.com/6jwtt7 下載 ns-2 2.33 版本的 source code,並且儲存到 c:/cygwin/home/。
4. 進入 cygwin 解壓縮下載的檔案,執行
5. 進入 ns-allinone-2.33 目錄進行安裝與編譯
這個步驟是機器而定,我的 Macbook 大約跑了三分鐘吧,學校電腦教室的跑了10來分鐘吧~
6. 安裝好之後,請在 ~/.bashrc 加入下列路徑的設定
因為我是用 Macbook 來實做的,所以路徑是 /Applications/ns-allinone-2.33 如果是 cygwin 的話,請改成下列的路徑
然後稍微檢查一下 tcl、tck 的版本與路徑,如果不同的話請自行將版本號改成跟目錄內的版本號一樣。
7. 請繼續在 cygwin 內輸入下列指令以進入 X-win
8. 請下載這個 ns 的範例檔,並儲存在 c:\cygwin\home\
9. 如果 PATH 路徑都正確的話,請繼續執行
沒意外的話就會跑出下列GUI介面

10. 跑完後目錄底下會多一個 out.tr 檔案,這時候就要採用 awk 來分析了,請先下載這個寫好的 awk檔案 並儲存在 c:\cygwin\home\
11. 執行下列指令之後就分析好啦~
「Unix-Like OS」
1. 安裝的部份可選用 make ports、yum、aptitude 等等來安裝必要套件。
(MacOS-Leopard 全部都內建了,不用另外安裝)
2. 後面步驟就都一樣了 XD
(MacOS-Leopard 請直接執行 X11.app 後在執行 ns example.tcl)
不過沒想到在 Leopard 上面也可以正常的跑~ 真是個好物啊!
「Cygwin on Windows」
1. 安裝 cygwin,請從 http://www.cygwin.com 下載。
2. 請安裝以下必要套件
diffutils、gawk、gcc、gcc-g++、gunplot、make、patch、perl、tar、xorg-x11-base、xorg-x11-bin、xorg-x11-etc、xorg-x11-devel、XFree86-lib-compat3. 從 http://tinyurl.com/6jwtt7 下載 ns-2 2.33 版本的 source code,並且儲存到 c:/cygwin/home/。
4. 進入 cygwin 解壓縮下載的檔案,執行
tar zxvf ns-allinone-2.33.tar.gz5. 進入 ns-allinone-2.33 目錄進行安裝與編譯
cd /home/ns-allinone-2.33/
./install這個步驟是機器而定,我的 Macbook 大約跑了三分鐘吧,學校電腦教室的跑了10來分鐘吧~
6. 安裝好之後,請在 ~/.bashrc 加入下列路徑的設定
export NS_HOME=/Applications/ns-allinone-2.33
export PATH=$NS_HOME/tcl8.4.18/unix:$NS_HOME/tk8.4.18/unix:$NS_HOME/bin:$PATH
export LD_LIBRARY_PATH=$NS_HOME/tcl8.4.18/unix:$NS_HOME/tk8.4.18/unix:$NS_HOME/otcl-1.13:$NS_HOME/lib:$LD_LIBRARY_PATH
export TCL_LIBRARY=$NS_HOME/tcl8.4.18/library因為我是用 Macbook 來實做的,所以路徑是 /Applications/ns-allinone-2.33 如果是 cygwin 的話,請改成下列的路徑
export NS_HOME=/home/ns-allinone-2.33然後稍微檢查一下 tcl、tck 的版本與路徑,如果不同的話請自行將版本號改成跟目錄內的版本號一樣。
7. 請繼續在 cygwin 內輸入下列指令以進入 X-win
startxwin.bat8. 請下載這個 ns 的範例檔,並儲存在 c:\cygwin\home\
9. 如果 PATH 路徑都正確的話,請繼續執行
ns example.tcl沒意外的話就會跑出下列GUI介面

10. 跑完後目錄底下會多一個 out.tr 檔案,這時候就要採用 awk 來分析了,請先下載這個寫好的 awk檔案 並儲存在 c:\cygwin\home\
11. 執行下列指令之後就分析好啦~
awk -f delay.awk out.tr「Unix-Like OS」
1. 安裝的部份可選用 make ports、yum、aptitude 等等來安裝必要套件。
(MacOS-Leopard 全部都內建了,不用另外安裝)
2. 後面步驟就都一樣了 XD
(MacOS-Leopard 請直接執行 X11.app 後在執行 ns example.tcl)
繼續閱讀淡入淡出效果 on Blogger
這個效果主要是從 Kaie's Blog 看來的。剛好昨天 歐蒐雷米歐 問我這個效果,我就順手把這個效果也弄上了我的部落格。
注意
1. 此效果雖然跟 Kaie's Blog 很像,但除了 var fade 的效果啟動變數之外,其他都未參考他的程式碼。
2. 此效果採用了 jQuery 的 javascript Library,如果您已經採用其他 javascript Library 可能會因為衝突而無法正常顯示。
3. 部份語法由 Tony 提供。
步驟一:請先從 jQuery 下載 Download jQuery 1.2.6 (16kb, Minified and Gzipped)。
步驟二:將這個檔案傳到您的網頁空間。(googlepage也可以)
步驟三:在模板中加入這個 script 的連結。
<script src="http://yourwebsite/jquery-1.2.6.min.js" type="text/javascript"></script>
步驟四:將相關的 function 用下列的 function 取代
/* true 啟用淡入淡出效果,false 取消淡入淡出效果*/
var fade = true;
function showFull(id) {
var par= $("#"+id);
$("[id=hidelink]",par).css("display","inline");
$("[id=showlink]",par).css("display","none");
$("[id=fullpost]",par).fadeIn('slow');
$("img",par).fadeIn('slow');
}
function hideFull(id) {
var post = document.getElementById(id);
var par= $("#"+id);
$("[id=hidelink]",par).css("display","none");
$("[id=showlink]",par).css("display","inline");
$("[id=fullpost]",par).fadeOut('slow');
$("img",par).fadeOut('slow');
post.scrollIntoView(true);
}
rsync遠端備份 on Debian
以下內容主要是從此篇文章而來,我只是加了一點自己的經驗作紀錄。
1. 看看有哪些 rsync 套件。
Student:~# aptitude search rsync
p grsync - GTK+ frontend for rsync
p libfile-rsync-perl - perl module interface to rsync(1)
p libfile-rsyncp-perl - A perl based implementation of an Rsync client
p librsync-dev - Library which implements the rsync remote-delta
algorithm
p librsync1 - Library which implements the rsync remote-delta
algorithm
p maildirsync - simple and efficient Maildir synchronisation
utility
p rsync - fast remote file copy program (like rcp)
p rsyncrypto - rsync friendly encryption
2. 廢話不多說,我最喜歡 command line,安裝吧!
Student:~# aptitude install rsync
3. 安裝完之後,請編輯 /etc/default/rsync
Student:~# vi /etc/default/rsync
將 RSYNC_ENABLE=false
改成RSYNC_ENABLE=tru
4. 設定 rsync server 端
Student:~# vi /etc/rsyncd.conf
[bbsce]
#允許使用rsync的ip
hosts allow = 192.168.0.200
#將其他的都檔掉:
hosts deny = *
#要存放備份的地方
path = /backup/bbs.ce
use chroot = yes
read only = no
uid = nobody
gid = nogroup
auth users = bbsce
secrets file = /etc/rsyncd.secrets
timeout = 600
5. 設定密碼 rsyncd.secrets
Student:~# vi /etc/rsyncd.secrets
#帳號:密碼
guest:test
#接著修改權限和擁有者
Student:~# chown root:root /etc/rsyncd.secrets
Student:~# chmod 600 /etc/rsyncd.secrets
6. 啟動rsync
Student:~# /etc/init.d/rsync start
#可以連到自己的電腦看看有沒有成功
Student:~# telnet localhost 873
7. 設定 rsync client
#client 安裝rsync
bbs:~# aptitude install rsync
8. 設定密碼
bbs:~# vi /etc/rsyncd.passwd
將剛剛設定的密碼貼在這邊
9. 更改權限與擁有
chmod 600 /etc/rsyncd.passwd
chown root:root /etc/rsyncd.passwd
10.開始備份
rsync -arHz --progress --delete --password-file=/etc/rsyncd.passwd /home/ username@192.168.0.100::Home/home
-a:保留權限,除了Hard Link
-r:遞迴地複製目錄中的所有目錄
-H:保留 Hard Link
-z:資料備份前先壓縮
--progress:顯示進度
--delete:如果要備份的主機上刪除了某個檔案,備份的主機也刪除某個檔案
--password-file:密碼檔的位置
這一行username@92.168.0.100::Home/home的意思是
帳號@server的ip::在server端/etc/rsyncd.conf中的名字/建立一個home來放資料
11.最後當然要讓他自動化
#vi /etc/crontab
加入
0 5 * * * root /usr/bin/rsync -arHz --progress --delete --password-file=/etc/rsyncd.passwd /home/ bbsce@192.168.0.100::Home/home
資料還原
1. 到要被還原資料的電腦(Client 192.168.0.100那一台)
2. 執行rsync還原
#rsync -arHz --progress --delete --password-file=/etc/rsyncd.passwd
username@192.168.0.100::Home/home /home
這樣就可以把/back/home裡的資料還原到你的/home裡面了
訂閱:
文章 (Atom)

