Deserializes JavaScript Object Notation (JSON) text to produce a JavaScript value.
JSON.parse(text [, reviver])
- text
Required. Valid JSON text.
- reviver
Optional. A function that filters and transforms the results. The deserialized object is traversed recursively, and the reviver function is called for each member of the object in post-order (every object is revived after all its members have been revived). For each member, the following occurs:
If reviver returns a valid value, the member value is replaced with the value returned by reviver.
If reviver returns what it received, the structure is not modified.
If reviver returns null or undefined, the object member is deleted.
The reviver argument is often used to transform JSON representation of International Organization for Standardization (ISO) date strings into Coordinated Universal Time (UTC) format Date objects.
A JavaScript value—an object or array.
Exception | Condition |
---|
JavaScript parser errors | The input text does not comply with JSON syntax. To correct the error, do one of the following: Modify the text argument to comply with JSON syntax. For more information, see the BNF syntax notation of JSON objects. Make sure that the text argument was serialized by a JSON-compliant implementation, such as, JSON.stringify.
|
This example uses JSON.parse to deserialize JSON text into the contact object.
var jsontext = '{"firstname":"Jesper","surname":"Aaberg","phone":["555-0100","555-0120"]}'; var contact = JSON.parse(jsontext); var fullname = contact.surname + ", " + contact.firstname; // The value of fullname is "Aaberg, Jesper"
This example uses JSON.parse to deserialize an ISO-formatted date string. The dateReviver function returns Date objects for members that are formatted like ISO date strings.
var jsontext = '{ "hiredate": "2008-01-01T12:00:00Z", "birthdate": "2008-12-25T12:00:00Z" }'; var dates = JSON.parse(jsontext, dateReviver); var string = dates.birthdate.toUTCString(); // The value of string is "Thu, 25 Dec 2008 12:00:00 UTC" function dateReviver(key, value) { var a; if (typeof value === 'string') { a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); if (a) { return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6])); } } return value; };
Supported in the following document modes: Internet Explorer 8 standards, Internet Explorer 9 standards. See Version Information.
Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards.
Serializes a JavaScript value into JavaScript Object Notation (JSON) text.
JSON.stringify(value [, replacer] [, space])
- value
Required. A JavaScript value, usually an object or array, to be serialized.
- replacer
Optional. A function or array that filters and transforms the results.
If replacer is a function, JSON.stringify calls the function, passing in the key and value of each member. The return value is serialized instead of the original value. If the function returns undefined, the member will be excluded from the serialization. The key for the root object is an empty string: "".
If replacer is an array, only members with key values in the array will be serialized. The order of serialization is the same as the order of the keys in the array. Thereplacer array is ignored when the value argument is also an array.
- space
Optional. Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
If space is omitted, the return-value text is generated without any extra white space.
If space is a number, the return-value text is indented with the specified number of white spaces at each level. If space is greater than 10, text is indented 10 spaces.
If space is a non-empty string, such as '\t', the return-value text is indented with the characters in the string at each level.
If space is a string that is longer than 10 characters, the first 10 characters are used.
A string that contains the serialized JSON text.
If the value that is being serialized has a toJSON method, the JSON.stringify function calls the toJSON method and uses the return value for serialization. If the return value of the toJSON method is undefined, the member will not be serialized. This enables an object to determine its own JSON representation.
Values that do not have JSON representations, such as undefined, will not be serialized. In objects, they will be dropped. In arrays, they will be replaced with null.
String values begin and end with a quotation mark. All Unicode characters may be enclosed in the quotation marks except for the characters that must be escaped by using a backslash. The following characters must be preceded by a backslash:
Order of Execution
During the serialization process, if a toJSON method exists for the value argument, JSON.stringify first calls the toJSON method. If it does not exist, the original value is used. Next, if a replacer argument is provided, the value (original value or toJSON return-value) is replaced with the return-value of the replacer argument. Finally, white spaces are added to the value based on the optional space argument to generate the final serialized JSON text.
This example uses JSON.stringify to serialize the contact object to JSON text. The memberfilter array is defined so that only the surname and phone members are serialized. The firstname member is omitted.
var contact = new Object(); contact.firstname = "Jesper"; contact.surname = "Aaberg"; contact.phone = ["555-0100", "555-0120"]; var memberfilter = new Array(); memberfilter[0] = "surname"; memberfilter[1] = "phone"; var jsonText = JSON.stringify(contact, memberfilter, "\t"); /* The value of jsonText is: '{ "surname": "Aaberg", "phone": [ "555-0100", "555-0120" ] }' */
This example uses JSON.stringify to serialize an array. The replaceToUpper function converts every string in the array to uppercase.
var continents = new Array(); continents[0] = "Europe"; continents[1] = "Asia"; continents[2] = "Australia"; continents[3] = "Antarctica"; continents[4] = "North America"; continents[5] = "South America"; continents[6] = "Africa"; var jsonText = JSON.stringify(continents, replaceToUpper); /* The value of jsonText is: '"EUROPE,ASIA,AUSTRALIA,ANTARCTICA,NORTH AMERICA,SOUTH AMERICA,AFRICA"' */ function replaceToUpper(key, value) { return value.toString().toUpperCase(); }
This example uses the toJSON method to serialize string member values in uppercase.
var contact = new Object(); contact.firstname = "Jesper"; contact.surname = "Aaberg"; contact.phone = ["555-0100", "555-0120"]; contact.toJSON = function(key) { var replacement = new Object(); for (var val in this) { if (typeof (this[val]) === 'string') replacement[val] = this[val].toUpperCase(); else replacement[val] = this[val] } return replacement; }; var jsonText = JSON.stringify(contact); /* The value of jsonText is: '{"firstname":"JESPER","surname":"AABERG","phone":["555-0100","555-0120"]}' */
Supported in the following document modes: Internet Explorer 8 standards, Internet Explorer 9 standards. See Version Information.
Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards.
http://msdn.microsoft.com/library/cc836459(VS.85).aspx
posted @
2013-03-04 16:59 David1228 閱讀(886) |
評論 (0) |
編輯 收藏
轉(zhuǎn)載自:http://linuxtoy.org/archives/kvm-issue.html
筆者在部署 KVM 虛擬機時曾遇到一個奇怪的問題,幾經(jīng)探索之后終于解決,現(xiàn)在寫出來跟大家分享一下。
筆者在單位部署了一臺服務(wù)器,上面運行著幾部 KVM 虛擬機,分別執(zhí)行不同的任務(wù)。系統(tǒng)上線之后,需要再增加幾部虛擬機。因為當(dāng)初部署服務(wù)器時做了虛擬機備份,所以就復(fù)制了一個備份的虛擬機。可是新虛擬機啟動之后無法在本地網(wǎng)絡(luò)上找到新虛擬機的 IP 地址(本地網(wǎng)絡(luò)采用 DHCP 分配 IP 地址)!因為服務(wù)器是遠程控制的,當(dāng)然新虛擬機也就無法使用了。
為了查找原因,筆者把虛擬機復(fù)制到本地主機上,用正常方法開啟。啟動過程及登錄都很正常,于是檢查網(wǎng)卡狀況:
$ ifconfig
可是卻只有顯示 lo 信息! 怪了,eth0 呢?只有 lo 當(dāng)然是沒有辦法同網(wǎng)絡(luò)通訊的。于是查找一下啟動信息:
$ dmesg | grep eth
發(fā)現(xiàn)如下信息:
udev: renamed network interface eth0 to eth1
原來 eth0 已經(jīng)沒有了,被命名為 eth1, 再看網(wǎng)卡配置
$ cat /etc/network/interfaces auto eth0 iface eth0 inet dhcp
至此事情水落石出,原來 KVM 是在啟動時傳遞 mac 參數(shù)的,如筆者是用下面命令啟動 KVM 虛擬機:
$ sudo kvm -m 256 -hda /data/kvm/mail.img -net nic,vlan=0,macaddr=52-54-00-12-30-05 -net tap,vlan=0,ifname=tap5,script=no -boot c -smp 2 -daemonize -nographic &
注意上面的 macaddr=52-54-00-12-30-05,這就是虛擬機啟動后的網(wǎng)卡 mac,因為網(wǎng)絡(luò)內(nèi)不可以有相同的 mac,所以啟動每個虛擬機的 mac 都要改。可是當(dāng)換了新的 mac 后,虛擬機里的系統(tǒng)就認(rèn)為換了新網(wǎng)卡,所以系統(tǒng)改變 eth0 為 eth1,而在網(wǎng)卡設(shè)置里面卻只設(shè)置了 eth0, 所以虛擬機啟動之后并沒有啟動新的 eth1 網(wǎng)卡,當(dāng)然就連不上網(wǎng)絡(luò)了。原因找到了之后問題的解決也就非常簡單:
$ vi /etc/network/interfaces
增加以下內(nèi)容:
auto eth1 iface eth1 inet dhcp
再重新啟動網(wǎng)絡(luò):
$ /etc/init.d/networking restart
至此問題應(yīng)該就完全解決了。不過有個問題還要注意,如果有多次用不同的 mac 啟動虛擬機,可能你的虛擬機里已經(jīng)有了 eth2, eth3 甚至是 10 都是有可能的,因為你每用一個新的 mac 去啟動虛擬機,系統(tǒng)就會增加一個網(wǎng)卡。可以修改下面這個文件:
$ vi /etc/udev/rules.d/70-persistent-net.rules
刪除所有的的 ethX 行,重啟虛擬機即可。
{ Thanks 逸飛. }
posted @
2013-02-20 11:41 David1228 閱讀(976) |
評論 (0) |
編輯 收藏
WARNING: The file has been changed since reading it!!!Do you really want to write to it (y/n)?y"/proc/sys/net/ipv4/ip_forward" E667: Fsync failedHit ENTER or type command to continue編輯/etc/sysctl.conf把net.ipv4.ip_forward = 0改成net.ipv4.ip_forward = 1如果此文件中沒有這個選項則將其添加上就行。然后執(zhí)行命令:#sysctl -p使其生效。
[root@IBM-007 sudo]# sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 2
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
vm.min_free_kbytes = 65536
kernel.panic_on_oops = 1
kernel.panic = 60
[root@IBM-007 sudo]#
[root@IBM-007 sudo]#
[root@IBM-007 sudo]# ll /
[root@IBM-007 sudo]#
再一次的查看
[root@IBM-007 sudo]# cat /proc/sys/net/ipv4/ip_forward
1
可以發(fā)現(xiàn)其原來的0就變成了1.
posted @
2013-01-30 14:12 David1228 閱讀(6299) |
評論 (0) |
編輯 收藏
#!/bin/bash
# Title : {stop|start|restart} Tomcat . Default is "restart".
# Author : Cheng PJ
# E-mail : 7looki@gmail.com
# Version : 1.0
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
file_name_f1=`echo ${0} | awk -F / '{print $1}'`
file_name_f2=`echo ${0} | awk -F / '{print $NF}'`
file_pwd=`echo ${0} | sed 's#'/${file_name_f2}'$##g'`
if [ -z "${file_name_f1}" ] || [ ${file_name_f1} != ${file_name_f2} ]; then
cd ${file_pwd}
fi
tomcat_bin=`pwd`
if [ ! -f ${tomcat_bin}/startup.sh ] || [ ! -f ${tomcat_bin}/bootstrap.jar ] || [ ! -f ${tomcat_bin}/catalina.sh ]; then
echo ""
echo "This script must be in the directory under \${Tomcat_Home}/bin !"
echo ""
exit 1
fi
tomcat_whoami=`whoami`
tomcat_own_user=`ls -l ${tomcat_bin}/startup.sh | awk '{print $3}'`
tomcat_who_run=`ps -ef | grep ${tomcat_bin} | grep -v "grep\|${0}" | awk '{print $1}'`
tomcat_who_run_other=`ps -ef | grep ${tomcat_bin} | grep -v "grep\|${0}" | awk '{print $1}' | grep -v "${tomcat_who_run}\|root" | sort | uniq`
tomcat_run_num=`ps -ef | grep ${tomcat_bin} | grep -v "grep\|${0}" | wc -l`
tomcat_echo_stop () {
echo "Tomcat Stopping ... [OK]"
echo ""
}
tomcat_echo_start () {
echo ""
echo "Tomcat Starting ... [OK]"
}
tomcat_echo_error () {
echo ""
echo "Tomcat Stopped ERROR ! Please check privilege or something !"
echo ""
exit 1
}
tomcat_stop () {
if [ ${tomcat_who_run} == ${tomcat_whoami} ] || [ ${tomcat_whoami} == "root" ]; then
ps -ef | grep ${tomcat_bin} | grep -v "grep\|${0}" | awk '{print $2}' | xargs kill -9
if [ $? -eq 0 ]; then
tomcat_echo_stop;
else
tomcat_echo_error;
fi
else
echo "ERROR ! You must root or ${tomcat_who_run} to run this script !"
exit 1
fi
}
tomcat_start () {
if [ ${tomcat_own_user} == ${tomcat_whoami} ] || [ ${tomcat_own_user} == "root" ]; then
sh ${tomcat_bin}/startup.sh
if [ $? -eq 0 ]; then
tomcat_echo_start;
else
tomcat_echo_error;
fi
else
echo "ERROR ! You must root or ${tomcat_own_user} to run this script !"
exit 1
fi
}
tomcat_shutdown () {
if [ ${tomcat_run_num} -eq 0 ]; then
echo "Tomcat is not running!"
echo ""
elif [ ${tomcat_run_num} -eq 1 ]; then
tomcat_stop;
else
if [ ${tomcat_who_run_other} == "" ]; then
tomcat_stop;
else
echo "Please shutdown Tomcat with other users (${tomcat_who_run_other}) "
echo "Tomcat is not stopped !"
exit 1
fi
fi
}
tomcat_startup () {
tomcat_run_check=`ps -ef | grep ${tomcat_bin} | grep -v "grep\|${0}" | wc -l`
if [ ${tomcat_run_check} -eq 0 ]; then
tomcat_start;
else
echo "Tomcat is not stopped ! Please stop Tomcat at first !"
echo 1
fi
}
case "$1" in
start|-start|--start)
tomcat_startup
;;
stop|-stop|--stop)
tomcat_shutdown
;;
help|-help|--help)
echo ""
echo "This script used for {start|stop|restart} Tomcat !"
echo ""
echo " By ST.7looki"
echo " 7looki@gmail.com"
echo ""
;;
restart|-restart|--restart|*)
tomcat_shutdown
sleep 1
tomcat_startup
esac
posted @
2013-01-30 10:48 David1228 閱讀(1490) |
評論 (2) |
編輯 收藏
Netperf使用轉(zhuǎn)載自:
http://os.chinaunix.net/a2004/0708/1042/000001042354.shtml 本文首先介紹網(wǎng)絡(luò)性能測量的一些基本概念和方法,然后結(jié)合 netperf 工具的使用,具體的討論如何測試不同情況下的網(wǎng)絡(luò)性能。 在構(gòu)建或管理一個網(wǎng)絡(luò)系統(tǒng)時,我們更多的是關(guān)心網(wǎng)絡(luò)的可用性,即網(wǎng)絡(luò)是否連通,而對于其整體的性能往往考慮不多,或者即使考慮到性能的問題,但是卻發(fā)現(xiàn)沒有合適的手段去測試網(wǎng)絡(luò)的性能。 當(dāng)開發(fā)出一個網(wǎng)絡(luò)應(yīng)用程序后,我們會發(fā)現(xiàn),在實際的網(wǎng)絡(luò)環(huán)境使用中,網(wǎng)絡(luò)應(yīng)用程序的使用效果不是很理想,問題可能出現(xiàn)在程序的開發(fā)上面,也有可能由于實際的網(wǎng)絡(luò)環(huán)境中存在著瓶頸。面對這種問題,程序員一般會一籌莫展,原因就在于不掌握一些網(wǎng)絡(luò)性能測量的工具。 在本文中,首先介紹網(wǎng)絡(luò)性能測量的一些基本概念和方法,然后結(jié)合 netperf 工具的使用,具體的討論如何測試不同情況下的網(wǎng)絡(luò)性能。 網(wǎng)絡(luò)性能測試概述 網(wǎng)絡(luò)性能測量的五項指標(biāo) 測量網(wǎng)絡(luò)性能的五項指標(biāo)是: 可用性(availability) 響應(yīng)時間(response time) 網(wǎng)絡(luò)利用率(network utilization) 網(wǎng)絡(luò)吞吐量(network throughput) 網(wǎng)絡(luò)帶寬容量(network bandwidth capacity) 1. 可用性 測試網(wǎng)絡(luò)性能的第一步是確定網(wǎng)絡(luò)是否正常工作,最簡單的方法是使用 ping 命令。通過向遠端的機器發(fā)送 icmp echo request,并等待接收 icmp echo reply 來判斷遠端的機器是否連通,網(wǎng)絡(luò)是否正常工作。 Ping 命令有非常豐富的命令選項,比如 -c 可以指定發(fā)送 echo request 的個數(shù),-s 可以指定每次發(fā)送的 ping 包大小。 網(wǎng)絡(luò)設(shè)備內(nèi)部一般有多個緩沖池,不同的緩沖池使用不同的緩沖區(qū)大小,分別用來處理不同大小的分組(packet)。例如交換機中通常具有三種類型的包緩沖:一類針對小的分組,一類針對中等大小的分組,還有一類針對大的分組。為了測試這樣的網(wǎng)絡(luò)設(shè)備,測試工具必須要具有發(fā)送不同大小分組的能力。Ping 命令的 -s 就可以使用在這種場合。 2. 響應(yīng)時間 Ping 命令的 echo request/reply 一次往返所花費時間就是響應(yīng)時間。有很多因素會影響到響應(yīng)時間,如網(wǎng)段的負(fù)荷,網(wǎng)絡(luò)主機的負(fù)荷,廣播風(fēng)暴,工作不正常的網(wǎng)絡(luò)設(shè)備等等。 在網(wǎng)絡(luò)工作正常時,記錄下正常的響應(yīng)時間。當(dāng)用戶抱怨網(wǎng)絡(luò)的反應(yīng)時間慢時,就可以將現(xiàn)在的響應(yīng)時間與正常的響應(yīng)時間對比,如果兩者差值的波動很大,就能說明網(wǎng)絡(luò)設(shè)備存在故障。 3. 網(wǎng)絡(luò)利用率 網(wǎng)絡(luò)利用率是指網(wǎng)絡(luò)被使用的時間占總時間(即被使用的時間+空閑的時間)的比例。比如,Ethernet 雖然是共享的,但同時卻只能有一個報文在傳輸。因此在任一時刻,Ethernet 或者是 100% 的利用率,或者是 0% 的利用率。 計算一個網(wǎng)段的網(wǎng)絡(luò)利用率相對比較容易,但是確定一個網(wǎng)絡(luò)的利用率就比較復(fù)雜。因此,網(wǎng)絡(luò)測試工具一般使用網(wǎng)絡(luò)吞吐量和網(wǎng)絡(luò)帶寬容量來確定網(wǎng)絡(luò)中兩個節(jié)點之間的性能。 4. 網(wǎng)絡(luò)吞吐量 網(wǎng)絡(luò)吞吐量是指在某個時刻,在網(wǎng)絡(luò)中的兩個節(jié)點之間,提供給網(wǎng)絡(luò)應(yīng)用的剩余帶寬。 網(wǎng)絡(luò)吞吐量可以幫組尋找網(wǎng)絡(luò)路徑中的瓶頸。比如,即使 client 和 server 都被分別連接到各自的 100M Ethernet 上,但是如果這兩個 100M 的Ethernet 被 10M 的 Ethernet 連接起來,那么 10M 的 Ethernet 就是網(wǎng)絡(luò)的瓶頸。 網(wǎng)絡(luò)吞吐量非常依賴于當(dāng)前的網(wǎng)絡(luò)負(fù)載情況。因此,為了得到正確的網(wǎng)絡(luò)吞吐量,最好在不同時間(一天中的不同時刻,或者一周中不同的天)分別進行測試,只有這樣才能得到對網(wǎng)絡(luò)吞吐量的全面認(rèn)識。 有些網(wǎng)絡(luò)應(yīng)用程序在開發(fā)過程的測試中能夠正常運行,但是到實際的網(wǎng)絡(luò)環(huán)境中卻無法正常工作(由于沒有足夠的網(wǎng)絡(luò)吞吐量)。這是因為測試只是在空閑的網(wǎng)絡(luò)環(huán)境中,沒有考慮到實際的網(wǎng)絡(luò)環(huán)境中還存在著其它的各種網(wǎng)絡(luò)流量。所以,網(wǎng)絡(luò)吞吐量定義為剩余帶寬是有實際意義的。 5. 網(wǎng)絡(luò)帶寬容量 與網(wǎng)絡(luò)吞吐量不同,網(wǎng)絡(luò)帶寬容量指的是在網(wǎng)絡(luò)的兩個節(jié)點之間的最大可用帶寬。這是由組成網(wǎng)絡(luò)的設(shè)備的能力所決定的。 測試網(wǎng)絡(luò)帶寬容量有兩個困難之處:在網(wǎng)絡(luò)存在其它網(wǎng)絡(luò)流量的時候,如何得知網(wǎng)絡(luò)的最大可用帶寬;在測試過程中,如何對現(xiàn)有的網(wǎng)絡(luò)流量不造成影響。網(wǎng)絡(luò)測試工具一般采用 packet pairs 和 packet trains 技術(shù)來克服這樣的困難。 收集網(wǎng)絡(luò)性能數(shù)據(jù)的方式 當(dāng)確定了網(wǎng)絡(luò)性能的測試指標(biāo)以后,就需要使用網(wǎng)絡(luò)測試工具收集相應(yīng)的性能數(shù)據(jù),分別有三種從網(wǎng)絡(luò)獲取數(shù)據(jù)的方式: 1. 通過snmp協(xié)議直接到網(wǎng)絡(luò)設(shè)備中獲取,如net-snmp工具 2. 偵聽相關(guān)的網(wǎng)絡(luò)性能數(shù)據(jù),典型的工具是tcpdump 3. 自行產(chǎn)生相應(yīng)的測試數(shù)據(jù),如本文中使用的netperf工具 Netperf Netperf是一種網(wǎng)絡(luò)性能的測量工具,主要針對基于TCP或UDP的傳輸。Netperf根據(jù)應(yīng)用的不同,可以進行不同模式的網(wǎng)絡(luò)性能測試,即批量數(shù)據(jù)傳輸(bulk data transfer)模式和請求/應(yīng)答(request/reponse)模式。Netperf測試結(jié)果所反映的是一個系統(tǒng)能夠以多快的速度向另外一個系統(tǒng)發(fā)送數(shù)據(jù),以及另外一個系統(tǒng)能夠以多塊的速度接收數(shù)據(jù)。 Netperf工具以client/server方式工作。server端是netserver,用來偵聽來自client端的連接,client端是netperf,用來向server發(fā)起網(wǎng)絡(luò)測試。在client與server之間,首先建立一個控制連接,傳遞有關(guān)測試配置的信息,以及測試的結(jié)果;在控制連接建立并傳遞了測試配置信息以后,client與server之間會再建立一個測試連接,用來來回傳遞著特殊的流量模式,以測試網(wǎng)絡(luò)的性能。 TCP網(wǎng)絡(luò)性能 由于TCP協(xié)議能夠提供端到端的可靠傳輸,因此被大量的網(wǎng)絡(luò)應(yīng)用程序使用。但是,可靠性的建立是要付出代價的。TCP協(xié)議保證可靠性的措施,如建立并維護連接、控制數(shù)據(jù)有序的傳遞等都會消耗一定的網(wǎng)絡(luò)帶寬。 Netperf可以模擬三種不同的TCP流量模式: 1) 單個TCP連接,批量(bulk)傳輸大量數(shù)據(jù) 2) 單個TCP連接,client請求/server應(yīng)答的交易(transaction)方式 3) 多個TCP連接,每個連接中一對請求/應(yīng)答的交易方式 UDP網(wǎng)絡(luò)性能 UDP沒有建立連接的負(fù)擔(dān),但是UDP不能保證傳輸?shù)目煽啃裕允褂肬DP的應(yīng)用程序需要自行跟蹤每個發(fā)出的分組,并重發(fā)丟失的分組。 Netperf可以模擬兩種UDP的流量模式: 1) 從client到server的單向批量傳輸 2) 請求/應(yīng)答的交易方式 由于UDP傳輸?shù)牟豢煽啃裕谑褂胣etperf時要確保發(fā)送的緩沖區(qū)大小不大于接收緩沖區(qū)大小,否則數(shù)據(jù)會丟失,netperf將給出錯誤的結(jié)果。因此,對于接收到分組的統(tǒng)計不一定準(zhǔn)確,需要結(jié)合發(fā)送分組的統(tǒng)計綜合得出結(jié)論。 Netperf的命令行參數(shù) 在unix系統(tǒng)中,可以直接運行可執(zhí)行程序來啟動netserver,也可以讓inetd或xinetd來自動啟動netserver。 當(dāng)netserver在server端啟動以后,就可以在client端運行netperf來測試網(wǎng)絡(luò)的性能。netperf通過命令行參數(shù)來控制測試的類型和具體的測試選項。根據(jù)作用范圍的不同,netperf的命令行參數(shù)可以分為兩大類:全局命令行參數(shù)、測試相關(guān)的局部參數(shù),兩者之間使用--分隔: netperf [global options]-- [test-specific options] 這里我們只解釋那些常用的命令行參數(shù),其它的參數(shù)讀者可以查詢netperf的man手冊。 -H host :指定遠端運行netserver的server IP地址。 -l testlen:指定測試的時間長度(秒) -t testname:指定進行的測試類型,包括TCP_STREAM,UDP_STREAM,TCP_RR,TCP_CRR,UDP_RR,在下文中分別對它們說明。 在后面的測試中,netserver運行在192.168.0.28,server與client通過局域網(wǎng)連接(100M Hub)。 Netperf測試網(wǎng)絡(luò)性能 測試批量(bulk)網(wǎng)絡(luò)流量的性能 批量數(shù)據(jù)傳輸?shù)湫偷睦佑衒tp和其它類似的網(wǎng)絡(luò)應(yīng)用(即一次傳輸整個文件)。根據(jù)使用傳輸協(xié)議的不同,批量數(shù)據(jù)傳輸又分為TCP批量傳輸和UDP批量傳輸。 1. TCP_STREAM Netperf缺省情況下進行TCP批量傳輸,即-t TCP_STREAM。測試過程中,netperf向netserver發(fā)送批量的TCP數(shù)據(jù)分組,以確定數(shù)據(jù)傳輸過程中的吞吐量: ./netperf -H 192.168.0.28 -l 60 TCP STREAM TEST to 192.168.0.28 Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec 87380 16384 16384 60.00 88.00 從netperf的結(jié)果輸出中,我們可以知道以下的一些信息: 1) 遠端系統(tǒng)(即server)使用大小為87380字節(jié)的socket接收緩沖 2) 本地系統(tǒng)(即client)使用大小為16384字節(jié)的socket發(fā)送緩沖 3) 向遠端系統(tǒng)發(fā)送的測試分組大小為16384字節(jié) 4) 測試經(jīng)歷的時間為60秒 5) 吞吐量的測試結(jié)果為88Mbits/秒 在缺省情況下,netperf向發(fā)送的測試分組大小設(shè)置為本地系統(tǒng)所使用的socket發(fā)送緩沖大小。 TCP_STREAM方式下與測試相關(guān)的局部參數(shù)如下表所示:
通過修改以上的參數(shù),并觀察結(jié)果的 。
posted @
2013-01-21 12:31 David1228 閱讀(459) |
評論 (0) |
編輯 收藏
使用httpd時候碰到一個問題,共享一下。
BC-EC配置tomcat的時候占用8443端口,如果tomcat服務(wù)器又作為http服務(wù)器,啟動httpd服務(wù)的時候就報錯,8443端口被占用。反過來httpd占用8443,tomcat啟動就報錯。
解決辦法:
編輯 /etc/httpd/conf.d/nss.conf配置文件,將該文件中的
nss.conf:Listen 8443
nss.conf:<VirtualHost _default_:8443>
改成
nss.conf:Listen 8444
nss.conf:<VirtualHost _default_:8444>
這樣啟動httpd和tomcat就互不影響了。
posted @
2013-01-18 11:22 David1228 閱讀(2733) |
評論 (0) |
編輯 收藏
--------------------------- 下面是在不啟動虛機的情況下,修改虛機磁盤文件的方法(增加一種調(diào)試的手段) ---------------------------------
-- 首先關(guān)閉虛機
# losetup /dev/loop100 /one_images/5/images/disk.0
# kpartx -a /dev/loop100
-- 通過以上兩個命令后,可以在/dev/mapper/目錄下看到虛機的兩個分區(qū)設(shè)備 loop100p1、loop100p2 (一般loop100p1是根分區(qū))(loop設(shè)備找一個空閑的即可,我這里寫的是loop100)
# mount /dev/mapper/loop100p1 /mnt
-- 將虛機根分區(qū)掛載到/mnt目錄,這時虛機的文件系統(tǒng)結(jié)構(gòu)就都在/mnt目錄下了(可以進行讀寫操作)
# umount /mnt
# kpartx -d /dev/loop100
# losetup -d /dev/loop100
-- 通過以上三個命令卸載,重新啟動虛機,修改都生效了。(測試虛機系統(tǒng)centos-5.5-x86_64)
posted @
2013-01-18 11:21 David1228 閱讀(397) |
評論 (0) |
編輯 收藏
記錄下,轉(zhuǎn)自:
http://blog.csdn.net/wonderful19891024/article/details/6166264
主機自帶硬盤超過300GB,目前只劃分使用了3個主分區(qū),不到70GB,如 下:
[root@db2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 29G 3.7G 24G 14% /
/dev/sda2 29G 22G 5.2G 81% /oracle
tmpfs 2.0G 0 2.0G 0% /dev/shm
[root@db2 ~]# cat /proc/partitions
major minor #blocks name
8 0 311427072 sda
sda1
8 2 30716280 sda2
8 3 8193150 sda3
8 16 976896 sdb
8 32 976896 sdc
現(xiàn)在需要給系統(tǒng)添加1個100GB的空間存放數(shù)據(jù)文件,而又不影響現(xiàn)有系統(tǒng)上業(yè)務(wù)的運行,
使用fdisk結(jié)合partprobe命令不重啟系統(tǒng)添加 一塊新的磁盤分區(qū)。操作步驟如下:
第1步,添加新的磁盤分區(qū)
[root@db2 ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 38770.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sda: 318.9 GB, 318901321728 bytes
255 heads, 63 sectors/track, 38770 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 3824 30716248+ 83 Linux
/dev/sda2 3825 7648 30716280 83 Linux
/dev/sda3 7649 8668 8193150 82 Linux swap / Solaris
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Selected partition 4
First cylinder (8669-38770, default 8669):
Using default value 8669
Last cylinder or +size or +sizeM or +sizeK (8669-38770, default 38770): +100G
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16:
Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@db2 ~]#
第2步,使用工具partprobe讓kernel讀取分區(qū)信息
[root@db2 ~]# partprobe
使用fdisk工具只是將分區(qū)信息寫到磁盤,如果需要mkfs磁盤分區(qū)則需要重啟系統(tǒng),
而使用partprobe則可以使kernel重新讀取分區(qū) 信息,從而避免重啟系統(tǒng)。
第3步,格式化文件系統(tǒng)
[root@db2 ~]# mkfs.ext3 /dev/sda4
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
12222464 inodes, 24416791 blocks
1220839 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
746 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632,
2654208, 4096000, 7962624, 11239424, 20480000, 23887872
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@db2 ~]#
第4步,mount新的分區(qū)/dev/sda4
[root@db2 ~]# e2label /dev/sda4 /data
[root@db2 ~]# mkdir /data
[root@db2 ~]# mount /dev/sda4 /data
[root@db2 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 29753556 3810844 24406900 14% /
/dev/sda2 29753588 11304616 16913160 41% /oracle
tmpfs 2023936 0 2023936 0% /dev/shm
/dev/sda4 96132968 192312 91057300 1% /data
[root@db2 ~]#
posted @
2012-11-29 14:56 David1228 閱讀(382) |
評論 (0) |
編輯 收藏
個人說明:以下作者應(yīng)該是在Ubuntu OS上做的測試。 感謝作者vpsee。
本人在公司的Red Hat Enterprise Linux Server release 6.1 (Santiago) 服務(wù)器上做的測試,可參見最下面截圖,監(jiān)控Tomcat和其他日志信息。很是方便哈^^.
由于Redhat OS上沒有apt-get,如果缺少相應(yīng)軟件包,可以通過yum或者iso源方式安裝缺少的軟件。
轉(zhuǎn)自:
http://www.vpsee.com/2012/11/install-real-time-log-monitoring-tool-log-io/#comments 日志是個好東西,對技術(shù)人員來說寫日志能紀(jì)錄成長,分享經(jīng)驗;對機器來說紀(jì)錄日志能及時發(fā)現(xiàn)錯誤,為日后的排錯提供信息。如果還在一臺機器上用 tail -f 監(jiān)聽單個日志或者用 multitail 監(jiān)聽多個日志也太 out 了,我們需要一種工具能紀(jì)錄上百臺機器、不同類型的日志,并最好能匯集到一個界面里方便查看,最好還是實時的。log.io 就是這樣一個實時日志監(jiān)控工具,采用 node.js + socket.io 開發(fā),使用瀏覽器訪問,每秒可以處理超過5000條日志變動消息。有一點要指出來的是 log.io 只監(jiān)視日志變動并不存儲日志,不過這個沒關(guān)系,我們知道日志存儲在哪個機器上。
posted @
2012-11-06 15:49 David1228 閱讀(2198) |
評論 (0) |
編輯 收藏
RHEL6 已經(jīng)推出很久了 ,沒想到在 RedHat 自家的 RHEL6 上安裝 KVM 還有這么多問題,難道不應(yīng)該是像 Apache/MySQL 那樣安裝完就可以用的么?(注:除去商標(biāo),CentOS 就是 RHEL,CentOS6 和 RHEL6 是一回事)。以下操作在 CentOS 6.2 最小化安裝版本 CentOS-6.2-x86_64-minimal.iso 上完成,其他版本可能不會遇到本文提到的部分問題。檢查 CPU
和 Xen 不同,KVM 需要有 CPU 的支持(Intel VT 或 AMD SVM),在安裝 KVM 之前檢查一下 CPU 是否提供了虛擬技術(shù)的支持:
# egrep 'vmx|svm' /proc/cpuinfo ... flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 sse4_2 popcnt aes lahf_lm ida arat dts tpr_shadow vnmi flexpriority ept vpid
安裝 KVM
安裝 KVM 很容易,要正常運行的話還需要折騰一下:
# yum -y install qemu-kvm libvirt python-virtinst bridge-utils
安裝完后關(guān)閉 selinux 并重啟系統(tǒng),然后確認(rèn)一下是否 kvm 安裝成功:
# vi /etc/sysconfig/selinux SELINUX=disabled # reboot # lsmod | grep kvm kvm_intel 50412 3 kvm 305988 1 kvm_intel # stat /dev/kvm File: `/dev/kvm' Size: 0 Blocks: 0 IO Block: 4096 character special file Device: 5h/5d Inode: 10584 Links: 1 Device type: a,e8 Access: (0666/crw-rw-rw-) Uid: ( 0/ root) Gid: ( 36/ kvm) Access: 2012-04-18 16:00:46.276341129 +0200 Modify: 2012-04-18 16:00:46.276341129 +0200 Change: 2012-04-18 16:00:46.276341129 +0200
再來確認(rèn)一下 libvirt 是否能正常啟動和關(guān)閉。重啟 libvirtd 服務(wù)的話會報錯,查看日志發(fā)現(xiàn) internal error Failed to create mDNS client 錯誤,這個問題容易改正,安裝 avahi 即可,也可以去 /etc/libvirt/libvirtd.conf 設(shè)置 mdns_adv = 0,VPSee 這里采用安裝 avahi 的方法:
# /etc/init.d/libvirtd restart Stopping libvirtd daemon: [FAILED] Starting libvirtd daemon: [ OK ] # tail /var/log/libvirt/libvirtd.log 2012-04-18 13:51:03.032+0000: 18149: info : libvirt version: 0.9.4, package: 23.el6_2.7 (CentOS BuildSystem , 2012-04-16-14:12:59, c6b5.bsys.dev.centos.org) 2012-04-18 13:51:03.032+0000: 18149: error : virNetServerMDNSStart:460 : internal error Failed to create mDNS client: Daemon not running # yum -y install avahi # /etc/init.d/messagebus restart # /etc/init.d/avahi-daemon restart
重啟 libvirtd 服務(wù)繼續(xù)報錯,發(fā)現(xiàn)缺少 dmidecode 包,安裝 dmidecode 后終于重啟 libvirtd 成功 :
# /etc/init.d/libvirtd restart Stopping libvirtd daemon: [FAILED] Starting libvirtd daemon: [ OK ] # tail /var/log/libvirt/libvirtd.log 2012-04-18 13:54:54.654+0000: 18320: info : libvirt version: 0.9.4, package: 23.el6_2.7 (CentOS BuildSystem , 2012-04-16-14:12:59, c6b5.bsys.dev.centos.org) 2012-04-18 13:54:54.654+0000: 18320: error : virSysinfoRead:465 : internal error Failed to find path for dmidecode binary # yum -y install dmidecode # /etc/init.d/libvirtd restart Stopping libvirtd daemon: [ OK ] Starting libvirtd daemon: [ OK ]
現(xiàn)在 kvm 和 libvirt 都安裝成功和運行了,但并不表示可用了,問題接著來。
安裝虛擬機
從 6 系列開始 RedHat 推薦使用 virt-install/virsh 系列工具操作 kvm,而不是直接使用 qemu-kvm,所以 qemu-kvm 被移到一個不起眼的地方 /usr/libexec/,做個鏈接:
# qemu-kvm -bash: qemu-kvm: command not found # ls /usr/libexec/qemu-kvm /usr/libexec/qemu-kvm # ln -sf /usr/libexec/qemu-kvm /usr/bin/kvm
VPSee 采用 RedHat 推薦的方式(virt-install)安裝虛擬機,這里以安裝 ubuntu-11.10-server-amd64.iso 為例:
# virt-install \ --name ubuntu \ --ram 512 \ --vcpus=1 \ --disk path=/root/ubuntu.img,size=10 \ --accelerate \ --cdrom /root/ubuntu-11.10-server-amd64.iso \ --graphics vnc
開始安裝,創(chuàng)建硬盤 ubuntu.img 后就報錯,用的是 root 帳號居然還 Permission denied?!
Starting install... Creating storage file ubuntu.img | 10.0 GB 00:00 ERROR internal error Process exited while reading console log output: char device redirected to /dev/pts/1 qemu-kvm: -drive file=/root/ubuntu.img,if=none,id=drive-ide0-0-0,format=raw,cache=none: could not open disk image /root/ubuntu.img: Permission denied Domain installation does not appear to have been successful. If it was, you can restart your domain by running: virsh --connect qemu:///system start ubuntu otherwise, please restart your installation.
修改 qemu.conf 配置,把下面幾個地方的注釋去掉,然后把 dynamic_ownership 的值改成0,禁止 libvirtd 動態(tài)修改文件的歸屬:
# vi /etc/libvirt/qemu.conf ... user = "root" group = "root" dynamic_ownership = 0 ...
重啟 libvirtd 服務(wù)再用上面的 virt-install 命令安裝就應(yīng)該可以了。這個時候 vnc 默認(rèn)綁定的是本機 127.0.0.1,如果其他機器想用 vnc 客戶端訪問這臺 kvm 服務(wù)器正在安裝的 ubuntu 的話需要把 vnc 綁定到服務(wù)器的 IP 地址或者綁定到全局 0.0.0.0. 修改 qemu.conf 文件取消 vnc_listen 一行前面的注釋,記得重啟 libvirtd:
# vi /etc/libvirt/qemu.conf ... vnc_listen = "0.0.0.0" ...
轉(zhuǎn)載自:
http://www.vpsee.com/?s=qemu.conf
posted @
2012-10-31 13:59 David1228|
編輯 收藏