歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> 關於Unix >> Solaris系統管理培訓

Solaris系統管理培訓

日期:2017/2/28 11:22:13   编辑:關於Unix


第一章:系統概念(System Concepts)
Objectives
Upon completion of this module, you should be able to
Match the three parts of an operating system (kernel, shell, and file system) to their definitions
Identify the three most common shells in the Solaris environment
Distinguish between multitasking and multiuser
Describe the client-server relationship
Define the following basic system terms: host, host name, network,
IP (Internet Protocol) address, client, and server
操作系統的主要三個部分
UNIX操作系統是基於文件的,操作系統的主要三個部分是:
Kernel
Shell
File structure
Kernel 是操作系統的核心,它的主要功能是:
管理系統的設備、內存、進程以及守護進程
系統程序與系統硬件之間接口
執行所有的命令
管理:
Swap space(交換分區) – 系統運行時保留的一部分磁盤空間
Daemons (守護進程)– 處理特定的系統任務
shell 是用戶與kernel之間的接口。它就像是命令的解釋器或翻譯器。Shell接收你輸入的命令,對你的輸入作出解釋,然後就將它發送給kernel執行。
操作系統的 Shells種類
Solaris系統中有三種shell:
Bourne shell ($) – 這是Solaris的缺省shell。Bourne shell為 AT&T UNIX 環境而開發。(/usr/bin/sh)
Korn shell ($) – 是Bourne shell的一個超級。它增加了一些功能,如:別名、歷史記錄以及命令行編輯等。(/usr/bin/ksh)
C shell (%) –C shell的語法類似於C語言,並且,C shell有些功能與 Korn shell相類似。(/usr/bin/csh)
Solaris環境的文件結構是分成的目錄樹結構,類似於DOS的文件結構。是一些有特定目的而組織在一起的目錄、子目錄和文件。
目錄 (Directory) – 其他目錄和文件所在處
子目錄(Subdirectory) – 屬於其他目錄的所有目錄
根目錄(/)位於目錄樹的最頂層,包含 :
/usr目錄包含系統的一些命令、工具、庫文件等 。
/opt目錄包含的三方應用軟件。
/dev目錄包含諸如磁盤、鍵盤、磁帶機、顯示器等地設備驅動程序。
/etc目錄包含系統配置文件,如用戶口令文件等等。
/export目錄一般包含用於NFS共享的目錄。
/export/home目錄包含用戶的個人主目錄。
/kernel目錄包含系統結構的kernel文件。這個目錄下的文件genunix是系統的UNIX kernel 。
虛擬內存操作系統——交換分區(Swap Space)
虛擬內存操作系統增大了物理內存,它將硬盤中的一部分空間用於存儲暫時不用內存數據。這塊硬盤空間叫做交換分區。與Windows下的SWAP文件的功能相似。
守護進程(Daemons)
守護進程是在後台運行的程序,它負責系統的某個特定的功能,比如打印。
系統管理的一些常見的概念:
主機(Host) – 網絡環境下的某台計算機系統。
主機名(Host name) – 某台系統的名字,網絡中的任何系統都必須有自己的主機名。
IP地址(IP address) – 網絡軟件用於鑒別網絡中某台機器的一個數字符號。
客戶機(Client) – 使用網絡中一個和多個服務的主機和進程。
服務器(Server) – 在網絡中提供一個或多個服務的主機和進程。
網絡(Network) – 許多機器連接在一起、可以互相通信的集合。
Solaris有下列特性:
多任務(Multitasking) – 多個進程或應用程序可以同時運行。
多用戶(Multiuser) – 同時可以有多個用戶訪問系統資源。
分布處理(Distributed processing) – 通過網絡使用資源。
第二章:OpenBoot PROM介紹
所有Sun機器都一個用於基本硬件測試和初始化的固件,還有一個提供多種重要功能的用戶程序。
基本元素
Sun系統的基本硬件元素包括:
Boot PROM芯片,它永久的固定在主板中。
非易失性隨機訪問內存(non-volatile random access memory (NVRAM) )芯片,包含主機的基本信息。
Boot PROM內容
boot PROM有以下功能:
加點自檢(Power-on self-tests (POST))
系統重起始開始執行。
檢測基本CPU板
因機器型號不同而不同。
設備驅動
有一些小型設備驅動程序,使得啟動的初始化過程中可以與不同的外圍設備相通訊
用戶操作界面
NVRAM 內容
除了永久性存在地以太網地址、主機ID、時鐘外,還保存著可以修改的系統的配置參數。
Basic Boot PROM Commands
ok banner
ok boot
ok help
ok printenv
ok setenv
ok set-defaults
ok probe-scsi
ok probe-scsi-all
ok probe-ide
ok reset
The Open Boot banner Command
The banner command lists several pieces of useful information about the system such as model, amount of memory, and hostid. You can also use the banner command to identify your system’s PROM version number. Three boot PROM levels are discussed in this module.
ok banner
Sun UltraSPARC 60 UPA/PCI (2 X UltraSPARC-II 296MHz), Keyboard Present
OpenBoot 3.11, 256 MB memory installed, Serial #3159808.
Ethernet address 8:0:22:1a:e7:3f, Host ID: 72303700.
ok
boot 命令和參數
您可以在boot命令後鍵入一個或多個參數。這些參數傳遞改操作系統內核,將影響整個啟動過程。
命令格式
ok boot [device_name] - [options]
參數
a 交互式啟動系統。提示輸入根設備和交換設備以及一些重要的系統文件
r 啟動時系統將重新查找所有的設備,在/devices和/dev目錄下重新生成文 件,更新/etc/path_to_inst文件。
s 系統啟動後停留在S運行級別。可以用來系統錯誤排除。
v 詳細地顯示出系統的啟動信息。有時可以用來系統的錯誤排除。
printenv 命令
printenv命令顯示NVRAM的參數以及參數的缺省值。
查看缺省啟動設備
您可以使用printenv顯示缺省啟動設備。
ok printenv
Parameter Name Value Default Value
tpe-link-test? True true
output-device ttya screen
input-device ttya keyboard
sbus-probe-list f0123 f0123
keyboard-click? False false
diag-file
diag-device net net
boot-file
boot-device disk disk
auto-boot? true true
More [,,q] ? q
您可以在系統的輸出中查看缺省啟動設備,參數是boot-device。您也可以輸入printenv boot-device,這樣只顯示啟動設備的值。
重新定義PROM Boot值
使用setenv命令可以重新定義PROM的值 。下面的例子中把auto-boot? 變為 false,然後reset命令使系統重新啟動,使變化生效。
ok printenv auto-boot?
auto-boot?true true
ok
ok setenv auto-boot? false
auto-boot? = false
ok reset
重置缺省值
使用set-defaults 命令將所有的參數重新設置為缺省的值。
ok set-defaults
______________________________________________________________________
注意 –set-defaults命令只對有缺省值的參數生效。
______________________________________________________________________
影響系統啟動和自檢的按鍵有:
stop
如果在系統加電自檢時按下Stop鍵,就取消POST(加電自檢)診斷,然後停留在OK狀態。
Stop+d
在系統自檢時同時按下stop和d鍵,系統將自動轉到診斷模式,診斷模式下系統將更完全地進行自檢。
Stop+n
如果由於NVRAM的設置不正確而導致系統無法正確啟動時,可以在系統加電自檢時同時按下stop和n鍵。它的作用是將NVRAM的參數值設為默認值。
Stop+a
同時按下stop和a鍵將中斷操作系統的運行,退到OK狀態。
警告:盡量不要在操作系統運行時按stop+a,這將導致操作系統停止並且導致數據的丟失。在萬不得以的時候,在按下stop+a後,鍵入sync命令用以將內存的數據同步到硬盤中。
探測系統總線
將外圍設備(如光驅、硬盤)與主板連接在一起的I/O總線有SCSI(small computer system interface)總線和IDE (integrated drive electronics)總線。
在OpenBoot 3.x系統中使用probe-命令
在OpenBoot 3.x的系統中,使用probe-命令時,您會看到一個警告。如果您在操作系統運行狀態下,用stop-a將系統強行暫停,或使用halt退出操作系統。這樣的狀態下使用probe-命令會造成機器掛起。因此,您必須先運行reset-all命令。
請先設置auto-boot?為false後再運行reset-all,系統將重新自檢,停留在OK狀態下,然後可以運行這個命令。
顯示連接在SCSI總線上的設備
probe-scsi命令將鑒別連接在SCSI控制器上的設備。
ok probe-scsi
Target 3
Unit 0 Disk SEAGATE ST1480 SUN0424626600190016
Copyright (c)
All Rights Reserved
Target 6
Unit 0 Removable Read Only device SONY CD-ROM
ok probe-scsi-all
顯示連接在PCI總線上的IDE設備
ok probe-ide
Device 0 ( Primary Master )
ATA Model : ST 34342A
Device 1 ( Primary Slave )
Not Present
Device 2 ( Secondary Master )
removable ATAPI Model : CDR-8240B
Device 3 ( Secondary Slave )
Removable ATAPI Model yyyyyyyyyyyyyyy
可以使用devalias命令查看設備別名的物理地址,這樣就可以知道啟動設備的物理設備了。
ok devalias
screen /SUNW,ffb@1e,0
mydisk /pci@1f,0/pci@1,1/ide@3/disk@0,0
net /pci@1f,0/pci@1,1/network@1,1
cdrom /pci@1f,0/pci@1,1/ide@3/cdrom@2,0:f
disk /pci@1f,0/pci@1,1/ide@3/disk@0,0
disk3 /pci@1f,0/pci@1,1/ide@3/disk@3,0
disk2 /pci@1f,0/pci@1,1/ide@3/disk@2,0
disk1 /pci@1f,0/pci@1,1/ide@3/disk@1,0
disk0 /pci@1f,0/pci@1,1/ide@3/disk@0,0
ide /pci@1f,0/pci@1,1/ide@3
floppy /pci@1f,0/pci@1,1/ebus@1/fdthree
ttyb /pci@1f,0/pci@1,1/ebus@1/se:a
ttya /pci@1f,0/pci@1,1/ebus@1/se:b
keyboard! /pci@1f,0/pci@1,1/ebus@1/su@14,3083f8
keyboard /pci@1f,0/pci@1,1/ebus@1/su@14,3083f8
mouse /pci@1f,0/pci@1,1/ebus@1/su@14,3062f8
設備別名在左列。設備物理地址在右列。
如果操作系統掛起了(沒有響應),並且您也不能遠程登錄,那您沒有別的選擇了,只有強行中斷操作系統。
中斷掛起的系統
如果系統掛起了,可以嘗試下列步驟:
1.用Stop-a中斷操作系統。如果成功,系統會停留在PROM狀態。如果是使用字符終端作為系統控制台,則按Break鍵。
2. 用sync命令將內存的內容同步到磁盤,減少數據的丟失。結束後系統會自動重起。
在ok提示符下鍵入sync命令。
ok sync
注意 – 您也可以用Stop-a強行中斷操作系統,然後鍵入go恢復操作系統運行。不建議使用此功能。
第三章:安裝Solaris操作系統
Software Groupings
基本
包含系統運行所需的最基本的軟件和設備驅動。不包括圖形界面和手冊頁。
最終用戶
除了基本軟件外,還包括圖形界面。
開發者
包括編譯工具、圖形界面、手冊頁。
完整分發和 OEM 支持
包含全部內容和一些OEM地硬件設備驅動。
Installation Information Worksheet
Acquire the following necessary information prior to your installation:
Host name:____________________________________________________
IP address:_____________________________________________________
Name service (NIS, NIS+, DNS or None):_________________________
Subnet (yes or no):______________________________________________
Geographic location:____________________________________________
Time zone information:__________________________________________
Root password:_________________________________________________
Installation Process
1. Insert the CD-ROM into the CD-ROM drive.
2. Boot the release media.
ok boot cdrom
3. Select the appropriate language and locale for your site and click on Continue.
4. Enter the assigned host name for the system
5. Type the IP address
6 . Select the type of the name service
7. Select Time Zone
8. Select Initial to perform an initial install and not preserve current settings
9 . Select the software group
10 . Set the sizes of each disk partition
11 . Type a root (superuser) password
第四章:軟件包管理
所有Solaris系統的軟件都以包的形式出現。
軟件包包含:
軟件包的描述文件
系統需求的描述文件
需要安裝的文件
安裝前以及安裝後需要運行的腳本
The pkgadd command
用於安裝軟件包
pkgadd [ -d [device | pathname ]] pkg_name
# pkgadd -d /cdrom/cdrom0/s0/Solaris_2.7/Product SUNWaudio
Processing package instance from
Audio applications
(sparc) 3.6.4,REV=1.98.08.13
Copyright 1998 Sun Microsystems, Inc. All rights reserved.
Using as the package base directory.
## Processing package information.
## Processing system information.
2 package pathnames are already properly installed.
## Verifying package dependencies.
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.
## Checking for setuid/setgid programs.
This package contains scripts which will be executed with super-user
permission during the process of installing this package.
Do you want to continue with the installation of [y,n,?] y
Installing Audio applications as
## Installing part 1 of 1.
Installation of was successful.
The pkginfo command
不加任何參數用於查看系統已經安裝的軟件包
# pkginfo | more
application SUNWAxg Solaris XGL 3.3 AnswerBook
application SUNWaadm Solaris 7 System Administrator Collection
system SUNWab2m Solaris Documentation Server Lookup
system SUNWab2r Solaris Documentation Server
system SUNWab2s Solaris Documentation Server
system SUNWab2u Solaris Documentation Server
application SUNWabda Sun Ultra 5/10 Hardware AnswerBook
application SUNWabe Solaris 7 User Collection
application SUNWabsdk Solaris 7 Software Developer Collection
The pkginfo Command
後面可跟一些參數,顯示特定某個軟件包的信息
Command Format
pkginfo [ -d [ device | pathname ] ] [ -l ] pkg_name
參數
-d device 指定軟件所在的位置,可以是目錄、磁帶機、軟盤等等
-l 顯示詳細信息
pkg_name 軟件包名
輸出列
CATEGORY 軟件包的類型,是“應用軟件”和是“系統軟件”
PKGINST 軟件包名,如果是SUNW打頭,則是SUN的產品
NAME 軟件的簡要描述
# pkginfo -d /cdrom/cdrom0/s0/Solaris_2.7/Product -l SUNWaudio
PKGINST: SUNWaudio
NAME: Audio applications
CATEGORY: system
ARCH: sparc
VERSION: 3.6.4,REV=1.98.08.13
BASEDIR: /
VENDOR: Sun Microsystems, Inc.
DESC: Audio binaries
PSTAMP: dtbuild37s19980813171753
HOTLINE: Please contact your local service provider
STATUS: spooled
FILES: 9 spooled pathnames
2 directories
3 executables
4 package information files
700 blocks used (approx)
The pkgrm Command
Command Format
pkgrm package_name
用於刪除軟件包
# pkgrm SUNWaudio
The following package is currently installed:
SUNWaudio Audio applications
(sparc) 3.6.4,REV=1.98.08.13
Do you want to remove this package? y
## Removing installed package instance
## Verifying package dependencies.
WARNING:
The package depends on the package
currently being removed.
WARNING:
The package depends on the package
currently being removed.
WARNING:
The package depends on the package
currently being removed.
WARNING:
The package depends on the package
currently being removed.
Dependency checking failed.
Do you want to continue with the removal of this package [y,n,?,q]
如果某個文件被多個包共享,則當最後一個包被刪除時才被刪除。
The pkgchk Command
用於檢查已安裝的軟件包
Command Format
pkgchk [ -p path1 [ path2...] ]
# pkgchk SUNWaudio
#
# pkgchk -p /etc/group
ERROR: /etc/group
file size <278> expected <282> actual
file cksum <23586> expected <24038> actual
pkgchk命令校驗包的屬性和內容是否與系統記錄的一致。
這個命令能檢測整個包或是某個文件。沒有輸出表示包已經安裝,但未發現不一致。
admintool圖形管理工具
admintool是solaris圖形管理工具,包括管理軟件包、主機名、主機地址、打印機、串口、用戶、用戶組等。
第五章:補丁維護
什麼是Patch?
簡單的說,補丁就是一些替換現存的文件和目錄的文件目錄集合。補丁糾正應用程序的錯誤或增加功能。
Patch編號
每個補丁都有編號。例如補丁號為101945,版本是34的話,這個補丁的目錄名就是101945-34.
patchadd命令用於安裝補丁:
# cd /tmp
# ls
105160-01 ps_data sdt_fl8zKOI_
# patchadd 105160-01
Checking installed packages and patches...
Verifying sufficient filesystem capacity (dry run method)
Installing patch packages...
Patch number 105160-01 has been successfully installed.
See /var/sadm/patch/105160-01/log for details
Patch packages installed:
SUNWdtbas
patchrm用於刪除補丁
# patchrm 105633-06
Checking installed packages and patches...
Patch 105633-06 has been backed out.
#
下面的命令用於檢查系統的補丁情況
# patchadd -p
Patch: 105160-05 Obsoletes: Requires: Incompatibles:Packages: SUNWdtbas
# showrev -p
Patch: 105160-05 Obsoletes: Requires:Incompatibles: Packages: SUNWdtbas
第六章:啟動過程
啟動有四個階段
Boot PROM 階段
Boot program 階段
Kernel 初始化階段
/sbin/init 階段
啟動過程:
自檢、顯示系統信息、讀取啟動設備的0扇區、在啟動設備尋找啟動程序、加載啟動程序、啟動內核、運行/sbin/init。
/sbin/init程序
讀取/etc/inittab文件。Init程序執行/sbin/rc*腳本。
系統有多種運行級別,不同的運行級別所啟動的服務不同。
系統運行級別有8種,分別為:
運行級別 意義
0 進入PROM狀態(OK狀態)
1 管理狀態(所有文件系統都掛上的單用戶模式,禁止其他用戶登錄)
2 多用戶模式(沒有網絡文件共享服務)
3 多用戶模式(有網絡文件共享服務)
4 未使用
5 退出操作系統並關機
6 重新啟動機器
S,s 單用戶模式
who命令查看運行級別
# who -r
. run-level 3 5月 10 17:03 3 0 S
可得到的信息:當前運行級別是3,系統啟動的時間是5月10日17:03.
/etc/inittabinittab定義了:
系統缺省運行級別
系統進入新運行級別需要做什麼
/etc/init.d目錄包含了系統的一些啟動腳本
/etc/rc1.d目錄包含進入運行級別1所需要運行的一些腳本
/etc/rc2.d目錄包含進入運行級別2所需要運行的一些腳本
...
...
這些目錄下包含兩種文件:
以K打頭,後面跟兩個數字以及一些字符串:表示系統到這個運行級別時所需要停止的一些服務,系統將以stop調用這個腳本。
以S打頭,後面跟兩個數字以及一些字符串:表示系統到這個運行級別時所需要開始的一些服務,系統將以start調用這個腳本。
增加啟動控制腳本
1.Identify the run level for the service
2.Determine which services are needed by the new process
3.Change to /etc/rc#.d and identify startup script
4.Repeat the process for the directory containing the shutdown script
5.Create the startup (shutdown) script in /etc/init.d
6.Create hard links to appropriate /etc/rc#.d directories
7.test
改變運行級別
init命令用於改變操作系統的運行級別。
命令格式:
init [ 0123456Ss ]
# init 0
INIT: New run level: 0
The system is coming down. Please wait.
System services are now being stopped.
Print services stopped.
Stopping the syslog service.
syslogd: going down on signal 15
Aug 14 14:54:30 snmpdx: received signal 15
The system is down.
syncing file systems... done
Program terminated
Type help for more information
ok
shutdown
用於改變操作系統運行級別。
命令格式:
shutdown [ -y ] [ -g seconds ] [ -i init-state ] [message]
選項:
y 系統提示時默認回答為YES
g 過多長時間改變
i 想要的運行級別
message 給所有登錄用戶的信息
# shutdown -y -g 0 -i 0
Shutdown started. Mon Dec 15 15:13:57 PST 1997
Broadcast Message from root (console) on mcmurdo Mon Dec
15 15:13:57...
THE SYSTEM IS BEING SHUT DOWN NOW ! ! !
Log off now or risk your files being damaged
Changing to init state 0 - please wait
ok
halt
進入0運行級別
poweroff
關閉系統並切斷電源
reboot
重新啟動系統
第七章:系統安全
UIDs(用戶ID)
UIDs用於區別文件和目錄的所有者。保存在 /etc/passwd。
GIDs(用戶組ID)
GIDs用戶區別用戶、文件、目錄的組成員。
/etc/passwd文件記錄了系統的用戶帳號的信息
格式
loginID:x:UID:GID:comment:home directory:login shell
#more /etc/passwd
root:x:0:1:Super-User:/:/sbin/sh
daemon:x:1:1::/:
bin:x:2:2::/usr/bin:
sys:x:3:3::/:
adm:x:4:4:Admin:/var/adm:
lp:x:71:8:Line Printer Admin:/usr/spool/lp:
uucp:x:5:5:uucp Admin:/usr/lib/uucp:
nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico
listen:x:37:4:Network Admin:/usr/net/nls:
nobody:x:60001:60001:Nobody:/:
noaccess:x:60002:60002:No Access User:/:
nobody4:x:65534:65534:SunOS 4.x Nobody:/:
jxbcpp:x:901:410:Dave Lister:/export/home/jxbcpp:/bin/sh
loginID 用戶名
x 隱藏的口令。加密的口令放在/etc/shadow文件中
UID 用戶ID
GID 組ID
comment 描述
home directory 個人主目錄
login shell 登錄後使用的shell
/etc/shadow文件記錄了系統用戶的加密後口令
格式
loginID:password:lastchg:min:max:warn:inactive:expire:
#more /etc/shadow
root:LXeokt/C/oXtw:6445::::::
daemon:NP:6445::::::
bin:NP:6445::::::
sys:NP:6445::::::
adm:NP:6445::::::
lp:NP:6445::::::
smtp:NP:6445::::::
uucp:NP:6445::::::
nuucp:NP:6445::::::
listen:*LK*:::::::
nobody:NP:6445::::::
noaccess:NP:6445::::::
nobody4:NP:6445::::::
lister:ubQhZXEMv/lyI:10336:7:90:5:30::
loginID 對應用戶名
password 加密後的口令。LK表示鎖定帳號,NP表示無口令
lastchg 最後更改口令的日期與1970年1月1日之間相隔的天數
min 改變口令需要最少的天數
max 同一口令允許的最大天數
warn 口令到期時,提前通知用戶的天數
inactive 用戶不使用帳號多少天禁用帳號
expire 用戶帳號過期的天數
最後一個字段未用
/etc/group文件記錄了系統的用戶組的信息
格式
groupname:password:GID:userlist
#more /etc/group
root::0:root
other::1:
bin::2:root,bin,daemon
sys::3:root,bin,sys,adm
adm::4:root,adm,daemon
uucp::5:root,uucp
mail::6:root
tty::7:root,tty,adm
lp::8:root,lp,adm
nuucp::9:root,nuucp
staff::10:
daemon::12:root,daemon
sysadmin::14:lister,torey
nobody::60001:
noaccess::60002:
Groupname 組名
password 口令。已經不使用
GID 組ID
userlist 成員列表
一個用戶可以同時屬於多個組。
id命令用於查看用戶的id號(用戶號)
命令格式
id [ options ] [ username ]
$ id
uid=10450(student1) gid=150(learning)
$ id -a
uid=10450(student1) gid=150(learning) groups=150(learning),14(sysadmin)
不加參數顯示用戶所在的id號用戶和主要組id號。
-a參數顯示用戶的所在所有組的組id號。
改變用戶
su命令用戶改變當前的用戶。
$ su - jxbcpp
Password:
su命令後可以加-,也可以不跟。如果跟-,則切換到那個用戶後執行用戶的啟動腳本,如.profile。
改變文件所有者
chown user_name filename
# ls -l memo
-rw-r--r-- 1 rimmer other 0 Jul 6 18:30 memo
# chown chris memo
# ls -l memo
-rw-r--r-- 1 chris other 0 Jul 6 18:30 memo
# cd /export/home
# chown -R chris mydocs
-R選項把mydocs目錄下所有子目錄及其文件的所有者都改變為chris。
# chown -R lister:staff mydocs
把mydocs目錄的所有者改為lister,所在組改為staff。
注:只有管理員才能改變所有者。
/etc/default/login文件
其中包含了CONSOLE=這一行,
如果CONSOLE=/dev/console未注釋,則root只能在控制台登錄。如果注釋了此行,root可以遠程登錄。
查看登錄狀態
命令who、finger、last可以查看用戶登錄狀態。
? who
查看本機登錄的用戶狀態。顯示用戶名、登錄的設備、登錄時間以及登錄的主機名字。
$ who
rimmer pts/1 Dec 21 07:07 (nepal)
lister console Dec 21 12:18 (:0)
用戶rimmer從機器nepal上登錄。而用戶lister則在本地登錄。
? finger
顯示本地和遠程系統用戶的詳細信息。包括用戶名、用戶注釋信息、終端名、空閒時間、登錄時間、登錄主機名。
$ finger bevw
Login name: bevw In real life: bev’s account
Directory: /home/bevw Shell: /bin/ksh
Last login Wed Oct 21 08:07 on console from :0
No unread mail
No Plan.
? last
顯示系統的最近用戶登錄狀況。
$ last
rimmer pts/4 pluto Fri Dec 18 10:24 - 11:00 (00:36)
lister pts/4 pluto Tue Dec 8 09:39 - 09:49 (00:10)
rimmer pts/4 pluto Thu Dec 3 15:16 - 15:17 (00:00)
rimmer console :0 Wed Dec 2 08:47 still logged in
reboot system boot Wed Dec 2 08:44
rimmer pts/0 pluto Tue Dec 1 17:27 - 17:28 (00:00)
rimmer pts/3 pluto Tue Dec 1 16:13 - 16:39 (00:26)
rimmer pts/2 pluto Tue Dec 1 15:32 - 15:38 (00:06)
holly term/a pluto Tue Dec 1 15:12 - 08:41 (17:29)
第八章:用戶管理
可以用admintool圖形工具增加、更改、刪除用戶和用戶組。
注意:
用戶所在的組必須先於用戶之前創建。
命令行方式:
增加用戶組
groupadd命令增加用戶組
groupadd [-g gid] group
說明:
g 制定組的ID號
gid 組的ID號(不能與現有的組ID號重復)
group 組名
#groupadd –g 100 sun
useradd命令增加用戶組
useradd [-u uid | -g group] | -d dir | -s shell | -c comment | -m [-k skel_dir] ] login
說明:
u 指定用戶ID號
g 制定所在組
d 指定用戶目錄
s 制定用戶SHELL
c 用戶的注釋
m 建立用戶目錄
login 用戶的登錄名
#useradd –u 1233 –g sun –d /export/home/sun –c “Sun test user.” –m –s /usr/bin/sh sun
第九章:初始化文件管理
用戶的初始化文件是一些命令腳本和shell參數。
下表列出不同的shell所運行的初始化文件:
Shell System User Template
(Read First) (Read Second/Third) /etc/skel
Bourne /etc/profile $HOME/.profile local.profile
Korn /etc/profile $HOME/.profile local.profile
C /etc/.login $HOME/.cshrc
then $HOME/.login local.cshrc
local.login
如當一個具有Bourne Shell的用戶登陸系統後,系統將首先自動運行/etc/profile這個初始化腳本,然後運行用戶目錄下的.profile初始化腳本。
當創建一個Bourne Shell的用戶時,系統會自動把/etc/skel/local.profile這個文件拷貝到用戶主目錄下。因此/etc/skel下包含的是一些用戶初始化腳本的模板。
如何手工運行初始化腳本文件:
Bourne and Korn Shells
$ cd
$ . ./.profile
$ . ./.kshrc
C Shell
% source ~/.login
% source ~/.cshrc
第十章:進程控制
使用ps命令顯示系統正在運行的進程。
參數:
e 列出系統所有的進程
f 列出詳細清單
UID:運行進程的用戶
PID:進程的ID
PPID:父進程的ID
C:進程的CPU使用情況(進程使用占CPU時間的百分比)
STIME:開始時間
TTY:運行此進程的終端或控制台
TIME:消耗CPU的時間總量
CMD:產生進程的命令名稱
要查找某進程:
#ps -ef|grep process_name
使用Kill命令給進程發送一個信號。Kill命令一般用於結束系統的某個進程。
Solaris有44個信號。每個信號有個數字和名稱。如果你未制定信號,則默認為信號15,這個信號用於結束進程。
用戶只能結束自己啟動的進程。超級用戶可以結束任何一個進程。
#find / -name test
#ps -aef|grep find
root 3602 3575 0 20:13:01 pts/0 0:00 grep find
root 3601 3575 2 20:12:56 pts/0 0:00 find / -name test
#kill 3601
第十一章:磁盤配置和命名
Solaris下,一個磁盤包含8個分區,標記為0-7。
分區0位根分區,包含啟動的信息
分區2代表整個磁盤
交換分區可以是任何分區,默認為分區1
其它分區用戶存放數據
邏輯設備名存放在/dev/dsk和/dev/rdsk中。這些名稱是/devices目錄下的符號連接。使用邏輯設備名便於系統管理員操作。
Sun使用下列命名方式定義邏輯設備名:
/dev/[r]dsk/c#t#d#s#
c:邏輯控制器號
t:物理總線目標號
d:磁盤或邏輯單元號(LUN)
s:分區號
物理設備名表示設備的完整信息,如設備總線地址。物理設備名在/devices目錄下。
# ls -l /dev/dsk/c0t3d0s0
lrwxrwxrwx 1 root root 86 Oct 20 16:04 /dev/dsk/c0t3d0s3 ->
../../devices/iommu@0,10000000/sbus@0,10001000/espdma@5,8400000/esp@5,880
0000/sd@3,0:d
實例名是系統設備的簡稱。例如:
sdn where s = SCSI, d = disk, and n = 邏輯磁盤號,例如sd0,表示第一個SCSI磁盤設備。
dmesg顯示實例名
dmesg命令鑒別系統所連接的設備。以實例和物理設備名稱的方式顯示。
# dmesg|more
May 13 20:18
cpu0: SUNW,UltraSPARC (upaid 0 impl 0x10 ver 0x40 clock 167 MHz)
SunOS Release 5.7 Version Generic [UNIX(R) System V Release 4.0]
Copyright (c) 1983-1998, Sun Microsystems, Inc.
NOTICE: 64 bit OS installed, but the 32-bit OS is the default
for the processor(s) on this system.
See boot(1M) for more information.
Booting the 32-bit OS ...
mem = 196608K (0xc000000)
avail mem = 189440000
Ethernet address = 8:0:20:9b:60:b5
root nexus = Sun Ultra 1 SBus (UltraSPARC 167MHz)
sbus0 at root: UPA 0x1f 0x0 ...
sbus0 is /sbus@1f,0
dma0 at sbus0: SBus0 slot 0xe offset 0x8400000
dma0 is /sbus@1f,0/espdma@e,8400000
/sbus@1f,0/espdma@e,8400000/esp@e,8800000 (esp0):
esp-options=0x46
...
...
prtconf用於顯示系統的配置信息,包括內存、外圍設備等。
# prtconf|more
System Configuration: Sun Microsystems sun4u
Memory size: 192 Megabytes
System Peripherals (Software Nodes):
SUNW,Ultra-1
packages (driver not attached)
terminal-emulator (driver not attached)
deblocker (driver not attached)
obp-tftp (driver not attached)
disk-label (driver not attached)
sun-keyboard (driver not attached)
ufs-file-system (driver not attached)
chosen (driver not attached)
openprom (driver not attached)
client-services (driver not attached)
options, instance #0
aliases (driver not attached)
memory (driver not attached)
virtual-memory (driver not attached)
counter-timer (driver not attached)
sbus, instance #0
SUNW,CS4231, instance #0 (driver not attached)
auxio (driver not attached)
...
...
當在系統中增加新設備時,需要重新配置系統的硬件信息。這樣,系統就會重新構建/devices和/dev目錄。
下面是新增加硬盤的步驟:
1.在根目錄下創建一個名為/reconfiguration的空文件,然後重新關機。
2. 將硬盤接上機器,然後開機。
3.用format命令查看新增的硬盤。
# touch /reconfigure
# init 5
# format
第十二章:磁盤、分區和格式化
磁盤卷標,也叫磁盤卷內容表(VTOC),包含:
磁盤的分區表
磁盤的卷名
各分區的分區標識(分區掛接點的描述)
各分區的分區標識(分區是否可寫或可掛接)
磁盤卷標占據磁盤的第一扇區
把一個磁盤分區的步驟:
1. Type format at the prompt and press Return.
2. Choose a disk by selecting the number to the left corresponding to its description.
3. Type partition at the format prompt.
4. Type print at the partition prompt.
5. Type partition number to change the root partition.
6. Enter the new values.
7. Once you are satisfied with the partition table, label the disk.
命令prtvtoc可以顯示某個磁盤的分區狀況
# prtvtoc /dev/rdsk/c0t0d0s2
* /dev/rdsk/c0t0d0s2 partition map
* Dimensions:
* 512 bytes/sector
* 80 sectors/track
* 9 tracks/cylinder
* 720 sectors/cylinder
* 2500 cylinders
* 1151 accessible cylinders
* Flags:
* 1: unmountable
* 10: read-only
* First Sector Last
* Partition Tag Flags Sector Count Sector Mount Directory
0 2 00 0 41040 41039 /
1 3 01 41040 65520 106559
2 5 00 0 828720 828719
6 4 00 106560 722160 828719 /usr
第十三章:文件系統介紹
文件系統的定義
對用戶來說,文件系統是存儲信息的文件和目錄的集合。
對操作系統來說,文件系統是以一些數據的集合。
磁盤文件系統
Solaris定義了3種文件系統類型:
ufs – UNIX文件系統。是Solaris缺省的文件系統。
hsfs – 高密度CD-ROM文件系統,是只讀文件系統。
pcfs – PC文件系統,支持DOS格式化的軟盤。
網絡文件系統
NFS是Solaris系統支持的網絡文件系統。
內存文件系統
指操作系統運行時存在於內存中的文件系統。
流分區已經定義了分區的大小和位置,但未創建文件系統。
塊分區已經創建了文件系統。
它們之間的邏輯設備名分別存放在/dev/rdsk河/dev/dsk中。
磁盤卷標包含了磁盤的分區表。磁盤卷標存放在磁盤的第一個扇區。
啟動塊
啟動塊存放著啟動程序。位於磁盤的1-15扇區。
超級塊
超級塊包含啟動塊後面的16個扇區。超級塊是文件系統的信息表,包含:
數據塊的數量
柱面組的數量
數據塊和碎片的大小
硬件的描述
掛接點
文件系統的狀態:干淨、穩定或激活
備份的超級塊
由於超級塊包含了許多關鍵數據,因此,必須要備份。備份是在文件系統創建時產生的。
Solaris下以inode的方式記錄文件
Inode包含文件的下列信息:
文件類型和訪問模式
文件的擁有者和所在組的
文件大小
上次訪問和更改的時間以及inode更改的時間
已用數據塊的數量
inode包含兩種指針:直接指針和間接指針
直接指針
有12個,直接指向數據塊。這12個指針可以支持96K字節的文件。
間接指針
單倍間接– 單倍間接指針指向包含指針的數據塊。這樣可以支持16M字節的文件。
雙倍間接–雙倍間接指針指向包含單倍間接指針的數據塊。這樣可以支持32G字節的文件。
三倍間接–三倍間接指針指向包含雙倍間接指針的數據塊。這樣可以支持70T字節的文件。
newfs創建文件系統
# newfs /dev/rdsk/c0t2d0s0
newfs: construct a new file system /dev/rdsk/c0t2d0s0: (y/n)? y
/dev/rdsk/c0t2d0s0: 41040 sectors in 57 cylinders of 9 tracks, 80 sectors
21.0MB in 4 cyl groups (16 c/g, 5.90MB/g, 2688 i/g)
super-block backups (for fsck -F ufs -o b=#) at: 32, 11632, 23232, 34832,
文件系統檢測工具(fsck)用於檢測文件系統是否出錯。
比如,某個數據塊不能同時被兩個不同的inode占用。Fsck程序可以檢測這種錯誤。
# fsck /dev/rdsk/c0t3d0s7
** /dev/rdsk/c0t3d0s7
** Last Mounted on /export/home
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cyl groups
2 files, 9 used, 21606 free (14 frags, 2699 blocks, 0.1% fragmentation)
文件系統錯誤
許多情況下,文件系統發生錯誤是由於超級塊有錯誤。發生錯誤的原因主要是:
非正常關機
掉電
硬件錯誤
fsck運行的時間
系統每次啟動時都會自動運行fsck。如果發現錯誤,會嘗試自動修復,如果錯誤非常嚴重,需要人工修復。這是進入系統單用戶模式,然後打命令:
#fsck /dev/rdks/c0t0d0s0
df命令查看已掛接的文件系統使用狀況
參數k:表示以千字節格式顯示
$ df -k
Filesystem kbytes used avail capacity Mounted on
/dev/dsk/c0t3d0s0 38111 19196 18877 51% /
/dev/dsk/c0t3d0s6 565503 361529 203409 64% /usr
/proc 0 0 0 0% /proc
fd 0 0 0 0% /dev/fd
/dev/dsk/c0t3d0s1 25159 4886 20248 20% /var
/dev/dsk/c0t3d0s5 27439 20362 7050 75% /opt
swap 45980 12 45968 1% /tmp
du命令顯示某個目錄下文件的占用磁盤空間的情況:
du [-a] [-s] [-k] [directory]
參數:
-k 以千字節方式顯示(默認是以塊方式顯示,一個塊為512字節)
-s 只以簡略的方式顯示
-a 顯示制定目錄下所有文件和目錄占用的磁盤塊數量
第十四章:文件系統掛接
掛接就是將分離的文件系統附加到文件系統分成結構中。文件系統要附加到某個掛接點,也就是目錄。
掛接和卸載文件系統發生在系統啟動和關閉時。
系統啟動時,將讀取/etc/vfstab文件。這個文件記錄系統要掛接的文件系統。因此/etc/vfstab文件中的文件系統將自動掛接。也可以從命令行方式下人工掛接文件系統。
不加參數的mount顯示系統目前已經掛接的文件系統。
# mount
/ on /dev/dsk/c0t3d0s0 read/write/setuid/largefiles/logging on Mon Nov 18
17:58:19 1998
/usr on /dev/dsk/c0t3d0s6 read/write/setuid/largefiles/logging on Mon Nov 18
17:58:19 1998
/proc on /proc read/write/setuid on Mon Nov 18 17:58:19 1998
/dev/fd on fd read/write/setuid on Mon Nov 18 17:58:19 1998
/var on /dev/dsk/c0t3d0s1 nolargefiles/read/write/setuid on Mon Nov 18 17:58:19
1998
/opt on /dev/dsk/c0t3d0s5 setuid/read/write/largefiles on Mon Nov 18 17:58:20
1998
/tmp on swap read/write on Mon Nov 18 17:58:20 1998
/pns on dbserver:/export/pse soft/nosuid/remote on Mon Nov 18 19:04:36 1998
nolargefiles參數將使文件系統中所有新建的文件小於2G字節。
# mount -o nolargefiles /dev/dsk/c0t3d0s7 /export/home
使用這個參數可能出現錯誤,原因是由於文件系統包含了大於2G的文件
要掛接在/etc/vfstab中已有的某個文件系統時,只需要用命令
# mount /export/home
/etc/vfstab文件格式
#device device mount FS fsck mount mount
#to mount to fsck point type pass at boot ops
#/dev/dsk/c1d0s2 /dev/rdsk/c1d0s2 /usr ufs 1 yes -
/proc - /proc proc - no -
fd - /dev/fd fd - no -
swap - /tmp tmpfs - yes -
/dev/dsk/c0t3d0s0 /dev/rdsk/c0t3d0s0 / ufs 1 no -
/dev/dsk/c0t3d0s6 /dev/rdsk/c0t3d0s6 /usr ufs 1 no -
/dev/dsk/c0t3d0s3 /dev/rdsk/c0t3d0s3 /export ufs 5 yes -
/dev/dsk/c0t3d0s7 /dev/rdsk/c0t3d0s7 /export/home ufs 5 yes -
/dev/dsk/c0t3d0s5 /dev/rdsk/c0t3d0s5 /opt ufs 8 yes -
/dev/dsk/c0t3d0s1 - - swap - no -
umount卸載文件系統
# umount /dev/dsk/c0t3d0s7

# umount /export/home
如果文件系統中某個文件正在使用,則不能卸載這個文件系統。
總結:如何增加一個新的硬盤
1. Set up hardware, including setting switches and attaching cables. Follow the instructions included with the new disk.
2. Reboot the system using the command boot -r. This command will restart the system using the reconfigure (-r) option.
3. Partition the disk.
4. Create the new file systems as required.
5. Edit the /etc/vfstab file as required.
6. Reboot the system.
光驅、軟驅的使用
Solaris有個服務進程管理光驅和軟驅,當光盤或軟盤放入機器中,系統會自動的掛接上,掛接的目錄是:
Media Location
CD-ROM /cdrom/cdrom_name
Diskette /floppy/floppy_name
如:
#cd /cdrom/cdrom0
管理進程叫卷管理服務器,其腳本位於/etc/init.d/volmgt。
第十五章:網絡文件系統
NFS即網絡文件系統,是UNIX系統直接用以共享文件的協議。
NFS服務器:提供網絡共享資源的系統
NFS客戶:使用網絡共享資源的系統
當客戶端發出一個NFS請求時,掛接進程聯系掛接守護進程(/usr/lib/nfs/mountd)。本地掛接進程將掛接信息寫到/etc/mnttab文件中。一旦客戶完成NFS掛接請求,服務器中的/etc/rmtab文件中會寫入掛接信息。當客戶卸載了NFS共享資源後,這些信息就會從文件中刪除。
NFS 服務器守護進程
客戶端NFS 守護進程
客戶端有兩個守護進程,/usr/lib/nfs/statd和/usr/lib/nfs/lockd。這些進程在系統進入運行級別2時自動運行。
# more /etc/dfs/dfstab
# Place share(M) commands here for automatic execution
# on entering init state 3.
#
# daemon processes and the share commands, after adding the very
# first entry to this file.
#
# share [-F fstype] [ -o options] [-d ""] [resource]
# e.g,
# share -F nfs -o rw=engineering -d "home dirs" /export/home2
share命令
share [ -F FSType ] [ -o options ] [ -d description ] pathname
參數
-F FSType 指定文件系統的類型。如果/etc/dfs/fstypes文件中缺省的遠程文件類型是NFS,則不需要指定
-o options 控制客戶端訪問NFS共享資源的權限
-d description 共享資源的描述
pathname 要共享的資源
unshare命令
unshare [ -F nfs ] pathname
dfshares命令
用以查看服務器的共享資源
# dfshares
RESOURCE SERVER ACCESS TRANSPORT
venus:/usr/share/man venus - -
#dfshares mars
RESOURCE SERVER ACCESS TRANSPORT
mars:/export mars - -
dfmounts命令
服務器上查看共享資源被利用的狀況
# dfmounts
RESOURCE SERVER PATHNAME CLIENTS
- venus /usr/share/man earth, pluto,(anon)
掛接遠程網絡文件系統
mount [ -F nfs ] [ -o options ] server:pathname mount_point
# mount venus:/usr/share/man /usr/share/man
Copyright © Linux教程網 All Rights Reserved