『Linux学习』基本命令篇(四)

来源:互联网 发布:大话java性能优化 编辑:程序博客网 时间:2024/05/06 04:21

1.内核模块的功能:

1)提供计算机外围设备的驱动程序。

2)提供一些其他的文件系统的支持。

所有的内核模块都在/lib/modules目录中。

使用lsmod命令列出目前已经载入的模块。

modprobe命令来临时载入某个模块。(可以同时载入相依赖的模块)

mod命令的语法格式如下:

modprobe  模块名

insmod 模块名 也可以载入一个模块

使用/sbin/modinfo这个命令来浏览某个模块的信息:

modinfo  模块名  

2./proc虚拟文件系统:、

为了是内核的管理和维护与文件系统的管理和维护能够使用完全相同的方法,UNIX操作系统使用引入了一个虚拟文件系统/pro。

/proc并不存在于硬盘上,而是一个存在在内存中的虚拟目录,可以借助修改这个目录中的文件来及时变更内核的参数。/proc这个目录中包含了存放在目前操作系统内核信息的文件。通过这些文件可以列出内核的状态。

1)可以使用/proc来获取内核的配置信息,或对内核进行配置。

2)/proc是一个虚拟的文件系统,所有的文件只存储在内存中,并不存放到硬盘上,这样访问/pro文件系统相当快。

3)由于/proc文件系统只存在于内存中,所以系统重启后所有的更改过的内容自动消失。又回到初始的设置。

4)利用/proc可以显示进程的信息,内存的资源,硬件设备,内核所占用的内存等。

5)在/proc中有一些子目录,如/proc/PID/子目录中包含了所有进程的信息,/proc/scsi/子目录中包含了scsi设备的信息,/proc/sys/子目录中包含了内核参数信息。

6)可以利用/proc/sys/子目录下的文件来修改网络设置,内存设置,或内核的一些参数

7)所有对/proc的修改立即生效

3.通过sysctl命令永久保存/pro/sys下的配置

使用sysctl这个命令所做的变更会保存到/etc/sysctl.conf这个系统设置的文件中。

使用sysctl命令可以进行系统的配置和维护,也可以监督系统的配置变化,

1)列出所有当前的系统设置:sysctl -a

2)从/etc/sysctl.conf文件中重新载入系统设置:sysctl - p

3)动态设置一个在/proc目录中文件的值,sysctl -w 值=?

4.从Linux-2.6内核开始使用udev这个工具来检测所有硬件设备,而kudzu这个工具有逐渐被取代的趋势,udev是一个工具,它能够根据系统中的硬件设备的状态动态更新设备文件,包括设备文件的创建,删除等,设备文件通常放在/dev目录下,使用udev后,在/dev目录中就只剩下包含系统中真正存在的设备。

udev是一个用户程序,配置文件是/etc/udev/udev.conf

[root@localhost etc]# more /etc/udev/udev.conf# udev.conf# The main config file for udev## This file can be used to override some of udev's default values# for where it looks for files, and where it places device nodes.## WARNING: changing any value, can cause serious system breakage!## udev_root - where in the filesystem to place the device nodesudev_root="/dev/"    #产生的设备文件的根目录是/dev# udev_db - The name and location of the udev database.udev_db="/dev/.udev.tdb" #通过udev产生的设备文件形成的数据库# udev_rules - The name and location of the udev rules fileudev_rules="/etc/udev/rules.d/"#用于指导udev工作的规则所在目录# udev_permissions - The name and location of the udev permission fileudev_permissions="/etc/udev/permissions.d/"# default_mode - set the default mode for all nodes that have no#                explicit match in the permissions filedefault_mode="0600"# default_owner - set the default owner for all nodes that have no#                 explicit match in the permissions filedefault_owner="root"# default_group - set the default group for all nodes that have no#                 explicit match in the permissions filedefault_group="root"# udev_log - set to "yes" if you want logging, else "no"udev_log="no"//当出现错误时,记录日志

udev的语句存放在/etc/udev/rules..d/目录文件中,这些语句包括文件名,权限,拥有者,属组以及发现一个新设备时要执行的命令。

[root@localhost etc]# ls -l /etc/udev/rules.d/total 48-rw-r--r--  1 root root  152 Oct  7  2006 10-wacom.rules-rwxr-xr-x  1 root root  310 Oct  7  2006 40-multipath.rules-rw-r--r--  1 root root 3567 Oct  8  2006 50-udev.rules-rw-r--r--  1 root root  507 Oct  8  2006 51-by-id.rules-rw-r--r--  1 root root  132 Oct 17 12:44 60-vboxadd.rules-rw-r--r--  1 root root  324 Oct  7  2006 90-ib.rules[root@localhost etc]# more -l /etc/udev/rules.d/50-udev.rules# There are a number of modifiers that are allowed to be used in some of the# fields.  See the udev man page for a full description of them.## See the udev.rules.examples file for more examples of how to create rules## create a symlink named after the device map name# note devmap_name comes with extras/multipath#KERNEL="dm-[0-9]*", PROGRAM="/sbin/devmap_name %M %m", NAME="%k", SYMLINK="%c"# DRI devices always go into a subdirectory (as per the LSB spec)KERNEL="card*",         NAME="dri/card%n"# alsa devicesKERNEL="controlC[0-9]*", NAME="snd/%k"KERNEL="hw[CD0-9]*",     NAME="snd/%k"KERNEL="pcm[CD0-9cp]*",  NAME="snd/%k"KERNEL="midi[CD0-9]*",   NAME="snd/%k"KERNEL="timer",          NAME="snd/%k"KERNEL="seq",            NAME="snd/%k"

5.系统总线支持和可热插拔总线支持。

在Linux操作系统中,可以使用/sbin/lspci命令来查看目前有那个设备插在PCI插槽中,而这些PCI的信息会存放在/proc/bus/pci/这个子目录中。

[root@localhost ~]# lspci00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]00:01.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)00:02.0 VGA compatible controller: Unknown device 80ee:beef00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controll                                                                                        er (rev 02)00:04.0 System peripheral: Unknown device 80ee:cafe00:05.0 Multimedia audio controller: Intel Corporation 82801AA AC'97 Audio (rev                                                                                         01)00:06.0 USB Controller: Apple Computer Inc. KeyLargo/Intrepid USB00:07.0 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)00:0d.0 SATA controller: Intel Corporation Mobile SATA AHCI Controller (rev 02)

Linux内核支持USB和IEEE1394这两种常见的可热插拔总线。

当Linux操作系统检测到被查到USB或IEEE1349插槽中时,系统就会自动进行如下操作:

1)执行/sbin目录中的hotplug这个程序,并从/etc/hotplug/子目录中载入这个设备所用的驱动程序。

2)之后,将这个设备的相关信息写入/pro/bus/usb子目录中。


可以使用/sbin/lsusb命令来列出哪些设备插在USB插槽中。

[root@localhost ~]# lsusbBus 001 Device 001: ID 0000:0000

oracle Linux会自动挂载USB设备,Linxu系统会将其挂载在/media目录下

[root@localhost ~]# ls -l /etc/hotplugtotal 292-rw-r--r--  1 root root   668 Oct 25  2006 blacklist-rwxr-xr-x  1 root root  6369 Oct 23  2006 dasd.agent-rwxr-xr-x  1 root root  1117 Oct 23  2006 firmware.agent-rwxr-xr-x  1 root root  5223 Oct 23  2006 hotplug.functions-rwxr-xr-x  1 root root  2873 Oct 23  2006 ieee1394.agent-rwxr-xr-x  1 root root  6597 Oct 23  2006 input.agent-rwxr-xr-x  1 root root  3227 Oct 23  2006 input.rc-rwxr-xr-x  1 root root  3370 Oct 23  2006 net.agentdrwxr-xr-x  2 root root  4096 Oct 23  2006 pci-rwxr-xr-x  1 root root  3746 Oct 23  2006 pci.agent-rwxr-xr-x  1 root root  2256 Oct 23  2006 pci.rc-rwxr-xr-x  1 root root  1527 Oct 23  2006 scsi.agent-rwxr-xr-x  1 root root  6967 Oct 23  2006 tape.agentdrwxr-xr-x  2 root root  4096 Oct 16 07:47 usb-rwxr-xr-x  1 root root 13464 Oct 23  2006 usb.agent-rw-r--r--  1 root root 39306 Oct 23  2006 usb.distmap-rw-r--r--  1 root root  4364 Oct 23  2006 usb.handmap-rwxr-xr-x  1 root root 12963 Oct 23  2006 usb.rc-rw-r--r--  1 root root 57453 Oct 16 07:47 usb.usermap

hotplug可以使用设备的驱动

还有一种PCMCIA设备。

当Linux检测到有PCMCIA设备时,会执行以下程序:

1)执行/sbin目录中的cardmgr这个程序,并从/etc/pcmcia子目录中载入适当的模块。

2)之后将这个设备的相关信息写入/etc/bus/pccard

[root@localhost ~]# ls -l /etc/pcmciatotal 212-rw-r--r--  1 root root   961 Oct  7  2006 bluetooth-rw-r--r--  1 root root  2088 Oct  7  2006 bluetooth.confdrwxr-xr-x  2 root root  4096 Oct 16 07:40 cis-rw-r--r--  1 root root 43910 Oct 25  2006 config-rw-r--r--  1 root root  2312 Oct  7  2006 config.opts-rwxr-xr-x  1 root root  1782 Oct  7  2006 ide-rw-r--r--  1 root root   486 Oct  7  2006 ide.opts-rwxr-xr-x  1 root root   853 Oct  7  2006 ieee1394-rw-r--r--  1 root root   232 Oct  7  2006 ieee1394.opts-rwxr-xr-x  1 root root   190 Oct  7  2006 isdn-rwxr-xr-x  1 root root   731 Oct  7  2006 network-rw-r--r--  1 root root  2116 Oct  7  2006 network.opts-rwxr-xr-x  1 root root  1622 Oct  7  2006 parport-rw-r--r--  1 root root   308 Oct  7  2006 parport.opts-rwxr-xr-x  1 root root  1842 Oct  7  2006 scsi-rw-r--r--  1 root root   573 Oct  7  2006 scsi.opts-rwxr-xr-x  1 root root  2678 Oct  7  2006 serial-rw-r--r--  1 root root   570 Oct  7  2006 serial.opts-rw-r--r--  1 root root  3786 Oct  7  2006 shared-rwxr-xr-x  1 root root  2673 Oct  7  2006 wireless-rw-r--r--  1 root root  5810 Oct  7  2006 wireless.opts
看到IDE和SCSI也在内

如果想要控制PCMCIA设备可以使用/sbin/cardctl这个命令,用来监督和控制PCMCIA插槽的状态。

6.系统监视和进程控制工具---top和free

top - 17:49:04 up 9 min,  1 user,  load average: 0.01, 0.16, 0.16(当前,5分钟,10分钟 平均负载)Tasks:  63 total,   2 running,  61 sleeping,   0 stopped,   0 zombie(僵尸进程)Cpu(s):  0.0% us,  0.0% sy,  0.0% ni, 100.0% id,  0.0% wa,  0.0% hi,  0.0% siMem:    774520k total,   240924k used,   533596k free,    34048k buffers(内存)Swap:  2096472k total,        0k used,  2096472k free,   137032k cached(交换区)  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND    1 root      16   0  1644  552  472 S  0.0  0.1   0:00.20 init    2 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0    3 root      34  19     0    0    0 S  0.0  0.0   0:00.01 ksoftirqd/0    4 root       5 -10     0    0    0 S  0.0  0.0   0:00.02 events/0    5 root       6 -10     0    0    0 S  0.0  0.0   0:00.09 khelper    6 root      15 -10     0    0    0 S  0.0  0.0   0:00.00 kacpid   18 root       5 -10     0    0    0 S  0.0  0.0   0:00.00 kblockd/0   36 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pdflush   37 root      15   0     0    0    0 S  0.0  0.0   0:00.02 pdflush   39 root      13 -10     0    0    0 S  0.0  0.0   0:00.00 aio/0   19 root      15   0     0    0    0 S  0.0  0.0   0:00.00 khubd   38 root      25   0     0    0    0 S  0.0  0.0   0:00.00 kswapd0  183 root      25   0     0    0    0 S  0.0  0.0   0:00.00 kseriod  297 root       9 -10     0    0    0 S  0.0  0.0   0:00.00 ata/0

系统默认每5秒刷新一下屏幕。

load average 不应该大于你的系统处理器数目 的2倍

[root@localhost ~]# free             total       used       free     shared    buffers     cachedMem:        774520     241372     533148          0      34592     137008-/+ buffers/cache:      69772     704748Swap:      2096472          0    2096472

7.系统监视和进程控制工具--vmstat和iostat

vmstat  [  时间间隔  ][  显示的记录行数  ]

[root@localhost ~]# vmstatprocs -----------memory---------- ---swap-- -----io---- --system-- ----cpu---- r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa 0  0      0 532956  34696 137164    0    0   124    18 1024    54  1  1 95  4

  • process/r:进程正在等待CPU(运行队列的大小)
  • process/b:进程在不中断的睡眠
  • swap/si:进程从交换区载入内存
  • swap/so:进程滚出交换区上,但是仍然处于运行状态
  • io/bi:载入内存的数据块数
  • io/bo:写入硬盘的数据块数
  • system/in:每秒钟的中断次数
  • system/cs:每秒钟的环境切换的次数
  • cpu/us:执行用户代码所使用的CPU时间
  • cpu/sy:执行系统代码所使用的CPU时间
  • cpu/id:CPU空闲时间
  • cpu/wa:CPU等待时间。
环境切换:就是在时间片内不能完成一个用户的任务,切换到其他用户时,要把这个用户的环境变量保存,压入栈,把下一个用户的环境变量弹出栈。
[root@localhost ~]# vmstat 3 5 (显示3次,每5秒一次)

iostat [   选项  ][  时间间隔  ]  [  刷新显示信息的次数  ]
1)-d 显示硬盘所传输的数据和服务时间,既包括每个硬盘,d为disk首字母
2)-p 包含每个分区的统计信息,p是partition的第一个字母
3)-c 只显示CPU的使用信息
4)-x 显示扩展的硬盘统计信息,x是extend的缩写。

[root@localhost ~]# iostatLinux 2.6.9-42.0.0.0.1.ELsmp (localhost.localdomain)    11/12/2012avg-cpu:  %user   %nice    %sys %iowait   %idle           0.43    0.00    0.43    2.43   96.70Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtnsda               4.12       157.86        25.58     337944      54765sda1              0.42         0.82         0.03       1760         54sda2              8.42       154.87        25.48     331538      54536sda3              0.39         0.50         0.00       1073          0sda4              0.00         0.00         0.00          2          0sda5              1.09         1.18         0.08       2523        175

8.系统进程中的监控。--ps和pgrep

[root@localhost ~]# ps -ef | moreUID        PID  PPID  C STIME TTY          TIME CMDroot         1     0  0 17:39 ?        00:00:00 init [5]root         2     1  0 17:39 ?        00:00:00 [migration/0]root         3     1  0 17:39 ?        00:00:00 [ksoftirqd/0]root         4     1  0 17:39 ?        00:00:00 [events/0]root         5     4  0 17:39 ?        00:00:00 [khelper]root         6     4  0 17:39 ?        00:00:00 [kacpid]root        18     4  0 17:39 ?        00:00:00 [kblockd/0]root        36     4  0 17:39 ?        00:00:00 [pdflush]root        37     4  0 17:39 ?        00:00:00 [pdflush]root        39     4  0 17:39 ?        00:00:00 [aio/0]root        19     1  0 17:39 ?        00:00:00 [khubd]root        38     1  0 17:39 ?        00:00:00 [kswapd0]root       183     1  0 17:39 ?        00:00:00 [kseriod]

1)-e选项  显示所有
2)-f选项显示全部信息。

9.系统中的进程监控:
ptree:以树的形似显示
kill :kill [  -signal ]  PIDS 
pkill:

10.软件包的管理:

1)rpm软件包的具体命名方式:name-version-release.architectures.rpm

RPM安装及移除软件:

1)rpm -i ,--install :安装软件

2)rpm -U ,--upgrade:升级旧版的软件

3)rmp -F,--fresh:刷新更新旧版的软件

4)rpm -e,--erase:移除/删除软件


查询RPM软件包中的信息:

1)rpm -qa:可以显示当前操作系统上安装的全部软件包

2)rpm -qf 文件名:可以显示这个文件由哪个软件包安装的

3)rpm -qi 软件包名:可以显示这个软件包的信息。

4)rpm -ql 软件包名:列出这个软件包中所包含的全部文件。


验证RPM包是否被修改过

       S file Size differs 文件大写被更改       M Mode differs (includes permissions and file type) 文件的权限或类型被修改过       5 MD5 sum differs 表示MD5值与当初安装时不同。       D Device major/minor number mismatch 表示设备的主设备号或从设备号被修改过       L readLink(2) path mismatch 文件的连接路径被修改过       U User ownership differs 文件的拥有者被修改过       G Group ownership differs 文件拥有的群组被修改过       T mTime differs文件的mTime,文件的修改时间       C selinux Context differs selinux(Linux系统安全环境)被修改过


1)rpm -Va:命令将显示所有已经安装rpm软件包文件与RPM数据库进行比较来验证,安装后的文件是否被修改过

[zhao@localhost ~]$ rpm -Va........?   /proc........?   /selinux........?   /sysS.?....T. c /etc/selinux/targeted/booleans..5....TC c /etc/selinux/targeted/contexts/files/file_contexts..5....T. c /etc/selinux/targeted/policy/policy.18.......T. c /etc/libuser.conf

2)rpm -V 软件包名:将显示这有由软件包名所指定的已经安装的rpm软件包与RPM数据库来进行比较来验证文件是否被修改过。

3)rpm -Vp 软件包名 :将已经安装的rpm软件包与软件包名所指定的软件包名进行比较来验证安装后文件哪些被修改过。


验证软件包的RedHat签名:

1)rpm -import RPM-GPG-KEY 命令将RPM-GPG=KEY导入系统。

2)RPM-GPG-KEY导入系统中后,使用rpm -qa gpg-pubkey命令来导入RPM-GPG-KEY的操作是否成功。

3)导入成功,使用rpm -K <package_file>.i386.rpm命令来验证有没有RedHat的签名。


rpm2cpio工具:

这个工具的用途:

因为rpm类型的文件只有root用户才可以安装,而.cpio类型的文件普通用户也可以安装。

[zhao@localhost ~]$ rpm2cpio xxx.rpm > /temp/xxx.cpio




原创粉丝点击