顯示具有 Solaris 標籤的文章。 顯示所有文章
顯示具有 Solaris 標籤的文章。 顯示所有文章

2013年11月20日 星期三

shell scripts for file checking at day-changed(solaris)

> su - user
> vi /home/user/meter.sh
#!/bin/bash
mday=`date +%d`
cday=`date +%Y-%m-%d`
npath="/its/cts/dat/logs/mlog/$mday"
nfile="$npath/xync.log"
#fday=`stat --format="%y" $nfile | cut -f1 -d" "`
#ls -E /etc/hosts | awk '{print $6}'| sed 's#-##g'

if [ -e $nfile ]; then
    fday=`ls -E $nfile | awk '{print $6}'` >/dev/null 2>&1
if [ $fday = $cday ]; then
    date "+%Y/%m/%d %H:%M:%S -- ...   --" >> $nfile
else
    date "+%Y/%m/%d %H:%M:%S -- Start --" > $nfile
fi

else
    date "+%Y/%m/%d %H:%M:%S -- Start --" > $nfile
fi

> chmod 755 /home/user/meter.sh
> crontab -e
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,
29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54
,55,56,57,58,59 * * * * /home/user/meter.sh 2>>/tmp/meter.log 1>>/tmp/mete
r.log

2010年11月9日 星期二

Solaris process crashed debug 範例


Solaris process crashed debug 範例

DEV901 /export/spare/cts>coreadm -e process
coreadm�G�z������ root �~������ -[giedu] �ﶵ 必須用root
DEV901 /export/spare/cts>su -
Password:
#Sun Microsystems Inc. SunOS 5.8 Generic Patch December 2002
DEV901 />coreadm -e process
DEV901 />exit

DEV901 /export/spare/cts>vi crashed.c
"crashed.c" 10 ��, 139 �Ӧr��
#include
int main(int argc, char* argv[])
{
int *a=0;
printf("start...\n");
printf("%s",a); crashed 的地方

return 0;
}

~
~
"crashed.c" 10 ��, 148 �Ӧr��
-g參數確保pstack 可以查出問題所在
DEV901 /export/spare/cts>cc -o crashed crashed.c –g  
ELF的檔案類型
DEV901 /export/spare/cts>file crashed
crashed: ELF 32-�줸 MSB �i���� SPARC ���� 1, �ʺA�s��, �����h DEV901 /export/spare/cts>./crashed
start...
Segmentation Fault (core dumped)      產生core file了

DEV901 /export/spare/cts>coreadm
�����֤��ɮ׹ϼˡG/var/core/core.%f.%p
init �֤��ɮ׹ϼˡGcore.%f
�����֤߶ɦL�Gdisabled
�C�ӳB�z�֤߶ɦL�Genabled       確認會產生core file
���� setid �֤߶ɦL�Gdisabled
�C�ӳB�z setid �֤߶ɦL�Gdisabled
�����֤߶ɦL�O���Gdisabled
DEV901 /export/spare/cts>cat /etc/coreadm.conf
#
# coreadm.conf
#
# Parameters for system core file configuration.
# Do NOT edit this file by hand -- use coreadm(1) instead.
#
COREADM_GLOB_PATTERN=/var/core/core.%f.%p
COREADM_INIT_PATTERN=core.%f 產生core file檔名
COREADM_GLOB_ENABLED=no
COREADM_PROC_ENABLED=yes 確認會產生core file
COREADM_GLOB_SETID_ENABLED=no
COREADM_PROC_SETID_ENABLED=no
COREADM_GLOB_LOG_ENABLED=no


DEV901 /export/spare/cts>ls -l core.crashed
-rw------- 1 cts staff 80360 11�� 9 11:16 core.crashed
DEV901 /export/spare/cts>pstack core.crashed
core 'core.crashed' of 23061: ./crashed
這個位置發生core dump
ff2b3218 strlen (0, ffbefad0, 0, ff33f789, 0, 10702) + 80
ff308188 printf (10700, ff340284, ff343a54, 0, 22318, ff29bc20) + f4
000106a8 main (1, ffbefb54, ffbefb5c, 20800, 0, 0) + 30
00010650 _start (0, 0, 0, 0, 0, 0) + 108
DEV901 /export/spare/cts>pmap core.crashed
core 'core.crashed' of 23061: ./crashed
00010000 8K read/exec /export/spare/cts/crashed
00020000 8K read/write/exec /export/spare/cts/crashed
相對於symbol table的位置,應該在FF280000之後
FF280000 688K read/exec /usr/lib/libc.so.1
FF33C000 32K read/write/exec /usr/lib/libc.so.1
FF380000 8K read/write/exec /usr/lib/libdl.so.1
FF390000 8K read/exec /usr/platform/sun4u-us3/lib/libc_psr.so.1
FF3A0000 176K read/exec /usr/lib/ld.so.1
FF3DC000 8K read/write/exec /usr/lib/ld.so.1
FF3DE000 8K read/write/exec /usr/lib/ld.so.1
FFBEE000 8K read/write/exec [ stack ]
total 952K

DEV901 /export/spare/cts>elfdump -s /usr/lib/libc.so.1 | grep strlen
[1965] 0x00033198 0x000000f0 FUNC GLOB D 30 .text strlen
[723] 0x00000000 0x00000000 FILE LOCL D 0 ABS strlen.s
[2129] 0x0007c6b4 0x0000002c FUNC LOCL D 0 .text mini_strlen
[4677] 0x00033198 0x000000f0 FUNC GLOB D 0 .text strlen
0xFF280000 + 0x00033198 + 80 = 0xFF2b3218
從上面可以看到,strlen crashed的位置是如何被找出來的。從pstack可以得到0xFF2b3218,透過pmap找出symbol table中,crashed的base address應該落於0xFF280000(屬於libc.so.1),因為libc.so.1以及./crashed都是ELF檔案,所以用elfdump找出其中的symbol位置,最後發現在0x0033198。而因為pstack有再記載crashed address是位在其base address所在symbol再+0x80之偏移量,所以算出這樣結果。(也就是global strlen()是發生問題所在,但並不表示他有BUG)

Core & Dump @ Solaris (2)


pstack, coreadm and symbol tables
Where symbol names come from?
In ELF files, symbols reside in two sections: .symtab and .dynsym.

On recent versions of Solaris, there is a new section, .SUNW_ldynsym, but for the purpose of this article it is identical to .dynsym, so I'll keep it simple and not talk about it.

Both sections are essentially tables that map name to a value; here we are interested in function names, so that value would be function address. When pstack unwinds the stack (starting from value of $pc and $fp/$sp registers that comes from special NOTE segment of core file), it goes through symbol tables of all files involved and find symbol with closest value.

For example, suppose we have this core file:

$ pstack core
core 'core' of 7719: ./a.out
fece586c strlen (8050ada, 8047a38, fed91c20, 0) + c
fed40814 printf (8050ad8, 0) + a8
08050969 ???????? (0, 8047b30, 8047a84, 80508bd, 1, 8047a90)
080509a2 main (1, 8047a90, 8047a98, fed93e40) + 12
080508bd _start (1, 8047b98, 0, 8047ba0, 8047bdc, 8047be7) + 7d
fece586c address belongs to libc.so.1 as can be seen from pmap(1) output:

$ pmap core
core 'core' of 7719: ./a.out
08046000 8K rwx-- [ stack ]
08050000 4K r-x--
08060000 4K rwx--
08061000 128K rwx-- [ heap ]
>>>FECC0000 760K r-x-- /lib/libc.so.1 <<<
FED8E000 32K rw--- /lib/libc.so.1
FED96000 8K rw--- /lib/libc.so.1
...
It is in code segment (r-x-- permissions gave that away) of /lib/libc.so.1.

Looking at libc.so.1 with elfdump we can see that global function strlen starts at offset 0x25860

$ elfdump -s /usr/lib/libc.so.1 | grep strlen
[2603] 0x00025860 0x00000045 FUNC GLOB D 37 .text strlen
So in our passed away process it would reside at 0xFECC0000 (base address of libc.so.1 in memory) + 0x25860 = 0xFECE5860. Hence 0xfece586c is 0xFECE5860+0xc, which is strlen+0xc

Symbol tables
As you can see in the above example, not all symbols were found. In this case, address 0x08050969 was not mapped to any symbol. That address belongs to a.out code segment starting at 0x08050000 and that's all we can tell. Yet the other symbol from the same segment is visible: main at 0x080509a2.

The difference is because those two symbols were present in different symbol tables while executable files are permitted to have only one: .dynsym (strictly speaking, that probably applies to dynamic executables only, but since Solaris 10 strongly discourages static linking, so we almost always have to deal with dynamic executables and shared libraries). This .dynsym section is used by run-time linker (ld.so.1(1)) and contains global names that program "exports" or "imports" from libraries; call to "main" is resolved at run time by looking up name "main" in .dynsym section and jumping to address associated with symbol found. Since this information is absolutely necessary at run time, .dynsym section always resides in a loadable segment and is always a part of process memory image (and thus a core file).

On the other hand, .symtab section that contains all symbols - including local ones - was useful mostly when linking relocatable object files (*.o). References inside one file can be resolved at compile time using offsets, so static functions does not have to have a name at run time, they are called directly using offset from current position. This is why .symtab section does not belong to a loadable segment and does not contribute to process' memory image in any way. And this is why it [used to be] customary to remove symbol table from final executables (using strip(1), for example) to save space and make life of support engineers harder.

In our case, ./a.out was indeed stripped:

$ elfdump -c a.out | grep symtab
$ elfdump -c a.out | grep dynsym
Section Header[4]: sh_name: .dynsym
It does have .dynsym, but no .symtab. By the way, main symbol indeed is present in .dynsym and has address 0x08050990:

$ elfdump -s -N .dynsym a.out | grep main
[28] 0x08050990 0x0000001a FUNC GLOB D 0 .text main
Loadable objects (executables and shared libraries)
Let's recompile a.out and see how it helps:

$ CC510 a.cc
$ ./a.out
Segmentation Fault (core dumped)
$ pstack core
core 'core' of 11761: ./a.out
fece586c strlen (8050ada, 8047a38, fed91c20, 0) + c
fed40814 printf (8050ad8, 0) + a8
08050969 __1cDfoo6F_i_ (0, 8047b30, 8047a84, 80508bd, 1, 8047a90) + 19
080509a2 main (1, 8047a90, 8047a98, fed93e40) + 12
080508bd _start (1, 8047b98, 0, 8047ba0, 8047bdc, 8047be7) + 7d
We now can see name __1cDfoo6F_i_ (mangled name of int foo()) instead of ???, but where would pstack get this information? __1cDfoo6F_i_ is not present in .dynsym, so it there was not information about this name in memory image of the process when it died:

$ strings core | grep __1cDfoo6F_i_
pstack(1) is smarter that that: it finds out which program generated this core file, locates it and uses its .symtab (if present, of course) to map symbols. Here's an excerpt from proc(1):

Some of the proc tools can need to derive the name of the
executable corresponding to the process which dumped core or
the names of shared libraries associated with the process.
These files are needed, for example, to provide symbol table
information for pstack(1). If the proc tool in question is
unable to locate the needed executable or shared library,
some symbol information is unavailable for display.
Let's delete a.out and see what happens:

$ rm a.out
$ pstack core
core 'core' of 11761: ./a.out
fece586c strlen (8050ada, 8047a38, fed91c20, 0) + c
fed40814 printf (8050ad8, 0) + a8
08050969 ???????? (0, 8047b30, 8047a84, 80508bd, 1, 8047a90)
080509a2 main (1, 8047a90, 8047a98, fed93e40) + 12
080508bd _start (1, 8047b98, 0, 8047ba0, 8047bdc, 8047be7) + 7d
We immediately got our ???'s back.

So pstack uses core file and executable/libraries as well in order to print readable names in stack trace.

Core file contents
If you have to send your core file to another person for inspection, you have him at a disadvantage: that person might not have your executable and even system libraries might be slightly different. If pstack would go look for address-to-symbol mapping there, it might end up printing wrong symbol names and question marks, making core file more harmful than helpful.

There is a way to embed symbol tables into the core file - using coreadm(1M) command. It allows to specify what kind of content you want the system to put into core file and it can even direct the system to pull .symtab from executable and shared libraries:

$ coreadm -I default+symtab(do this under root).
More information on coreadm can be found in its man page: coreadm(1M).

Side note: in fact, symbol tables of libc.so.1 and ld.so.1 were present in my core file even without "symtab" content requested as can be seen by elfdump -c core; seems to be an undocumented, but useful feature.

Let's turn .symtab inclusion on and see how if it helps:

$ su -
# coreadm -I default+symtab
# exit
$ ./a.out
Segmentation Fault (core dumped)
$ rm a.out
$ pstack core
core 'core' of 13604: ./a.out
fece586c strlen (8050ada, 8047a38, fed91c20, 0) + c
fed40814 printf (8050ad8, 0) + a8
08050969 __1cDfoo6F_i_ (0, 8047b30, 8047a84, 80508bd, 1, 8047a90) + 19
080509a2 main (1, 8047a90, 8047a98, fed93e40) + 12
080508bd _start (1, 8047b98, 0, 8047ba0, 8047bdc, 8047be7) + 7d
Core file now contains many symbol tables, one per loadobject:

$ elfdump -c core | grep symtab
Section Header[1]: sh_name: .symtab
Section Header[3]: sh_name: .symtab
Section Header[6]: sh_name: .symtab
Section Header[8]: sh_name: .symtab
Section Header[10]: sh_name: .symtab
Section Header[12]: sh_name: .symtab
and one of them has definition of our int foo() function that starts at 0x08050950:

$ elfdump -s core | grep foo
[56] 0x08050950 0x00000034 FUNC LOCL D 0 __1cDfoo6F_i_
How to prevent ??? to appear in stack trace?
Use pstack on the same machine
First and foremost, you can avoid many problems by first using pstack on the same machine where core file was generated. This will ensure that pstack uses the same binary and libraries as the process that generated core. Otherwise, you might end up looking at wrong symbols or (in the best case) a lot of question marks.

Don't strip binaries
In Solaris, it is no longer customary to strip binaries (see http://blogs.sun.com/ali/entry/which_solaris_files_are_stripped). Space savings are questionable and performance of unstripped binary does not suffer, so why having lives of those who will debug it difficult?

Don't delete binaries
By default, Solaris does not include .symtab into core files (except for libc.so and ld.so as I mentioned earlier, but that is not relevant here when we talk about user executables and libraries). So if you delete or move executable/library after core file was generated, pstack won't be able to find its .symtab and thus map addresses to local function names.

In other words, unless you've changed core file contents with coreadm(1M), don't delete your binaries before you have a chance to inspect core file. They are needed.

Use coreadm
Most of problems above can be eliminated with one blow:

# coreadm -I default+symtabThis tells the system to pull .symtab sections from every binary involved in the process and put them into core file. You no longer need binaries to see names instead of numbers in stack trace.



Core & Dump @ Solaris


managing crash dumps and core files
当操作系统崩溃的时候,savecore命令在启动的时候自动执行,并将内核信息存放在/var/crash/nodename/vmcore.X文件里面,将名字列表存放在/var/crash/nodename/unix.X文件里面.
在crash dump目录下,还创建了一个bounds的文件
# dumpadm
# cat /etc/dumpadm.conf
注意尽量使用dumpadm命令而避免直接编辑/etc/dumpadm.conf文件
dumpadm的一般语法格式是:
/usr/sbin/dumpadm [nuy] [-c content-type] [-d dump-device] [-m mink| minm| min%]
[-r root-dir] [-s savecore-dir]
其中-n是禁止重启之后自动运行savecore命令,-u是执行更新,-y是允许重启之后自动运行savecore命令.content-type包括三种类型:kernel,all,curproc.-r是指定根目录,如果没有这个参数那么默认是"/"目录.
当一个core文件发生的时候,要创建两个core文件的副本,分别是global core file,per-process core file,global core file只有root用户可以操作.后一个文件只有所有者可以操作.
# coreadm
# cat /etc/coreadm.conf
带-p参数的coreadm命令任何用户都可以使用,而带其他参数的coreadm命令则只有root用户可以使用.
coreadm -i pattern命令和coreadm -p pattern命令大同小异,区别在于前者在系统重启之后才生效.coreadm -i pattern命令的作用是设定per-process core文件名模式
coreadm -e包含四项:global,process,global-setid,proc-setid,log
coreadm -d:让设定的选项失效
coreadm -u:更新
coreadm -g pattern:设定global core文件名模式

使用coreadm命令p选项的一些参数:
%u:EUID;%g:EGID;%f:可执行文件名;%n:系统标示名;%m:机器硬件名;%t:自1970.1开始运行的秒数
$$ shell's pid
使用coreadm命令的一些实例:
# coreadm -p core.%f.%p $$
# coreadm -p $HOME/corefiles/%n.%f.%p $$
# coreadm -g /var/core/core.%f.%P -e global
# coreadm 278 5678


1 Core
core檔是系統軟體出現問題後產生的資訊記錄。它對軟體發展者和系統管理者的工作有很大的幫助作用。本節主要對Core檔產生和管理做一些初步介紹。

(1) 管理core文件概述
core檔在進程或者應用程式異常終止時產生。我們可以使用coreadm命令來管理core檔。比如,你可以使用coreadm命令來設定所有的core檔都放在一個目錄中。這樣,就會很容易通過測試找到問題的痕跡。

有兩種類型的core檔:

單個進程的core檔,在默認情況下是啟動的。當進程異常終止時,單個進程的core檔就在異常終止進程的目錄中產生。產生後,單個進程的core檔的擁有者就是進程的擁有者。只有擁有者才能查看這個檔。
全局core檔,它默認的情況下是不開啟的。如果啟動了全局core檔,它產生在引起全局core檔產生的目錄。全局core文件的擁有者就是超級用戶。非特權用戶不能查看全局core檔。
當進程異常終止時,默認在當前目錄產生core檔。如果這時全局core檔路徑也開啟著,每個異常終止的進程就會有兩個檔產生:一個在當前的工作目錄;另一個在全局core檔目錄。
默認時,setuid進程既不產生全局core檔也不產生單個core檔。
如果全局core檔是開啟的,core檔可以用表17-3中的變數所描述。

表17-3 描述Core檔的變數

變 量 名 變數描述
%d 執行的檔目錄名
%f 執行的檔案名
%g 組的ID
%m 機器名稱
%n 系統節點名
%p 進程ID
%t 十進位的時間
%u 有效的用戶ID
%z 進程運行的分區(xone)名
%% 百分比


舉例說明,全局core檔路徑設置為:

/var/core/core.%f.%p

這時,如果sendmail的PID為12345的進程發生異常終止,將產生下列core檔:

/var/core/core.sendmail.12345

我們可以使用coreadm命令設定進程產生的core檔的目錄和名稱。這將取代原來的默認設置。

# coreadm -i /var/core/core.%f.%p

全局core的屬性值存儲在/etc/coreadm.conf文件中。

(2) 管理core檔的實例

1.顯示當前core檔的設置
例17-2 使用不帶任何參數的coreadm命令顯示當前core的設置情況。

$ coreadm
global core file pattern:
global core file content: default
nit core file pattern: core
init core file content: default
global core dumps: disabled
per-process core dumps: enabled
global setid core dumps: disabled
per-process setid core dumps: disabled
global core dump logging: disabled

2.設置core檔案名的樣式
將當前Shell運行的所有進程所產生的core檔命名:

$ coreadm -p $HOME/corefiles/%f.%p $$
對全局檔設置core檔命名需要超級用戶許可權:
# coreadm -g /var/corefiles/%f.%p

3.啟用單個進程core檔的路徑
# coreadm -e process
$ coreadm $$
1180: /home/kryten/corefiles/%f.%p

4.啟用全局core檔的路徑
# coreadm -e global -g /var/core/core.%f.%p

(3) 查詢core檔資訊
一些proc工具可以像檢測活動的進程一樣檢測core檔。比如,/usr/proc/bin/pstack、pmap、pldd、pflags和pcred工具能管理core文件。更詳細的資訊請查看porc(1)的幫助。

例17-3 使用proc工具檢查core檔。
$ ./a.out
Segmentation Fault(coredump)
$ /usr/proc/bin/pstack ./core
core ’./core’ of 19305: ./a.out
000108c4 main (1, ffbef5cc, ffbef5d4, 20800, 0, 0) + 1c
00010880 _start (0, 0, 0, 0, 0, 0) + b8 

2 系統crash資訊的管理

crash主要回饋主機能否正常運行等比較嚴重的問題。系統管理員需要特別關注crash資訊。
(1) 系統崩潰概述
系統崩潰(crash)發生在硬體故障、I/O問題或軟體錯誤的情況下。如果系統崩潰發生了,它將在控制臺上顯示錯誤資訊,並將實體記憶體的拷貝寫入轉儲設備。這時,系統將自動重新啟動。當系統重啟後,savecore 命令運行將資料從轉儲設備中找回,並存儲到savecore目錄。這些資料為系統診斷提供了依據。

系統崩潰轉儲檔
當savecore命令自動運行將崩潰資訊從轉儲設備中找回,並寫成兩個檔:unix.X和vmcore.X。其中X為轉儲的次序號碼。這些檔一起用於表現系統的崩潰轉儲資訊。
崩潰轉儲檔存儲在預先設定好的目錄中,默認情況下是/var/crash/hostname。在以前的Solaris版本中,崩潰轉儲檔將在系統重新啟動的時候不寫在特定的目錄,除非你手動啟動,將記憶體的映射存儲到崩潰轉儲檔中。不過現在就自動存儲崩潰轉儲檔了。

dumpadm命令
我們可以用dumpadm命令來在Solaris系統中管理系統崩潰轉儲資訊。
dumpadm命令能使你在作業系統上設置崩潰轉儲。這個命令的設置參數包括轉儲的內容、轉儲的設備和崩潰轉儲資訊的存儲路徑。
轉儲資料是以壓縮的形式被存在轉儲設備中的。內核的崩潰轉儲映射可能達到4GB,壓縮資料就意味著更快的轉儲速度和更小的轉儲設備磁碟空間。
保存崩潰轉儲檔是在後臺運行的崩潰轉儲檔的任務。系統啟動的時候不需要等待savecore命令完成就可以進行下一步。當然,大的記憶體數量是有利於savecore完成任務的。
系統崩潰轉儲檔是由savecore命令產生的,保存一般也是按默認路徑進行的。
savecore –L命粗體令是新的屬性,它使你能在系統運行的時候崩潰轉儲。當系統記憶體存儲有問題的時候,這個命令試圖在系統運行的時候調試記憶體的快照。如果系統是啟動的,並且有些命令還能執行,你可以運行cavecore –L命令來存儲系統轉儲設備的快照到崩潰轉儲目錄。

通過dumpadm命令,轉儲設置參數存儲在/etc/dumpadm.conf文件中。注意不要手動編輯這個檔,這樣做可能會帶來不一致的轉儲設置。

dumpadm命令如何工作
當系統啟動的時候,dumpadm命令調用svc:/system/dumpadm:default服務來設置基於/etc/dumpadm.conf文件的的崩潰轉儲參數。

dumpadm命令通過/dev/dump介面來初始化轉儲設備和轉儲內容。

(2) 管理系統崩潰轉儲資訊

在管理系統崩潰資訊中,你必須要記住以下幾點:
你必須是超級用戶或具有管理系統崩潰功能的用戶。
不要關閉保存崩潰轉儲資訊的屬性。系統崩潰轉儲檔提供了導致系統崩潰的很珍貴的資訊。
不要輕易刪除系統崩潰資訊。

1.如何顯示當前的崩潰轉儲設置
# dumpadm
Dump content: kernel pages
Dump device: /dev/dsk/c0t3d0s1 (swap)
Savecore directory: /var/crash/venus
Savecore enabled: yes

上面輸出的意義如下:
轉儲內容是內核記憶體的換頁。
內核記憶體將轉儲到swap設備中,就是/dev/dsk/c0t3d0s1。
系統崩潰轉儲檔存在/var/crash/venus目錄。
系統的崩潰轉儲功能是啟動著的。

2.如何修改當前的崩潰轉儲設置
命令介紹

# dumpadm -c content -d dump-device -m nnnk | nnnm | nnn% -n -s savecore-dir

dumpadm命令的各個參數具體意義列在表17-4中。

表17-4 dumpadm命令的參數列表

轉儲參數
描 述

-c content
轉儲的資料類型。默認的轉儲內容是內核的記憶體。使用all關鍵字是指所有記憶體

-d dump-device
系統崩潰時,臨時存儲的專門設備

-m nnnk | nnnm | nnn%
在savecore目錄中為了存儲崩潰轉儲檔所留的專門空間。這個參數有可能是kb(nnnk),也有可能mb(nnnm),也有可能是百分比(nnn%)

-n 或-y
是否自動進行崩潰轉儲,y為是,n為否

-s savecore-dir
用來改變崩潰轉儲檔的路徑。默認路徑是/var/crash/hostname


 例17-4 轉儲內容改為所有記憶體,轉儲目錄改為/dev/dsk/c0t1d0s1,轉儲空間最大為這個檔系統的10%。

先查看原來的轉儲設置:

# dumpadm
Dump content: kernel pages
Dump device: /dev/dsk/c0t3d0s1 (swap)
Savecore directory: /var/crash/pluto
Savecore enabled: yes

更改轉儲設置:

# dumpadm -c all -d /dev/dsk/c0t1d0s1 -m 10%
Dump content: all pages
Dump device: /dev/dsk/c0t1d0s1 (dedicated)
Savecore directory: /var/crash/pluto (minfree = 77071KB)
Savecore enabled: yes

3.如何檢查崩潰轉儲檔內容
例17-5 使用mdb工具輸出崩潰轉儲檔內容,其中包括系統資訊和在/etc/system檔中可調用的一些參數。

# /usr/bin/mdb -k unix.0
Loading modules: [ unix krtld genunix ip nfs ipc ptm ]
> ::status
debugging crash dump /dev/mem (64-bit) from ozlo
operating system: 5.10 Generic (sun4u)
> ::system
set ufs_ninode=0x9c40 [0t40000]
set ncsize=0x4e20 [0t20000]
set pt_cnt=0x400 [0t1024] 

2010年6月18日 星期五

solaris iscsi

本次實作,只是想要為公司在IDC的機器上省下一筆錢
實際環境是用Open Solaris建一個iscsi target server
然後試著用RHEL來抓這個server看看
由於RHEL應該鮮少作業系統有廣泛支援,得知Linux有support ZFS,所以就以Solaris的ZFS為主要Filesystem

ServerIP : 172.16.43.144 (OpenSolaris SunOS 5.10 @vmware)
ClientIP : 172.16.43.99 (RHEL 5.4 @dom0,建議使用此版本,因為kernel版本剛好有fuse支援)
在Server關機狀態下,先幫它加一個HDD(20G),加完後透過下面指令,
可以知道多了一筆記錄(new HDD c1t1d0)

1.查到HDD的ID
# format
Searching for disks...done


AVAILABLE DISK SELECTIONS:
0. c1t0d0
/pci@0,0/pci15ad,1976@10/sd@0,0
1. c1t1d0
/pci@0,0/pci15ad,1976@10/sd@1,0
Specify disk (enter its number):

2.為zfs建立storage pools
zfs的精神在於,要先建storage pool,再從pool抓來建立共用的Lun(以下注意,實作過程都沒有格式化)
# zpool create iscsi-1 c1t1d0

確認建立的結果
# zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
iscsi-1 19.9G 194K 19.9G 0% ONLINE -

建立一個zfs
# zfs create iscsi-1/public
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
iscsi-1 12.0G 7.56G 25.5K /iscsi-1
iscsi-1/public 12.0G 7.56G 24.5K /iscsi-1/public

3. 實作target server
把剛才抓出來的zfs利用iscsi共享出來,
(1)用這個方法共享,那這個zfs底下的所有Lun就會直接share至iscsi
也就是如果share在zfs,則底下的每個Lun就會直接被share至iscsi
# zfs set shareiscsi=on iscsi-1/public
建立第1個Lun
# zfs create -V 2g iscsi/public/sean
建立第2個Lun
# zfs create -V 10g iscsi/public/share
檢視結果
# iscsitadm list target
Target: iscsi-1/public/sean
iSCSI Name: iqn.1986-03.com.sun:02:cf6f7152-7468-4f02-e214-ff7d6784c92c
Connections: 0
Target: iscsi-1/public/share
iSCSI Name: iqn.1986-03.com.sun:02:15a4b01a-9fdf-4a42-ef74-e82a9cc81397
Connections: 0

(2)用這個方法共享,那這個每建一個Lun就要share一次
# zfs create -V 2g iscsi/public/sean
# zfs set shareiscsi=on iscsi-1/public/sean

共享設定完成後,接著要設定提供出來的iscsi管道
# iscsitadm create tpgt 1
1是target gruop id
在1這個target group設定pathing(連進來的都透過172.16.43.144這個網卡的IP)
# iscsitadm modify tpgt -i 172.16.43.144 1
如果要設定多網卡多IP(multi-pahting),那就上面的指令多敲幾個就好
確認設定結田
# iscsitadm list tpgt
TPGT: 1
IP Address count: 1

4.結果驗證,並確認RHEL可以抓得到
1)在OpenSolaris上看看target server shared狀態
# iscsitadm list target -v
Target: iscsi-1/public/sean
iSCSI Name: iqn.1986-03.com.sun:02:cf6f7152-7468-4f02-e214-ff7d6784c92c
Alias: iscsi-1/public/sean
Connections: 0
ACL list:
TPGT list:
LUN information:
LUN: 0
GUID: 0x0
VID: SUN
PID: SOLARIS
Type: disk
Size: 2.0G
Backing store: /dev/zvol/rdsk/iscsi-1/public/sean
Status: online
Target: iscsi-1/public/share
iSCSI Name: iqn.1986-03.com.sun:02:15a4b01a-9fdf-4a42-ef74-e82a9cc81397
Alias: iscsi-1/public/share
Connections: 0
ACL list:
TPGT list:
LUN information:
LUN: 0
GUID: 0x0
VID: SUN
PID: SOLARIS
Type: disk
Size: 10G
Backing store: /dev/zvol/rdsk/iscsi-1/public/share
Status: online
確認target server是不是開3260 port
# netstat -an | grep 3260
*.3260 *.* 0 0 49152 0 LISTEN
*.3260 *.* 0 0 49152 0 LISTEN

2)從RHEL上可以從下面操作來驗證
安裝iscsi套件
[root@localhost ~]# yum install iscsi-initiator-utils.i386 -y
啟動iscsi client服務
[root@localhost vlc-1.0.0-rc4]# service iscsid start
[root@localhost vlc-1.0.0-rc4]# chkconfig iscsid on
去找找到172.16.43.144是否真有提供iscsi
[root@localhost vlc-1.0.0-rc4]# iscsiadm --mode discovery --type sendtargets --portal 172.16.43.144
172.16.43.144:3260,1 iqn.1986-03.com.sun:02:cf6f7152-7468-4f02-e214-ff7d6784c92c
172.16.43.144:3260,1 iqn.1986-03.com.sun:02:15a4b01a-9fdf-4a42-ef74-e82a9cc81397

5.在RHEL上mount zfs

[root@localhost zfs]# ll
total 1468
-rwxrwxrwx 1 root root 1502751 Jun 18 16:27 zfs-fuse-0.6.0-6.el5.i386.rpm
[root@localhost zfs]# rpm -vih zfs-fuse-0.6.0-6.el5.i386.rpm
warning: zfs-fuse-0.6.0-6.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6
Preparing... ########################################### [100%]
1:zfs-fuse ########################################### [100%]
[root@localhost zfs]#

備註:fuse版表示Filesystem in UserSpacE,那麼就表示不在Kernel space執行的意思了

啟動zfs服務
[root@localhost zfs]# service zfs-fuse status
zfs-fuse is stopped
[root@localhost zfs]# service zfs-fuse start
Starting zfs-fuse: [ OK ]
Immunizing zfs-fuse against OOM kills [ OK ]
Mounting zfs partitions: chkco [ OK ]
[root@localhost zfs]# chkconfig zfs-fuse on
[root@localhost zfs]# service zfs-fuse status
zfs-fuse (pid 2387) is running...
no pools available
[root@localhost zfs]#

登入target server(target name的iqn在前面就discover出來了)
[root@localhost zfs]# iscsiadm --mode node --targetname iqn.1986-03.com.sun:02:cf6f7152-7468-4f02-e214-ff7d6784c92c --portal 172.16.43.144 --login
Logging in to [iface: default, target: iqn.1986-03.com.sun:02:cf6f7152-7468-4f02-e214-ff7d6784c92c, portal: 172.16.43.144,3260]
Login to [iface: default, target: iqn.1986-03.com.sun:02:cf6f7152-7468-4f02-e214-ff7d6784c92c, portal: 172.16.43.144,3260]: successful

fdisk 會發現有無法解讀的table
[root@localhost zfs]# fdisk -l

Disk /dev/sda: 500.1 GB, 500106780160 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 102400 7 HPFS/NTFS
Partition 1 does not end on cylinder boundary.
/dev/sda2 13 13068 104857600 7 HPFS/NTFS
Partition 2 does not end on cylinder boundary.
/dev/sda3 13068 48053 281022464 7 HPFS/NTFS
Partition 3 does not end on cylinder boundary.
/dev/sda4 48054 60801 102392640 5 Extended
Partition 4 does not end on cylinder boundary.
/dev/sda5 48054 48067 105808+ 83 Linux
/dev/sda6 48067 60801 102286768+ 8e Linux LVM

Disk /dev/sdb: 2147 MB, 2147483648 bytes
67 heads, 62 sectors/track, 1009 cylinders
Units = cylinders of 4154 * 512 = 2126848 bytes

Disk /dev/sdb doesn't contain a valid partition table

有發現/dev/sdb這個,但無法解讀,不過沒關係就照作吧
[root@localhost zfs]# zpool status
no pools available
[root@localhost zfs]# zpool list
no pools available
[root@localhost zfs]# zpool create iscsi-clt /dev/sdb
[root@localhost zfs]# zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
iscsi-clt 1.98G 75K 1.98G 0% ONLINE -
[root@localhost zfs]# zfs list
NAME USED AVAIL REFER MOUNTPOINT
iscsi-clt 70.5K 1.95G 21K /iscsi-clt

把它mount起來,並產生檔案試試
[root@localhost zfs]# zfs set mountpoint=/iscsi-mnt iscsi-clt
[root@localhost iscsi-mnt]# zfs mount iscsi-clt
[root@localhost iscsi-mnt]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
94082868 8201004 81025648 10% /
/dev/sda5 102454 11983 85181 13% /boot
tmpfs 2068836 0 2068836 0% /dev/shm
/dev/sda3 281022460 201541340 79481120 72% /mnt/ntfs-280g
iscsi-clt 2047940 23 2047918 1% /iscsi-mnt

如果要umount可以下
[root@localhost iscsi-mnt]# zfs umount iscsi-clt

[root@localhost zfs]# cd /iscsi-mnt/
[root@localhost iscsi-mnt]# ls -l
total 0
[root@localhost iscsi-mnt]# touch 1234
-rw-r--r-- 1 root root 0 Jun 18 16:49 1234
[root@localhost iscsi-mnt]#[root@localhost iscsi-mnt]# cat 1234
fdklasjflasjdfkajsdfl;ajsdf
alsdfja;lsdkjf;aklsdf
askdf;jaskdf;jaskldf
vi 1234

可以把下列這幾行加到/etc/rc.local
iscsiadm --mode node --targetname iqn.1986-03.com.sun:02:cf6f7152-7468-4f02-e214-ff7d6784c92c --portal 172.16.43.144 --login
zpool create iscsi-clt /dev/sdb
#以下這行是為了保險,理當設定一次後就會KEEP下來,只要再zfs mount即可
zfs set mountpoint=/iscsi-mnt iscsi-clt
zfs mount iscsi-clt

如果要一寫多讀,那唯獨可以設為(在iscsi client)
zfs set readonly=on [pool/zfs]

重開機時zpool status 可以觀察到iscsi-clt的狀態,如果UNAVAIL那就表示可能iscsi client連線有問題嘍
重新login連線,再檢查一次zpool status應該可恢復正常

linux使用zfs所需套件
-rwxrwxrwx 1 root root 84548 May 6 04:38 fuse-2.7.4-8_12.el5.i386.rpm
-rwxrwxrwx 1 root root 27287 May 6 04:38 fuse-devel-2.7.4-8_12.el5.i386.rpm
-rwxrwxrwx 1 root root 28498 May 6 04:35 fuse-kmdl-2.6.18-164.el5-2.7.4-8_12.el5.i686.rpm
-rwxrwxrwx 1 root root 28560 May 6 04:36 fuse-kmdl-2.6.18-164.el5PAE-2.7.4-8_12.el5.i686.rpm
-rwxrwxrwx 1 root root 28545 May 6 04:36 fuse-kmdl-2.6.18-164.el5xen-2.7.4-8_12.el5.i686.rpm
-rwxrwxrwx 1 root root 28531 May 6 04:36 fuse-kmdl-2.6.18-194.el5-2.7.4-8_12.el5.i686.rpm
-rwxrwxrwx 1 root root 28562 May 6 04:36 fuse-kmdl-2.6.18-194.el5PAE-2.7.4-8_12.el5.i686.rpm
-rwxrwxrwx 1 root root 28570 May 6 04:36 fuse-kmdl-2.6.18-194.el5xen-2.7.4-8_12.el5.i686.rpm
-rwxrwxrwx 1 root root 72616 May 6 04:37 fuse-libs-2.7.4-8_12.el5.i386.rpm

-rwxrwxrwx 1 root root 1502751 Jun 18 16:27 zfs-fuse-0.6.0-6.el5.i386.rpm

如果在mount zfs有下面錯誤訊息時
[root@HTS171 ~]# zfs mount iscsi-clt
cannot mount 'iscsi-clt': Input/output error.
Make sure the FUSE module is loaded.
那表示fuse-kmdl-xxx沒安裝(它需要fuse.ko)
fuse-kmdl-xxx請特別注意要跟kernel版本搭配(uname -a)

文章:
http://blog.xuite.net/ibjenny.cheng/vserver/22157067?ref=rel
http://www.wretch.cc/blog/wenbinlai/11660199
http://expert.lccnet.com.tw/zone/viewthread.php?tid=13224
http://forum.homeserver.com.tw/index.php?PHPSESSID=4cb8l8i2ljeov46q76u5trdac5&board=29.0
http://ian.testers.homelinux.net/wiki/view/Cluster_filesystem
Solaris FileSystem Choice
[cluster filesystem]
GFS
Lustre
UFS(globe option)
[non-cluster filesystem]
ZFS
NTFS
EXT3

2010年2月25日 星期四

processes fork and swap space

今天在Sun Solaris上進行壓力測試, 想當然爾跑出了一堆程式, 可是卻停在第20xx後程式就fork不出來了。可憐的是,程式的原始碼不是自己持有,也就是說跑的是別人家的程式,實在很難抓問題,尤其在沒有任何其他明顯線索下。沒辦法了,自己寫一支程式來測試看看嘍,好在之前有在Linux寫了一支壓力測試程式,重新Make後,就趕上架去處理吧。
RUN了2圈後,很快發現fork error , errno=12 (ENOMEM), 從man page上可以發現是swap space的問題,check一下指令
swap -l :查詢swap 空間設定為多少
swap -s:目前當下剩下的swap space 還有多少可用
在測試前後比較,明顯發現swap空間的不足,二話不說,當然是增加swap嘍。

話雖然這樣就解決了,只是fork程式跟swap空間有什麼關係呢
以下摘錄自: http://bbs.nsysu.edu.tw/txtVersion/treasure/linux/M.1013884061.A.html

BSD對swap space的處理頗為保守. 要求所有在主記憶體的page
在配置前都必須要先有一塊swap space. 所以swap space的大
小限制了可以執行的程式數量.不過這也保證程式只有在fork或
exec時才會發生記憶體不足的現象, 而不會執行到一半要被swap
出去, 卻找不到swap space可用的窘況.也就是說如果你的電腦有
64MB的記憶體,但是只劃了16MB的記憶體,這樣的系統只願意讓你使
用16MB而已, 這也是有些系統管理的書籍建議你swap space不要比
main memory小的原因.


這句話也為我自己解釋了長久以來在上課時,老師總要我們把swap空間開DRAM的1~2倍的原因

目前知道跟process 數量上限直接有關的
1. 實體記憶體大小
2.Swap 大小
3.System configuration(ulimit , plimit...etc)

那哪些是間接的呢
例如CPU idle, process使用的共用資源限制(例如程式去搶share memory resource)或socket resource...etc

不知道還有沒有別的?!

PS.真是小時不努力,老大徒傷悲

文章分類