Solaris系统管理培训

Solaris系统管理培训

第一章:系统概念(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的缺省shellBourne 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

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 

在系统自检时同时按下stopd键,系统将自动转到诊断模式,诊断模式下系统将更完全地进行自检。 

Stop+n 

如果由于NVRAM的设置不正确而导致系统无法正确启动时,可以在系统加电自检时同时按下stopn键。它的作用是将NVRAM的参数值设为默认值。 

Stop+a 

           同时按下stopa键将中断操作系统的运行,退到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图形管理工具 

admintoolsolaris图形管理工具,包括管理软件包、主机名、主机地址、打印机、串口、用户、用户组等。 

 

第五章:补丁维护

什么是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,系统启动的时间是5101703. 

 

/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 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 1997 

Broadcast Message from root (console) on mcmurdo Mon Dec 

15 ... 

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::: 

 

loginID 对应用户名 

password 加密后的口令。LK表示锁定帐号,NP表示无口令 

lastchg 最后更改口令的日期与197011日之间相隔的天数 

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 memo 

# chown chris memo 

# ls -l memo 

-rw-r--r-- 1 chris other 0 Jul 6 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可以远程登录。 

 

查看登录状态 

命令whofingerlast可以查看用户登录状态。 

 who 

查看本机登录的用户状态。显示用户名、登录的设备、登录时间以及登录的主机名字。 

$ who 

rimmer pts/1 Dec 21 ( nepal ) 

lister console Dec 21 (: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 on console from :0 

No unread mail 

No Plan. 

 

 last 

显示系统的最近用户登录状况。 

$ last 

rimmer pts/4 pluto Fri Dec 18 () 

lister pts/4 pluto Tue Dec 8 () 

rimmer pts/4 pluto Thu Dec 3 () 

rimmer console :0 Wed Dec 2 still logged in 

reboot system boot Wed Dec 2  

rimmer pts/0 pluto Tue Dec 1 () 

rimmer pts/3 pluto Tue Dec 1 () 

rimmer pts/2 pluto Tue Dec 1 () 

holly term/a pluto Tue Dec 1 ()

 

第八章:用户管理

可以用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命令一般用于结束系统的某个进程。 

Solaris44个信号。每个信号有个数字和名称。如果你未制定信号,则默认为信号15,这个信号用于结束进程。 

用户只能结束自己启动的进程。超级用户可以结束任何一个进程。 

 

#find / -name test 

#ps -aef|grep find 

    root  3602  3575  0 pts/0    0:00 grep find 

    root  3601  3575  2 pts/0    0:00 find / -name test 

#kill 3601 

 

第十一章:磁盘配置和命名

Solaris下,一个磁盘包含8个分区,标记为07 

分区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 /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  

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格式化的软盘。 

 

网络文件系统 

NFSSolaris系统支持的网络文件系统。 

 

内存文件系统 

指操作系统运行时存在于内存中的文件系统。 

 

流分区已经定义了分区的大小和位置,但未创建文件系统。 

块分区已经创建了文件系统。 

它们之间的逻辑设备名分别存放在/dev/rdsk/dev/dsk中。 

 

磁盘卷标包含了磁盘的分区表。磁盘卷标存放在磁盘的第一个扇区。 

 

启动块 

启动块存放着启动程序。位于磁盘的115扇区。 

 

超级块 

超级块包含启动块后面的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 

1998 

/usr on /dev/dsk/c0t3d0s6 read/write/setuid/largefiles/logging on Mon Nov 18 

1998 

/proc on /proc read/write/setuid on Mon Nov 18 1998 

/dev/fd on fd read/write/setuid on Mon Nov 18 1998 

/var on /dev/dsk/c0t3d0s1 nolargefiles/read/write/setuid on Mon Nov 18  

1998 

/opt on /dev/dsk/c0t3d0s5 setuid/read/write/largefiles on Mon Nov 18  

1998 

/tmp on swap read/write on Mon Nov 18 1998 

/pns on dbserver:/export/pse soft/nosuid/remote on Mon Nov 18 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/nfsd)响应请求并返回数据。服务器守护进程由/etc/init.d/nfs.server产生。如果/etc/dfs/dfstab文件中有共享条目,这些共享目录会在守护进程启动时自动共享。 

客户端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. 

# 

# Issue the command '/etc/init.d/nfs.server start' to run the NFS 

# 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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值