程序员开发实例大全宝库

网站首页 > 编程文章 正文

Linux基础架构学习 - 第二天 - 排除障碍

zazugpt 2024-08-20 00:51:13 编程文章 25 ℃ 0 评论

磁盘

当应用程序或Linux服务器遇到输入/输出(I / O)问题时,开始寻找的几个地方包括以下内容:

  • 磁盘性能
  • 文件系统调整
  • 冗余廉价磁盘阵列(RAID)类型
  • 高速缓存

磁盘类型对磁盘I / O有影响。在计算磁盘瓶颈方面非常有用的几个命令包括iostat和iotop。

iostat显示自您第一次运行时自上次启动以来的值。之后,每个下一个值都是自上次运行以来的值。要确定哪个设备正忙,请查看每秒传输数或tsp值。之后,查看Blk_read和Blk_wrtn值,它们分别以每秒块数表示读取或写入的数据量。每个块是512个字节。

在iostat的输出中,要看的一个更重要的值是iowait。这是CPU在块设备(例如磁盘)上等待的时间。如果此数字很大,则系统上的进程正在等待磁盘I / O,您应该考虑使用更快的磁盘子系统。

值得关注的另一个值是“偷”百分比。这表示虚拟机管理程序从虚拟机窃取CPU周期以提供给另一个虚拟机的时间。如果此数字很大,则您在虚拟机管理程序上运行的虚拟机太多,您需要将某些虚拟机移动到另一个虚拟机管理程序。清单10-8显示了iostat输出的示例。

Listing 10-8. iostat

# iostat
avg-cpu: %user %nice %system %iowait %steal %idle
 0.88 0.01 0.19 0.01 0.00 98.92
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 0.29 1.16 5.52 570626 2704192
dm-0 0.09 0.68 0.32 333948 158440
dm-1 0.00 0.01 0.00 2576 0
dm-2 0.65 0.40 5.19 197626 2544776
dm-3 0.00 0.02 0.00 11834 912
avg-cpu: %user %nice %system %iowait %steal %idle
 22.55 0.00 76.47 0.98 0.00 0.00
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 7.84 0.00 5498.04 0 5608
dm-0 687.25 0.00 5498.04 0 5608
dm-1 0.00 0.00 0.00 0 0
dm-2 0.00 0.00 0.00 0 0
dm-3 0.00 0.00 0.00 0 0
avg-cpu: %user %nice %system %iowait %steal %idle
 6.86 0.00 93.14 0.00 0.00 0.00
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 1210.78 0.00 928674.51 0 947248
dm-0 120155.88 0.00 961247.06 0 980472
dm-1 0.00 0.00 0.00 0 0
dm-2 0.00 0.00 0.00 0 0
dm-3 0.00 0.00 0.00 0 0

在对系统上的磁盘进行故障排除时,必须将分区通用唯一标识符(UUID)映射到分区名称。 blkid命令显示UUID和分区之间的关系,如清单10-9所示。 还显示了lsblk命令,它提供了一个漂亮的磁盘分区树结构,从而帮助您解决与磁盘相关的问题。

Listing 10-9. Linux Partition UUID

# blkid
/dev/loop0: LABEL="CentOS_6.4_Final" TYPE="iso9660"
/dev/sda1: SEC_TYPE="msdos" UUID="0D0B-EDD2" TYPE="vfat"
/dev/sda2: UUID="2494e765-1e20-47e2-a068-d2165e9d6863" TYPE="ext4"
/dev/sda3: UUID="qkXEix-y7nX-KfTD-zGQz-QBgE-f9Uu-0xYO2K" TYPE="LVM2_member"
/dev/sda4: UUID="18PFqD-P7kz-lnzG-4kUe-gL6C-dIer-ShYeVa" TYPE="LVM2_member"
/dev/mapper/vg_hv1-lv_swap: UUID="32a60536-ae0d-4d5b-ac04-2b721e9abee5" TYPE="swap"
/dev/mapper/vg_hv1-lv_root: UUID="7b51a9fa-2514-4c76-b91c-ddb91c336315" TYPE="ext4"
/dev/mapper/vg_hv1-lv_var: UUID="19750d8a-ccf0-4196-a6c2-be7678985cf0" TYPE="ext4"
/dev/mapper/vg_hv1-lv_home: UUID="20e57eef-1be8-4be2-b9a7-aac90ed979c9" TYPE="ext4"
/dev/mapper/vg_hv1-lv_tmp: UUID="0dd34d7a-8749-4c7e-9163-ea78c278cf1d" TYPE="ext4"

文件系统

要解决文件系统问题,首先需要了解磁盘几何以及如何在磁盘上创建文件系统。 磁盘有双面盘片。 在每个盘子上都是称为轨道的同心圆。 曲目分为几个部门。 每个扇区通常为512字节。 圆柱体是盘片的所有表面上的相应轨道组。 清单10-10显示了一个磁盘示例。

Listing 10-10. Disk Partition

# parted
GNU Parted 2.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit mb print
Model: Dell Virtual Disk (scsi)
Disk /dev/sda: 999654MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
 1 1.05MB 211MB 210MB fat16 boot
 2 211MB 840MB 629MB ext4
 3 840MB 210555MB 209715MB lvm
 4 210555MB 600000MB 389445MB bigdisk

有关其他信息,请参阅http://kias.dyndns.org/comath/42.html。

提前阅读

更改预读值有助于加快文件系统的读取速度。 预读通过预取数据并将其加载到页面缓存中来加速文件访问。 默认大小为1024,您可以增加它以加快文件读取速度,如清单10-11所示。

Listing 10-11. Enabling Read-Ahead

# blockdev --getra /dev/sda
1024
# blockdev --setra 2048 /dev/sda
# blockdev --getra /dev/sda
2048

压测

为了防止应用程序磁盘I / O出现问题,一种可能的方法是确定应用程序的磁盘I / O需求,然后使用基准测试工具测试各种存储子系统。 此策略可以正确应用程序部署。 可用于对存储子系统进行基准测试的一些工具包括:

  • Iozone(http://www.iozone.org/)
  • Hdparm(http://linux.die.net/man/8/hdparm)

RAID

在解决磁盘问题时,RAID非常重要。 有很多级别的RAID; 一些常见的包括以下内容:

RAID 0:跨磁盘剥离数据。 没有冗余或容错。 优点是由于多次读写而导致性能提高。

RAID 1:镜像数据而不进行剥离或奇偶校验计算。 至少有两个驱动器; 如果一个失败,您仍然可以访问您的数据

RAID 5:使用分布式奇偶校验进行块级剥离。 奇偶校验分布在驱动器中。 此级别至少需要三个磁盘。 驱动器丢失会导致性能下降。

RAID 6:具有双分布式奇偶校验的块级剥离。 此策略允许两个驱动器发生故障。

RAID 1 + 0:先镜像然后剥离。 此级别至少需要四个磁盘。

RAID 0 + 1:剥离然后镜像。 此级别至少需要四个驱动器。

在解决硬件磁盘问题时,您应该知道正在使用哪个RAID级别(如果有的话)。 这样做的原因是,当一个或多个驱动器发生故障时,某些RAID级别以降级模式运行,而即使一个驱动器发生故障,其他RAID级别也会完全失败。 作为初始设计和实施的一部分,保留备用RAID驱动器始终是一个好主意,以便在RAID驱动器发生故障时使用。 大多数RAID控制器使用备用驱动器自动开始构建故障驱动器。 在重建RAID卷期间,性能通常会降低。 磁盘大小越大,重建逻辑RAID卷所需的时间越长。

您可以在以下处找到有关RAID的更多信息

https://en.wikipedia.org/wiki/RAID

RAID计算器(https://www.icc-usa.com/raid-calculator/)

RAID级别教程(http://www.thegeekstuff.com/2010/08/raid-levels-tutorial/)

Listing 10-12. Increase Page Size

# View Transparent HugePage information
$ cat /proc/meminfo | grep Huge
AnonHugePages: 3162112 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
# View number of huge pages reserved
$ cat /proc/sys/vm/nr_hugepages
0
# Check if transparent huge pages are used by default
$ cat /sys/kernel/mm/redhat_transparent_hugepage/enabled
[always] madvise never
# echo "2000" >> /proc/sys/vm/nr_hugepages
# cat /proc/sys/vm/nr_hugepages
2000

估计任何应用程序的内存使用应该是应用程序设计的一部分。 内存价格波动很大,而且在昂贵的情况下购买内存会导致企业的额外成本。 应用程序的内存饥饿症状包括:

  • 性能缓慢
  • 频繁的应用程序崩溃
  • 性能不一致
  • 数据丢失

记忆类型

Linux内存可以分为以下几种:

  • 物理
  • 交换
  • 高速缓存
  • 缓冲的

物理内存由系统上的内存模块组成。 交换是用于内存的磁盘部分。 缓存是指在物理内存中加载的文件,以加快磁盘访问速度。 缓冲是指物理内存中加载的原始磁盘块。 缓存和缓冲区都会释放回空闲内存池,以便根据需要使用应用程序。 要确定您的系统内存是否正常运行,以下工具非常有用:

free

vmstat

top

sar

如果系统内存不足,可能会发生两件事。 一个是内核恐慌并且系统崩溃。 另一个是,为了防止内核恐慌,Linux激活了内存不足(OOM)杀手。 OOM杀手杀死程序导致内存耗尽。 此策略可防止内核恐慌。 清单10-13是使用其中一些工具来确定系统内存问题的示例。

使用free命令,我们首先检查系统上的可用内存。 该系统具有1GB RAM,如996总大小所示。 通过查看/ proc / meminfo也可以确认内存; MemTotal字段显示1GB RAM。 请注意,缓存为18MB,缓冲区为6MB。 “真正的”可用内存是853MB,我们通过添加free,buffers和cached(828 + 6 + 18 = 852)的值来获得。 此系统没有交换内存,因此显示为0。

Listing 10-13. Memory Troubleshooting

# free -m
 total used free shared buffers cached
Mem: 996 168 828 0 6 18
-/+ buffers/cache: 142 853
Swap: 0 0 0
# head -5 /proc/meminfo
MemTotal: 1020388 kB
MemFree: 848076 kB
Buffers: 6944 kB
Cached: 19176 kB
SwapCached: 0 kB

Let’s run a program that consumes a certain amount of memory—say, 300MB.

##Consume 300MB of memory
# ./eatmemory 300M

当我们在运行300MB程序后检查内存时,我们看到已用内存从168上升到473(168 + 305)。 请注意,缓存和缓冲区保持不变,而 - / + buffers / cache free从853减少到548. 5MB的差异是程序本身正在运行。 我们可以通过查看/ proc / meminfo来确认可用内存的减少,我们发现MemFree现在是535MB而不是848MB。

## Check free memory
# free -m
 total used free shared buffers cached
Mem: 996 473 523 0 6 18
-/+ buffers/cache: 447 548
Swap: 0 0 0
# head -10 /proc/meminfo
MemTotal: 1020388 kB
MemFree: 535072 kB
Buffers: 6960 kB
Cached: 19208 kB
SwapCached: 0 kB

让我们尝试通过将使用量增加900MB来消耗比系统更多的内存。 一旦我们尝试消耗更多的东西,OOM就会开始并杀死我们的程序。 当我们的记忆食者被杀后检查空闲记忆时,免费现在是845MB。 请注意,磁盘缓存从18MB降至6MB。 内核已将内存中加载的磁盘缓存放弃到我们的程序中。 缓冲区也是如此; 他们从6MB下降到1MB。

# ./eatmemory 900M
Eating 943718400 bytes in chunks of 1024...
Killed
# free -m
 total used free shared buffers cached
Mem: 996 150 845 0 1 6
-/+ buffers/cache: 142 853
Swap: 0 0 0

如果我们查看/ var / log / messages,我们会看到一条消息,说明Linux OOM杀手激活并终止正在消耗内存的进程。

Sep 28 14:55:15 server kernel: eatmemory invoked oom-killer: gfp_mask=0x280da, order=0, oom_adj=0, oom_score_adj=0
Sep 28 14:55:15 server kernel: eatmemory cpuset=/ mems_allowed=0
Sep 28 14:55:15 server kernel: Pid: 27950, comm: eatmemory Not tainted 2.6.32-431.5.1.el6.x86_64 #1
Sep 28 14:55:15 server kernel: Call Trace:
Sep 28 14:55:15 server kernel: [<ffffffff810d05a1>] ? cpuset_print_task_mems_allowed+0x91/0xb0
Sep 28 14:55:15 server kernel: [<ffffffff81122950>] ? dump_header+0x90/0x1b0
...[SNIP]...
Sep 28 14:55:15 server kernel: [27830] 89 27830 20340 227 0 0 0 pickup
Sep 28 14:55:15 server kernel: [27950] 0 27950 206967 205992 0 0 0 eatmemory
Sep 28 14:55:15 server kernel: Out of memory: Kill process 27950 (eatmemory) score 779 or sacrifice child
Sep 28 14:55:15 server kernel: Killed process 27950, UID 0, (eatmemory) total-vm:827868kB, anon-rss:823932kB, file-rss:36kB

如果我们在问题之前和之后检查vmstat,我们也可以关联事件。 在我们的记忆采集器启动之前,有865M可用内存。 在我们开始消耗内存后,免费减少到331MB。 当我们开始消耗更多内存时,免费减少到113MB,之后我们的进程被终止并且现在自由返回到864MB。

# vmstat 1
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r b swpd free buff cache si so bi bo in cs us sy id wa st
...[SNIP]...
 0 0 0 865280 1824 7184 0 0 0 12 114 217 0 0 97 3 0
 0 0 0 865280 1824 7188 0 0 0 0 110 206 0 0 100 0 0
 0 0 0 857528 3328 11880 0 0 6172 16 309 694 1 1 82 16 0
 0 0 0 857528 3328 11876 0 0 0 0 109 209 0 0 100 0 0
 0 0 0 855984 3508 12476 0 0 780 0 213 516 1 1 94 4 0
 0 0 0 855992 3508 12480 0 0 0 0 111 207 0 0 100 0 0
 0 0 0 855992 3508 12480 0 0 0 0 108 206 0 0 100 0 0
 0 0 0 856016 3508 12480 0 0 0 0 152 278 0 0 100 0 0
 0 0 0 852744 3784 13820 0 0 1612 44 175 330 0 1 91 8 0
...[SNIP]...
 0 0 0 852792 3860 13824 0 0 0 0 126 232 0 0 100 0 0
 0 0 0 852792 3860 13824 0 0 0 0 116 213 0 0 100 0 0
 ./eatmemory 500M <--- Start consuming memory; notice that free reduces to 331MB from 852MB.
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r b swpd free buff cache si so bi bo in cs us sy id wa st
 0 0 0 331860 3860 13824 0 0 12 0 308 222 3 17 80 0 0
 0 0 0 331860 3860 13836 0 0 0 0 111 210 0 0 100 0 0
 0 0 0 331860 3860 13836 0 0 0 0 108 207 0 0 100 0 0
 0 0 0 331860 3860 13836 0 0 0 4 111 212 0 0 100 0 0
...[SNIP]...
./eatmemory 900M <---- Consume even more memory; free now reduces to 113MB from 331MB.
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r b swpd free buff cache si so bi bo in cs us sy id wa st
 2 1 0 113420 80 924 0 0 1404 32 503 1079 8 30 63 0 0
 OOM kicks in at this point and our process is killed, thereby releasing memory. free is back up to 864MB.
 0 0 0 864684 432 5164 0 0 4000 0 205 684 0 3 97 0 0
 0 0 0 864684 432 5156 0 0 0 0 111 211 0 0 100 0 0

如果我们在几分钟后观察系统,我们会注意到缓冲区和缓存已经增加。 它们分别为80MB和924MB,但由于我们的进程被杀,它们分别增加到5112MB和15,460MB。

## After 10 minutes
# vmstat 1
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r b swpd free buff cache si so bi bo in cs us sy id wa st
 0 0 0 850076 5112 15464 0 0 0 1 2 9 0 0 100 0 0
 0 0 0 850068 5120 15460 0 0 0 12 119 216 0 0 98 2 0

当在/ proc中将panci_on_oom的值设置为0时,OOM杀手将激活。 这是默认值。 如果要禁用OOM,请将值更改为1。

 # cat /proc/sys/vm/panic_on_oom
 0

使用sar我们可以关联我们的发现。 sar应该显示与vmstat一致的输出以及免费的输出。 对sar的一个警告是,默认情况下,它每十分钟报告一次数据。 这意味着如果我们的记忆增加和减少事件发生在十分钟内,我们会错过它们。 您可以使用内部和计数选项从sar获取更精细的数据,如sar <interval> <count>。

$ sar -r
 09:20:01 AM kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit
 ...[SNIP]...
 12:50:01 PM 590372 430016 42.14 99288 172044 157856 15.47
 01:00:01 PM 587620 432768 42.41 99304 172068 163948 16.07
 01:10:01 PM 563184 457204 44.81 99652 192968 165464 16.22
 # At this point we consume 300MB memory; notice kbbuffers goes from 99652 to 5172.
 01:20:02 PM 854128 166260 16.29 5172 14820 173072 16.96
 01:30:01 PM 854012 166376 16.31 5272 14820 173072 16.96
...[SNIP]...
 # Now we run eatmemory with 900MB option, causing kbbuffers to go down even more; same with # kbcached
 03:00:01 PM 860088 160300 15.71 2004 8136 181020 17.74
 03:10:01 PM 858732 161656 15.84 2400 9180 181020 17.74
 # Once the OOM kills the eatmemory process, both kbbuffers and kbcached start to increase
 03:20:01 PM 849680 170708 16.73 5076 15312 181020 17.74

调整虚拟内存

虚拟内存可以定义为物理内存和交换空间。 通常在虚拟内存中,可以找到进程,文件系统缓存和内核。 您可以通过以下方式控制虚拟内

  • Swappiness
  • min_free_kbytes
  • dirty_ratio
  • dirty_background_ratio
  • drop_caches

您可以使用sysctl实用程序或编辑/etc/sysctl.conf文件来修改内核参数。 “Swappiness”是内核将进程交换到磁盘的趋势。 该值可以设置在0到100之间,默认值为60。 将值增加到60以上会导致内核积极交换不活动的进程。 较低的值会导致内核在内存中保持不活动的进程更长时间。 例如,如果您使用的是基于内核的虚拟机(KVM),那么最好不要交换非活动虚拟机,因为它们在虚拟机管理程序上作为Linux进程运行。 因此,您可以选择将swappiness值从60降低到较低的数字。

您无法禁用Linux页面缓存(在free命令的缓存列中看到的值)。 但是,您可以限制缓存值,执行此操作的一些方法如下:

  • vm.vfs_cache_pressure (default = 100): Controls the tendency of the kernel to reclaim memory. Increasing this value makes the kernel reclaim cache memory frequently and hence reduces the size of the page cache.
  • vm.dirty_background_ratio ( default = 20): Linux usually writes data out of the page cache using a process called pdflush. This number indicates the percentage of system memory, the number of pages at which pdflush starts writing out dirty data. Decreasing this number causes pdflush to write out the dirty data sooner.
  • vm.dirty_ratio (default = 40): Indicates the percentage of number of memory pages at which the processes write out their own dirty data. Decreasing this number causes the processes to write out the dirty data sooner rather than later, thereby limiting the size of the page cache.
  • vm.dirty_expire_centisecs (default = 3000 , mentioned in milliseconds): Indicates the expire time for dirty pages. Decreasing this number makes them more eligible to be written out by pdflush.
  • vm.swappiness (default = 60): Decreasing this number causes the page cache size to be limited.

You can read more about Linux memory at

  • https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Performance_Tuning_Guide/s-memory-tunables.html
  • https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Tuning_and_Optimization_Guide/sect-Virtualization_Tuning_Optimization_Guide-Memory-Huge_Pages.html
  • https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Tuning_and_Optimizing_Red_Hat_Enterprise_Linux_for_Oracle_9i_and_10g_Databases/sect-Oracle_9i_and_10g_Tuning_Guide-Large_Memory_Optimization_Big_Pages_and_Huge_Pages-Configuring_Huge_Pages_in_Red_Hat_Enterprise_Linux_4_or_5.html
  • http://www.thomas-krenn.com/en/wiki/Linux_Performance_Measurements_using_vmstat

域名系统

调试域名系统(DNS)最重要的工具之一就是挖掘。 在设置BIND服务器期间,以及之后,使用dig可以帮助解决许多问题的根本原因,并确保您的DNS服务器按预期工作。 dig的使用一般是dig @server名称类型。 如果未指定服务器,则dig会在/etc/resolv.conf中查看服务器。 如果未指定类型,则dig会查找A记录。 清单10-14显示了如何使用dig来查找DNS记录。

Listing 10-14. Using dig command

#query the A record of www.example.com
$ dig www.example.org
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> www.example.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28891
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.example.org. IN A
;; ANSWER SECTION:
www.example.org. 21599 IN A 93.184.216.119
;; Query time: 43 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Tue Aug 26 22:55:38 2014
;; MSG SIZE rcvd: 49

挖掘显示许多有用于故障排除的信息。 让我们回顾一些信息。 首先,挖掘给我们正在使用的挖掘版本; 在这种情况下,它是v9.8。 dig还列出了我们提供的选项,即+ cmd。 虽然我们没有明确说出+ cmd,但这是隐含的。 您也可以在dig命令行中指定+ nocmd,它不会显示使用的选项。

问题部分告诉您,您要求提供www.example.org的A记录。 同样,答案部分显示了所提问题的答案。

查询时间也显示为43毫秒,在这种情况下 - 以及收到的消息大小。

您可以在$ HOME / .digrc文件中指定用于挖掘的各种选项。 设置DNS服务器后,使用dig命令检查来自DNS服务器的响应。

如果你想获得没有所有调试信息的DNS记录,那么你可以使用+ short选项进行挖掘,它只返回答案,如清单10-15所示。

Listing 10-15. dig options

#query the same A record; this time, just return the IP address
$ dig +short www.example.org
93.184.216.119
#find out the start of authority (SOA) for example.org
$ dig +short example.org soa
sns.dns.icann.org. noc.dns.icann.org. 2014080856 7200 3600 1209600 3600
#query the NS or name server record for example.org
$ dig +short example.org ns
b.iana-servers.net.
a.iana-servers.net.
#see if there is a TXT record for example.org
$ dig +short example.org txt
"v=spf1 -all"
"$Id: example.org 2783 2014-08-07 17:40:21Z mvergara $"
#look up the hostname for the given IP address
$ dig +short -x 74.125.239.51
nuq04s19-in-f19.1e100.net.
#find out the MX record for gmail.com
$ dig +short gmail.com mx
20 alt2.gmail-smtp-in.l.google.com.
30 alt3.gmail-smtp-in.l.google.com.
5 gmail-smtp-in.l.google.com.
10 alt1.gmail-smtp-in.l.google.com.
40 alt4.gmail-smtp-in.l.google.com.

NSLOOKUP

nslookup传统上用于调试DNS; 但是,dig已成为nslookup的事实上的替代工具。 nslookup也可以类似于dig的方式使用,并且它支持交互式查询。 清单10-16显示了nslookup的基本用法。

Listing 10-16. nslookup Use

##
# By default 'nslookup' uses the name server in /etc/resolv.conf
$ nslookup
> server
Default server: 8.8.8.8
Address: 8.8.8.8#53
Default server: 8.8.4.4
Address: 8.8.4.4#53
>www.yahoo.com
Server: 8.8.8.8
Address: 8.8.8.8#53
# The reason this answer is nonauthoritative is because 8.8.4.4 is not the authority for yahoo.com.
Non-authoritative answer:
www.yahoo.com canonical name = fd-fp3.wg1.b.yahoo.com.
Name: fd-fp3.wg1.b.yahoo.com
Address: 206.190.36.45
Name: fd-fp3.wg1.b.yahoo.com
Address: 206.190.36.105
# To get the 'mx' record, set the type to 'mx'
> set type=mx
> yahoo.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
yahoo.com mail exchanger = 1 mta7.am0.yahoodns.net.
yahoo.com mail exchanger = 1 mta6.am0.yahoodns.net.
yahoo.com mail exchanger = 1 mta5.am0.yahoodns.net.
> set type=soa
> yahoo.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
yahoo.com
 origin = ns1.yahoo.com
 mail addr = hostmaster.yahoo-inc.com
 serial = 2014092411
 refresh = 3600
 retry = 300
 expire = 1814400
 minimum = 600

BIND统计文件

BIND可以配置为存储有关其性能的统计信息。 要启用BIND统计信息,请在named.conf文件中启用清单10-17中所示的选项。

Listing 10-17. BIND Statistics File

[ statistics-file path_name; ]
[ zone-statistics yes ; ]

要使BIND转储统计信息,请使用rndc stats命令,该命令会导致BIND创建path_name定义的统计信息文件。 在对BIND进行故障排除时,查看统计信息文件非常有用。 如果需要确定BIND服务器正在接收的查询类型,可以在统计文件中找到此信息。 此外,您可以使用统计信息来确定如何扩展BIND服务器。 BIND统计信息可分为以下几个部分:

  • Incoming requests: Total incoming requests into the server
  • Incoming queries: Requests divided by type, A, NS, SOA, and so on
  • Outoging queries: The queries this BIND server made
  • Name server statistics
  • Zone maintenance statistics
  • Resolve statistics
  • Cache database resource record sets (DB RRsets)
  • Socket I/O Statistics
  • Per-zone query statistics

Listing 10-18 shows a brief summary of the BIND statistics file. The statistics are cumulative from the time BIND server was started.

Listing 10-18. BIND Statistics Output

+++ Statistics Dump +++ (1412550650)
++ Incoming Requests ++
 2863814921 QUERY
 6239 NOTIFY
++ Incoming Queries ++
 2059811570 A
 12 NS
 9055 SOA
 193324325 PTR
 195930 MX
 21 TXT
 610472679 AAAA
 1275 SRV
 1 DS
 1 DNSKEY
 52 AXFR
...[SNIP]...

DHCP

Some of the common issues that revolve around troubleshooting DHCP require a basic understanding of the protocol itself. The various messages involved in DHCP are listed in RFC 2131 (https://www.ietf.org/rfc/rfc2131.txt). The various options and vendor extensions are defined in RFC 2132 (https://www.ietf.org/rfc/rfc2132.txt). Some of the messages are as follows:

  • DHCPDISCOVER
  • DHCPOFFER
  • DHCPREQUEST
  • DHCPACK
  • DHCPNAK
  • DHCPDECLINE
  • DHCPRELEASE
  • DHCPINFORM

When a client is configured to use DHCP, it sends out a DHCPDISCOVER message. This is a broadcast message to locate available servers. Because it is broadcast, it is restricted to the broadcast domain, unless IP helpers are enabled on routers that forward DHCP broadcast requests to appropriate DHCP servers.

After a server receives a DHCPDISCOVER message, it responds with DHCPOFFER, which includes configuration parameters. The client then requests a DHCP IP using DHCPREQUEST. The client confirms the parameters that the server sent in the request. The server then sends DHCPACK to the client, confirming the DHCPREQUEST from the client. The server sends DHCPNAK if the client’s lease has expired or if the client has some incorrect parameters in DHCPREQUEST. The client sends DHCPDECLINE to the server if it rejects DHCPOFFER, which could be because the address is already in use. After the client is ready to give up the DHCP IP address, it sends a DHCPRELEASE message. DHCPINFORM is also a client-to-server message that asks for a local configuration.

When debugging a DHCP issue, if you use tcpdump to view network traffic, some or all of the message will be visible. Listing 10-19 shows how to interpret DHCP traffic.

Using tcpdump, we capture DHCP traffic between the client and the server. The DHCP server is 10.1.1.10, with the MAC address 00:50:56:bd:7d:21. The DHCP client has the MAC address 00:50:56:bd:7f:f6 and gets the IP address 10.1.1.50. The tcpdump options we are using are -v (verbose), -n (don’t convert IP to hostname), -e (print link-level header), and -s0 (snarf 0-length bytes of data from each packer, rather than the default 65,535 bytes). We are capturing port 67 and 68 traffic for DHCP.

Initially we see the DHCPDISCOVER message from the client, as is seen in bold type. The destination address of this message is broadcast.

Listing 10-19. DHCP Conversation

# tcpdump -vnes0 -i eth0 port 67 or port 68
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
05:58:12.000470 00:50:56:bd:7f:f6 > Broadcast, ethertype IPv4 (0x0800), length 342: (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from 00:50:56:bd:7f:f6, length 300, xid 0xa033135f, Flags [none]
 Client-Ethernet-Address 00:50:56:bd:7f:f6
 Vendor-rfc1048 Extensions
 Magic Cookie 0x63825363
 DHCP-Message Option 53, length 1: Discover
 Parameter-Request Option 55, length 13:
 Subnet-Mask, BR, Time-Zone, Classless-Static-Route
 Domain-Name, Domain-Name-Server, Hostname, YD
 YS, NTP, MTU, Option 119
 Default-Gateway

The server then responds to the client with DHCPOFFER, as seen in bold type.

05:58:13.001158 00:50:56:bd:7d:21 > 00:50:56:bd:7f:f6, ethertype IPv4 (0x0800), length 342: (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
10.1.1.10.bootps > 10.1.1.50.bootpc: BOOTP/DHCP, Reply, length 300, xid 0xa033135f, Flags [none]
 Your-IP 10.1.1.50
 Client-Ethernet-Address 00:50:56:bd:7f:f6
 Vendor-rfc1048 Extensions
 Magic Cookie 0x63825363
 DHCP-Message Option 53, length 1: Offer
 Server-ID Option 54, length 4: 10.1.1.10
 Lease-Time Option 51, length 4: 600
 Subnet-Mask Option 1, length 4: 255.255.255.0
 BR Option 28, length 4: 172.24.81.255
 Domain-Name Option 15, length 14: "example.com"
 Domain-Name-Server Option 6, length 8: 172.24.0.7,172.24.0.8
 Default-Gateway Option 3, length 4: 172.24.81.3

The third step is the client responding with DHCPREQUEST.

05:58:13.001634 00:50:56:bd:7f:f6 > Broadcast, ethertype IPv4 (0x0800), length 342: (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
0.0.0.0.bootpc > 255.255.255.255.bootps: BOOTP/DHCP, Request from 00:50:56:bd:7f:f6, length 300, xid 0xa033135f, Flags [none]
 Client-Ethernet-Address 00:50:56:bd:7f:f6
 Vendor-rfc1048 Extensions
 Magic Cookie 0x63825363
 DHCP-Message Option 53, length 1: Request
 Server-ID Option 54, length 4: 10.1.1.10
 Requested-IP Option 50, length 4: 10.1.1.50
 Parameter-Request Option 55, length 13:
 Subnet-Mask, BR, Time-Zone, Classless-Static-Route
 Domain-Name, Domain-Name-Server, Hostname, YD
 YS, NTP, MTU, Option 119
 Default-Gateway

The fourth step is the client responding with DHCPACK.

05:58:13.003958 00:50:56:bd:7d:21 > 00:50:56:bd:7f:f6, ethertype IPv4 (0x0800), length 342: (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
10.1.1.10.bootps > 10.1.1.50.bootpc: BOOTP/DHCP, Reply, length 300, xid 0xa033135f, Flags [none]
 Your-IP 10.1.1.50
 Client-Ethernet-Address 00:50:56:bd:7f:f6
 Vendor-rfc1048 Extensions
 Magic Cookie 0x63825363
 DHCP-Message Option 53, length 1: ACK
 Server-ID Option 54, length 4: 10.1.1.10
 Lease-Time Option 51, length 4: 600
 Subnet-Mask Option 1, length 4: 255.255.255.0
 BR Option 28, length 4: 172.24.81.255
 Domain-Name Option 15, length 14: "example.com"
 Domain-Name-Server Option 6, length 8: 172.24.0.7,172.24.0.8
 Default-Gateway Option 3, length 4: 172.24.81.3

Conclusion

In this chapter we covered troubleshooting TCP/IP, CPU, disk, memory, DNS, and DHCP. We looked at a number of tools, specific to the topics, that can be used to debug the various problem you may encounter. Some additional tools that are worth looking into are the following :

  • Valgrind: For memory analysis (http://valgrind.org/)
  • OProfile: For application profiling (http://oprofile.sourceforge.net/news/)
  • SystemTap: For gathering information about running systems (https://sourceware.org/systemtap/)
  • Perf: For statistics on running programs (https://perf.wiki.kernel.org/index.php/Main_Page)

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表