1、unix 数据库 学习 笔记Unix学习笔记FAQ/dev/rdsk和/dev/dsk的区别/dev/rdsk代表raw disk,即字符设备/dev/dsk代表block disk,即块设备这两个目录中存储的逻辑设备名称所指的物理设备是一样的,但是访问方式不一样。由于不同的命令所需的设备类型不一致,所以需要根据情况选择rdsk或者dsk/devices 存储物理设备名称/etc/path_to_inst 存储实例名称(kernel对系统每一个设备的简称)和物理设备名称的映射关系,比如sd,代表第n块 scsi disk; dad代表可能代表第n块IDE硬盘设备逻辑设备名称 是对/device
2、s中的物理设备的符号链接,所有的逻辑设备名称都存储于/dev目录下,逻辑设备名称包含如下几部分控制器编号、目标号、磁盘号、分片号(s0-s7)或者fdisk分区号(p0-p4),如下ctds,pIDE devices do not use a target number and are represented as (cds,p).Devfsadm扫描硬件可以使操作系统立即扫描当前设备,如果硬件发生变动,使用该命令可是Unix立即识别相应的变动,比如增加或移除了硬盘后可以使用该命令,使得format命令立即可以看到更新后的结果;If you remove a disk from a runni
3、ng system or make any configuration changes and you wantthat change to take affect without rebooting the system, then you can run the devfsadm com-mand from command line.磁盘的标签To “label” a disk means to write slice informa-tion onto the disk. You usually label a disk after you change its sliceSMIThe
4、traditional VTOC(Volume Table of Con-tents) label for disks that are less than 1TB in size. EFIProvides support for disks that are larger than 1TB on systems that run a 64-bit Solaris kernel. The Extensible Firmware Interface (EFI) disk label is not available for disks connected to a system running
5、a 32-bit Solaris kernel. A disk that is less than 1 TB (terabyte) in size can be labeled with an EFI label using format -e command.Prtvtoc查看磁盘分区信息查看磁盘slice详细信息Slice 2在VTOC中代表如下意义VTOCRefers to the entire disk, by convention. The size of this slice should not be changedbash-3.00# prtvtoc /dev/rdsk/c1t
6、0d0s2* /dev/rdsk/c1t0d0s2 partition map* Dimensions:* 512 bytes/sector* 63 sectors/track* 255 tracks/cylinder* 16065 sectors/cylinder* 2087 cylinders* 2085 accessible cylinders* Flags:* 1: unmountable* 10: read-only* Unallocated space:* First Sector Last* Sector Count Sector * 0 1076355 1076354* Fir
7、st Sector Last* Partition Tag Flags Sector Count Sector Mount Directory 0 2 00 1076355 24017175 25093529 1 3 01 96390 979965 1076354 2 5 00 0 33495525 33495524 3 14 01 96390 33399135 33495524 4 15 01 16065 80325 96389 7 8 00 25093530 8401995 33495524 8 1 01 0 16065 160641block=1sector=512bytesolaris
8、中如何挂载光驱1,用#iostat -En或#ls -l /dev/ | grep sr查看设备号。如:# iostat -Enc0t6d0 Soft Errors: 0 Hard Errors: 0 Transport Errors: 0Vendor: TOSHIBA Product: DVD-ROM SD-M1401 Revision: 1009 Serial No: 12/20/00Size:或# ls -l /dev/ | grep srlrwxrwxrwx 1 root root 13 Feb 27 2004 rsr0 - rdsk/c0t6d0s2lrwxrwxrwx 1 root
9、 root 12 Feb 27 2004 sr0 - dsk/c0t6d0s22,然后 # mount F hsfs o ro /dev/dsk/c0t6d0s2 /cdrom服务的开启与关闭安装solaris10,启动后发现找不到ftp、telnet的关闭方法,管理命令 svcadm(服务状态管理,启动、停止等)# svcs 查看当前所有的服务状态,可以使用|管道符重定向作更个性化的查找;如# svcs |grep online 查看当前运行服务# svcs |grep offline 查看当前停止服务# svcs |grep inetd 查看inetd服务状态ftp服务#svcadm di
10、sable svc:network/ftp关闭ftp服务#svcadm enable svc:network/ftp启用ftp服务如果无法用root ftp,在 /etc/ftpd/ftpusers,如果有root,行首加#号注释掉就可以了telnet服务#svcadm disable svc:network/telnet如果无法用root telnet,修改 /etc/default/login把CONSOLE=/dev/console该行注释掉,就可以用root telnetSSH服务Solaris在安装完毕后就提供了该项服务:OpenSSH服务的开启方法:svcadm enbale -r
11、t ssh默认情况下,OpenSSH是禁止root帐户通过SSH方式登录的,以保障安全。方法如下:修改 /etc/ssh/sshd_config文件,将其中的“PermitRootLogin no”修改为“PermitRootLogin yes”,再执行 svcadm restart ssh 重新启动SSH服务。#svcadm disable svc:network/smtp:sendmailMount分区挂接临时挂接时直接使用mount命令挂接,如下Mount /dev/dsk/c1t2d0s2 /mnt如果需要在系统启动时自动挂接,需要在/etc/vfstab中加入挂接命令;mount v
12、命令显示当前系统所有已挂接硬件,该命令实际读取的是/etc/mnttab文件;umount卸载失败如何处理卸载分区Umount /mnt如果提示umount: /mnt busy,表示有应用程序正在读写该分区,最好的处理方法如下The safest way to stop all processes that are accessing a file system beforeunmounting it is to use the fuser command to report on the processes that areaccessing a particular file syste
13、m. Once the processes are known, send a SIGKILLto each process.The following example shows how an unmount of the /export/home file sys-tem failed because the file system is busy. The fuser -c command obtains theIDs of the processes that are accessing the file system. The ps -ef and grep com-mands en
14、able you to identify the particular process. Next, use the fuser -c -kcommand to kill the running process. Finally, rerun the umount command tounmount the file system查看文件系统或者fstyp -v /dev/rdsk/c1t2d0s5|more注:vfstab中只能查看已挂接分区的文件系统创建文件系统The newfs command enables you to create a UFS file system by read
15、ing param-eter defaults from the disk label, such as tracks per cylinder and sectors per track.You can also customize the file system by using the newfs command options。Ensure that you have met the following prerequisites.? The disk must be formatted and divided into slices.? To recreate an existing
16、 UFS file system, unmount it first.? Know the device name associated with the slice that will contain the file system运行级别Solaris os 共有8个run levles,每个级别对应相应的系统行为,见下表系统默认启动后进入级别3,即多用户级别,其实是读取配置文件/etc/inittab中的配置信息initdefault所得。查看当前系统运行级别使用命令# who -r . run-level 3 Sep 11 23:26 3 0 S改变当前系统运行级别Init -5 关机
17、Init -6重启杀死僵死进程(zombie process)显示进程参数The pargs command can be used to print the arguments and environment variablesassociated with a process. The pargs command solves a problem of the ps command,being unable to display all the arguments that are passed to a process. The pscommand, when used with -f
18、option, prints the full command name and its arguments,up to a limit of 80 characters. If the limit is crossed then the command line is truncated.With the -e option, pargs command can be used to display the environmentvariables that are associated with a process. Following is an example of using the
19、pargs command查看进程树When a Unix process forks or initiates a new process, the forking process is calleda parent process and the forked process is called a child process. This parent-childrelationship can be displayed with the ptree command. When the ptree com-mand is executed for a PID, it prints the
20、process ancestry tree, that is, all the par-ents and children for this process, with child processes indented from theirrespective parent processes as shown below查看硬盘的大小和型号iostat E如何查看系统的版本$ uname -X $ more /etc/release开启root远程登录telnetSolaris 10和后续版本为了保护系统安全,缺省只提供ssh服务,而且还不允许root用户直接登录,这对于开发和调试系统的使用
21、用户来说很不方便。在Solaris 10上开放telnet服务并允许root用户登录的方法如下:1. 打开telnet服务 # svcadm enable telnet svcadm是Solaris下最新的网络服务管理系统,要了解它和svcs的使用方法,请参见其帮助手册。2. 开放root登录权限 修改/etc/default/login文件,注释掉其中的: CONSOLE=/dev/console3. 修改root用户的缺省shell为bash 修改/etc/passwd文件,将root用户的shell改为/usr/bin/bash root:x:0:0:Super-User:/:/usr/
22、bin/bash开启root ftp权限/etc/ftpd/ftpusers中注释掉root用户修改solaris10的hostname修改三个文件1、#vi /etc/hosts# Internet host table#:1 localhost127.0.0.1 localhost192.168.32.128 solaris10 solaris10.pick.some.domain # Added by DHCP2、/etc/hostname.hme0(hme0为网卡名称)solaris103、/etc/nodenamesolaris10添加swap片:1、编辑/etc/vfstab文件#
23、vi /etc/vfstab#devicedevicemountFSfsckmountmount#to mountto fsckpointtypepassat bootoptions.2、按照以下格式添加swap空间:/dev/dsk/c1t2d0s2-swap-no-3、使用swap -a命令添加:# swap -a /dev/dsk/c1t2d0s2网络配置常用文件/etc/hostname.hme0:主机名,hme0为网卡接口名/etc/hosts:IP配置/etc/defaultrouter:缺省网关/etc/netmasks:子网掩码/etc/nsswitch.conf:在host的
24、行末加上dns,要与files用分隔符隔开/etc/resolv.conf:配置域名服务器/etc/nodename:主机名关闭和重启solaris重启/usr./sbin/shutdown y i6 g0关闭/usr./sbin/shutdown y i5 g 120 = disk replacement =120秒后关机df和du查看结果不一This section gives the technical explanation of why du and df sometimes reportdifferent totals of disk space usage.When a prog
25、ram that is running in the background writes to a file while theprocess is running, the file to which this process is writing is deleted.Running df and du shows a discrepancy in the amount of disk space usage.Thedf command shows a higher value.Explanation Summary- -When you open a file, you get a po
26、inter.Subsequent writes to this filereferences this file pointer.The write call does not check to see if the fileis there or not.It just writes to the specified number of characters startingat a predetermined location.Regardless of whether the file exist or not, diskblocks are used by the write oper
27、ation.The df command reports the number of disk blocks used while du goes through thefile structure and and reports the number of blocks used by each directory.Asfar as du is concerned, the file used by the process does not exist, so it doesnot report blocks used by this phantom file.But df keeps tr
28、ack of disk blocksused, and it reports the blocks used by this phantom file即df命令通过直接统计已使用的block块来计算大小,du命令通过枚举文件系统目录来统计每个目录所占用的block块来计算大小,如果某个文件正在被进程写入,那么这个文件相当于被删除,其大小不会被du命令统计,所以通常df命令执行速度快而且其结果比du命令大。如果可以保证当前文件系统中没有文件在被被进程写入,那么两个命令的统计结果应该相等查看cpu个数和主频Prtdiag vPsrinfo v查看虚拟cpu个数,此增强功能是为了识别芯片多线程(CM
29、T) 功能psrinfo -p 命令可以显示系统中物理处理器的总数查看内存大小prtconf |grep -i memory文件解压方式.bz2文件bzcat xxx.bz2.gz文件gzip d xxx .gz.tar文件Tar xvf xxx.tar.zip文件Uzip xxx.zip复杂后缀一次性解压.tar.bz2文件bzcat xxx.tar.bz2 | /bin/tar -xf .tar.gz文件gzip -d xxx.tar.gz | /bin/tar -xf tar包时排出特定文件夹或文件假设文件夹结构如下HzjHzj/xxHzj/repick/xxx当前目录为Hzj1、指定要
30、排出的文件夹或文件echo Hzj/repick excludefiles2、使用排出列表打包文件tar-cvfX mytest.tar excludefiles *3、查看打包结果tar-ft mytest.tar |grep repack应该为空才对打包和压缩组合使用tar cvfX - excludefiles *|gzip -c nrm.20120111.hzj.tar.gz其中excludefiles中存放要排出的文件夹列表sh中如何获取当前时间date +%Y-%m-%d/dev/null 2&1什么意思in UNIX0 = stdin1 = stdout2 = stderr/dev/null表示标准输出(1)输出到空设备,即抛弃此输出,&表示等同于的意思,2&1,表示2的输出重定向等同于1,因为之前标准输出已经重定向到了空设备文件,所以标准错误输出也重定向到空设备文件,即 ls rlt test.sh dev/null 2&1表示不管该文件存不存在都不会产生任何输出ftp服务配置配置服务inetd.conf中增加如下行ftp stream tcp nowait root /usr/sbin/in.ftpd
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1