裝機後主要要做的事情,目前想到的是設定防火牆還有hostname以及DNS
在設定hostname部分:
Linux 及 FreeBSD 修改主機名稱同樣使用 hostname 指令即可
例如:hostname taiwanwolf
這樣重新連線後,提示符號下就會變成
[root@taiwanwolf ~]
但這樣重開機後,還是會變回
[root@localhost ~]
為了系統下次啟動時也能自動使用新 hostname,需要作以下修改
vi /etc/sysconfig/network
把 hostname 部分改成新的名稱
P.S
Debian 為 /etc/hostname
FreeBSD 為 /etc/rc.conf
在設定DNS部分:
編輯 vim /etc/resolv.conf
內容如下
nameserver 139.175.252.16
nameserver 139.175.55.244
存檔即可
2009年4月24日
2009年4月7日
jQuery + AJAX + PHP 應用範例
ajax有很多技術,早先我是用xajax,但最近看了jQuery之後,覺得用法還蠻直接的,只要把jQuery的js檔案在HTML裡面include進來就可以直接使用語法,此外jQuery還支援很多Plugins及UI (User Interface)的操作,以下是一個很簡單的範例。
實際流程是:整個網頁載入後,會出現一個輸入姓名的欄位
此時可隨便輸入一個名字
按下Send按鈕,驅動ajax,並有loading效果
等待5秒後,下方將出現剛剛輸入的名字
程式流程:透過jQuery的ajax功能與後端Server的PHP程式溝通(此範例使用GET方法)之後,再把結果(echo 指令的output)丟回給前端的瀏覽器,只要這個範例能夠看懂,就等於打通任督二脈(前後端資料能溝通),之後想在後端查詢資料庫還是做運算等動作,就都沒有問題了~
前端:hello.htm 內容如下
後端 hello.php 的程式碼如下
<?php
$myname = $_GET['name'];
sleep(5); //為了製造 ajax loading效果,所以延遲5秒
echo "You input name is $myname <br>";
?>
至於ajax loading 時的BAR或小花旋轉等圖示,網路上有一個ajaxload圖示庫可以來製作
實際流程是:整個網頁載入後,會出現一個輸入姓名的欄位
此時可隨便輸入一個名字
按下Send按鈕,驅動ajax,並有loading效果
等待5秒後,下方將出現剛剛輸入的名字
程式流程:透過jQuery的ajax功能與後端Server的PHP程式溝通(此範例使用GET方法)之後,再把結果(echo 指令的output)丟回給前端的瀏覽器,只要這個範例能夠看懂,就等於打通任督二脈(前後端資料能溝通),之後想在後端查詢資料庫還是做運算等動作,就都沒有問題了~
前端:hello.htm 內容如下
<HTML>
<HEAD>
<style type="text/css">
#loadingImg{
position:absolute;
width:300px;
top:0px;
left:50%;
margin-left:-120px;
text-align:center;
padding:7px 0 0 0;
font:bold 11px Arial, Helvetica, sans-serif;
}
</style>
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#btn').click(function (){
$.ajax({
url: 'hello.php',
cache: false,
dataType: 'html',
type:'GET',
data: { name: $('#name').val()},
error: function(xhr) {
alert('Ajax request 發生錯誤');
},
success: function(response) {
$('#msg').html(response);
$('#msg').fadeIn();
}
});
});
$('#clean').click(function(){
$('#msg').html("");
// document.getElementById('msg').innerHTML = "";
});
$("#loadingImg").ajaxStart(function(){
$(this).show();
});
$("#loadingImg").ajaxStop(function(){
$(this).hide();
});
})
</script>
</HEAD>
<BODY>
<div id="loadingImg" style="display:none"><img src="loading.gif"> loading...</div>
<br><br><br>
<div align="center">
Enter your name <br>
<input type="text" id="name"> <br>
<input type="button" value="send" id="btn">
<input type="button" value="reset" id="clean">
<br><br><br>
<div id="msg"> </div>
</div>
</BODY>
</HTML>
後端 hello.php 的程式碼如下
<?php
$myname = $_GET['name'];
sleep(5); //為了製造 ajax loading效果,所以延遲5秒
echo "You input name is $myname <br>";
?>
至於ajax loading 時的BAR或小花旋轉等圖示,網路上有一個ajaxload圖示庫可以來製作
標籤:
AJAX,
ajax loading,
jQuery,
jQuery ajax範例,
PHP
利用dd指令遠端備份為ISO檔及還原成硬碟 (Linux, Unix, Solaris等適用)
遠端備份A(主機)的硬碟為ISO檔並儲存到B(File Server)的/backup目錄下
備份成ISO檔並丟到File Server:
Step1:SSH進入到欲備份的A主機下指令 (Linux)
Step2:dd if=/dev/hda | gzip -9 -c | ssh taiwanwolf@fileserver_ip dd of=/backup/hda.img.gz
Solaris 大概像以下的語法
/usr/local/bin/dd if=/dev/dsk/c1t0d0s2 | /usr/local/bin/gzip -9 -c | /usr/local/bin/ssh taiwanwolf@fileserver_ip /bin/dd of=/backup/c1t0d0s2.img.gz
從遠端File Server的ISO檔還原到本機硬碟
Step1:從一台裝上硬碟的Server, SSH進入到B(File Server)
Step2:ssh taiwanwolf@fileserver_ip zcat /backup/hda.img.gz | dd of=/dev/hda
如果該還原主機沒有作業系統,可採用 knoppix 之類的LiveCD來開機, 再綁上IP即可進行還原或備份
備份成ISO檔並丟到File Server:
Step1:SSH進入到欲備份的A主機下指令 (Linux)
Step2:dd if=/dev/hda | gzip -9 -c | ssh taiwanwolf@fileserver_ip dd of=/backup/hda.img.gz
Solaris 大概像以下的語法
/usr/local/bin/dd if=/dev/dsk/c1t0d0s2 | /usr/local/bin/gzip -9 -c | /usr/local/bin/ssh taiwanwolf@fileserver_ip /bin/dd of=/backup/c1t0d0s2.img.gz
從遠端File Server的ISO檔還原到本機硬碟
Step1:從一台裝上硬碟的Server, SSH進入到B(File Server)
Step2:ssh taiwanwolf@fileserver_ip zcat /backup/hda.img.gz | dd of=/dev/hda
如果該還原主機沒有作業系統,可採用 knoppix 之類的LiveCD來開機, 再綁上IP即可進行還原或備份
標籤:
遠端備份ISO,
dd,
dd on the fly,
Linux,
Solaris 硬碟備份,
Unix
2009年4月6日
Solaris SoftRAID 的meta資訊重建
由於平時監控 /var/adm/messages 的程式發出錯誤 (表示又有事了 @_@)
查看是硬碟的 write error如下, 進主機下 metastat, 發現 meta 資料有錯, 所以需要重新去resync
# metastat
d0: Mirror
Submirror 0: d10
State: Needs maintenance
Submirror 1: d20
State: Okay
Pass: 1
Read option: roundrobin (default)
Write option: parallel (default)
Size: 10491456 blocks
d10: Submirror of d0
State: Needs maintenance
Invoke: metareplace d0 c1t0d0s0
Size: 10491456 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t0d0s0 0 No Maintenance
d20: Submirror of d0
State: Okay
Size: 10491456 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t1d0s0 0 No Okay
d1: Mirror
Submirror 0: d11
State: Okay
Submirror 1: d21
State: Okay
Pass: 1
Read option: roundrobin (default)
Write option: parallel (default)
Size: 8476608 blocks
d11: Submirror of d1
State: Okay
Size: 8476608 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t0d0s1 0 No Okay
d21: Submirror of d1
State: Okay
Size: 8476608 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t1d0s1 0 No Okay
d4: Mirror
Submirror 0: d14
State: Needs maintenance
Submirror 1: d24
State: Okay
Pass: 1
Read option: roundrobin (default)
Write option: parallel (default)
Size: 16780224 blocks
d14: Submirror of d4
State: Needs maintenance
Invoke: metareplace d4 c1t0d0s4
Size: 16780224 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t0d0s4 0 No Maintenance
d24: Submirror of d4
State: Okay
Size: 16780224 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t1d0s4 0 No Okay
d5: Mirror
Submirror 0: d15
State: Needs maintenance
Submirror 1: d25
State: Okay
Pass: 1
Read option: roundrobin (default)
Write option: parallel (default)
Size: 6298944 blocks
d15: Submirror of d5
State: Needs maintenance
Invoke: metareplace d5 c1t0d0s5
Size: 6298944 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t0d0s5 0 No Maintenance
d25: Submirror of d5
State: Okay
Size: 6298944 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t1d0s5 0 No Okay
d6: Mirror
Submirror 0: d16
State: Okay
Submirror 1: d26
State: Okay
Pass: 1
Read option: roundrobin (default)
Write option: parallel (default)
Size: 82842816 blocks
d16: Submirror of d6
State: Okay
Size: 82842816 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t0d0s6 0 No Okay
d26: Submirror of d6
State: Okay
Size: 82842816 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t1d0s6 0 No Okay
d7: Mirror
Submirror 0: d17
State: Needs maintenance
Submirror 1: d27
State: Okay
Pass: 1
Read option: roundrobin (default)
Write option: parallel (default)
Size: 16780224 blocks
d17: Submirror of d7
State: Needs maintenance
Invoke: metareplace d7 c1t0d0s7
Size: 16780224 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t0d0s7 0 No Maintenance
d27: Submirror of d7
State: Okay
Size: 16780224 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t1d0s7 0 No Okay
做法很簡單, Solaris 已經幫我們列出來了
以最後一筆 d7 為例,表示為第七個Virtual的分割區, d17是第1顆硬碟, d27是第2顆硬碟
d17: Submirror of d7
State: Needs maintenance <-- Solaris 跟你說需要維護了
Invoke: metareplace d7 c1t0d0s7 <-- 指令就在這裡
所以我們就下
# metareplace -e d7 c1t0d0s7
表示要重新 resync 第1顆的第七個分割區,然後依序把 Needs maintenance 的分割區都下完,可同時執行,然後再下
# metastat | grep sync
去看完成的狀態,即可復原
查看是硬碟的 write error如下, 進主機下 metastat, 發現 meta 資料有錯, 所以需要重新去resync
# metastat
d0: Mirror
Submirror 0: d10
State: Needs maintenance
Submirror 1: d20
State: Okay
Pass: 1
Read option: roundrobin (default)
Write option: parallel (default)
Size: 10491456 blocks
d10: Submirror of d0
State: Needs maintenance
Invoke: metareplace d0 c1t0d0s0
Size: 10491456 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t0d0s0 0 No Maintenance
d20: Submirror of d0
State: Okay
Size: 10491456 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t1d0s0 0 No Okay
d1: Mirror
Submirror 0: d11
State: Okay
Submirror 1: d21
State: Okay
Pass: 1
Read option: roundrobin (default)
Write option: parallel (default)
Size: 8476608 blocks
d11: Submirror of d1
State: Okay
Size: 8476608 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t0d0s1 0 No Okay
d21: Submirror of d1
State: Okay
Size: 8476608 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t1d0s1 0 No Okay
d4: Mirror
Submirror 0: d14
State: Needs maintenance
Submirror 1: d24
State: Okay
Pass: 1
Read option: roundrobin (default)
Write option: parallel (default)
Size: 16780224 blocks
d14: Submirror of d4
State: Needs maintenance
Invoke: metareplace d4 c1t0d0s4
Size: 16780224 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t0d0s4 0 No Maintenance
d24: Submirror of d4
State: Okay
Size: 16780224 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t1d0s4 0 No Okay
d5: Mirror
Submirror 0: d15
State: Needs maintenance
Submirror 1: d25
State: Okay
Pass: 1
Read option: roundrobin (default)
Write option: parallel (default)
Size: 6298944 blocks
d15: Submirror of d5
State: Needs maintenance
Invoke: metareplace d5 c1t0d0s5
Size: 6298944 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t0d0s5 0 No Maintenance
d25: Submirror of d5
State: Okay
Size: 6298944 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t1d0s5 0 No Okay
d6: Mirror
Submirror 0: d16
State: Okay
Submirror 1: d26
State: Okay
Pass: 1
Read option: roundrobin (default)
Write option: parallel (default)
Size: 82842816 blocks
d16: Submirror of d6
State: Okay
Size: 82842816 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t0d0s6 0 No Okay
d26: Submirror of d6
State: Okay
Size: 82842816 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t1d0s6 0 No Okay
d7: Mirror
Submirror 0: d17
State: Needs maintenance
Submirror 1: d27
State: Okay
Pass: 1
Read option: roundrobin (default)
Write option: parallel (default)
Size: 16780224 blocks
d17: Submirror of d7
State: Needs maintenance
Invoke: metareplace d7 c1t0d0s7
Size: 16780224 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t0d0s7 0 No Maintenance
d27: Submirror of d7
State: Okay
Size: 16780224 blocks
Stripe 0:
Device Start Block Dbase State Hot Spare
c1t1d0s7 0 No Okay
做法很簡單, Solaris 已經幫我們列出來了
以最後一筆 d7 為例,表示為第七個Virtual的分割區, d17是第1顆硬碟, d27是第2顆硬碟
d17: Submirror of d7
State: Needs maintenance <-- Solaris 跟你說需要維護了
Invoke: metareplace d7 c1t0d0s7
所以我們就下
# metareplace -e d7 c1t0d0s7
表示要重新 resync 第1顆的第七個分割區,然後依序把 Needs maintenance 的分割區都下完,可同時執行,然後再下
# metastat | grep sync
去看完成的狀態,即可復原
訂閱:
文章 (Atom)