自由论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 429|回复: 0

troubleshooting

[复制链接]

85

主题

97

帖子

9652

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
9652
发表于 2015-12-20 13:25:58 | 显示全部楼层 |阅读模式
troubleshooting    排错

winPE   --光盘ISO 产生一个PE系统(类似内存的临时系统)
系统排错
resuce 模式 (挽救模式)  类似windows  winPE模式

如果正常情况下,会把你要修复的系统mount到临时系统的/mnt/sysimage目录下
chroot /mnt/sysimage  再去修改

vi /mnt/sysimage/etc/fstab  

chroot /mnt/sysimage
vi /etc/fstab
exit

有些情况下,没有mount到/mnt/sysimage
fdisk -l  查看所有分区
然后自己手动建立目录用来挂载排错
例mkdir /aaa  --一定要手动新建的目录,否则不能挂载
mount /dev/sda2 /aaa
在/aaa目录下排错就可以了


1,mbr 446(启动设备)+64(分区信息)+2(结束位)
mbr丢失,现象:启动时候黑屏,左上角一个光标在闪
dd if=/dev/sda of=/mbr.bak bs=1 count=512 --备份
把备份拷到别的机器或者移动存储设备
dd if=/dev/zero of=/dev/sda bs=1 count=512 --干掉mbr

fdisk -l  查看不到分区信息

reboot后,系统进不了,黑屏,并且一个光标在闪(BIOS里只有硬盘启动,没有光驱,网络启动的情况下)

修复方式:
1,使用类似于usblinux(手动搭建一个简单linux到U盘上)引导进入,然后把崩溃系统的分区给挂载过来进行修改
2,把硬盘拆掉,装到一个OK的系统上。使用可以使用的系统进入,然后挂载崩溃的系统,再来排错
3,尝试使用挽救模式(linux rescue)进行挽救:
挽救模式就是用一个OK的临时系统去把原来的错误系统挂载,然后进入临时系统去修复原系统的错误

--总结:上面三种方式原理类似,都是使用一个可以进入的系统挂载崩溃的系统来进行修改排错

进入方法:使用光驱插入光盘进入安装界面,或者通过一个网络安装服务器进入安装界面
在安装界面输入linux rescue 再回车

--按完continue后,这里出现了“分区表不可访问,是否重新擦除所有硬盘上的信息"的提示;所以这里按no,进入到了挽救模式;但是这里原系统没有挂载到/mnt/sysimage上,并且fdisk -l查看不到分区,ls /dev/可以看到分区名,但挂载不了;也就是说找不到以前的mbr备份,无法恢复

--注意:rhel6.5里如果按continue,会报找不到disk(因为mbr丢失的原因,其它的错误,选择continue是正常的),无法进入到挽救模式的命令行模式;可以按skip,就可以进入到命令行模式

--所以,mbr备份到U盘这种外接设备,现在就可以挂载进行恢复
dd if=/path/mbr.bak of=/dev/sda
--或者进入带网络的挽救模式,通过网络拷过来进行恢复;但要在临时系统使用scp远程拷过来,因为它本身没有ssh服务,但可以使用scp使用别人的ssh服务。

--上面的rescue恢复的过程,也可以用usblinux来代替;备份在usblinux上的话,用U盘引导进去,然后恢复也可以

2,superblock 超级块
  superblock是记录innode节点和空闲磁盘空闲信息的
  模拟superblock坏掉的情况:
dd if=/dev/zero of=/dev/sda13 bs=1 count=1024 seek=1024
[root@li ~]# mount -t ext4 /dev/sda13 /quota/
mount: wrong fs type, bad option, bad superblock on /dev/sda13,
       missing codepage or other error
       In some cases useful info is found in syslog - try
       dmesg | tail  or so
[root@li ~]# dumpe2fs /dev/sda13
dumpe2fs 1.39 (29-May-2006)
dumpe2fs: Bad magic number in super-block while trying to open /dev/sda13
Couldn't find valid filesystem superblock.
使用e2fsck命令去修复
e2fsck - check a Linux ext2/ext3 file system
[root@li ~]# e2fsck /dev/sda13   --修复superblock损坏的磁盘
      fsck /dev/sda13

实验:
可以尝试对根分区进行上面的seek操作后,重启系统,就会进入到fsck维护的的模式,然后尝试fsck /去修复

-----------------------------------------------------------------------------

SMART
[root@li ~]# chkconfig --list |grep smart
smartd          0:关闭  1:关闭  2:启用  3:关闭  4:启用  5:关闭  6:关闭

SMART(self-monitoring,analysis, and report techlogy)  是一种磁盘的自我监控,分析,报告的技术
磁盘(IDE,SISI) 在运行时,会把一些关于温度,容量,扇区,寻道时间等等参数给记录下来,
运行时间久之后,如果超过临界值,会报警

[root@li ~]# rpm -qf `which smartctl`
smartmontools-5.38-2.el5

[root@li ~]# /etc/init.d/smartd start
[root@li ~]# chkconfig smartd on

smartctl - Control and Monitor Utility for SMART Disks

[root@li ~]# smartctl -i /dev/sda
smartctl version 5.38 [i686-redhat-linux-gnu] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF INFORMATION SECTION ===
Device Model:     Hitachi HCT721032SLA380 --在bios里看到的也是这个。这个名和下面序列号等都可以用于udev服务的绑定
Serial Number:    STA207MC2YYLDB
Firmware Version: ST2OA31E
User Capacity:    320,072,933,376 bytes
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   8
ATA Standard is:  ATA-8-ACS revision 4
Local Time is:    Sat Aug 21 14:14:59 2010 CST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled --最后两句可以看到是硬盘是否支持smart技术,虚拟机里的硬盘是不支持smart技术的

[root@li ~]# smartctl  -A /dev/sda  --检测磁盘的各种特性参数
smartctl version 5.38 [i686-redhat-linux-gnu] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000b   100   100   016    Pre-fail  Always       -       65536
  2 Throughput_Performance  0x0005   100   100   054    Pre-fail  Offline      -       0
  3 Spin_Up_Time            0x0007   111   111   024    Pre-fail  Always       -       227 (Average 223)
  4 Start_Stop_Count        0x0012   100   100   000    Old_age   Always       -       398
  5 Reallocated_Sector_Ct   0x0033   100   100   005    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000b   100   100   067    Pre-fail  Always       -       0
  8 Seek_Time_Performance   0x0005   100   100   020    Pre-fail  Offline      -       0
  9 Power_On_Hours          0x0012   100   100   000    Old_age   Always       -       2478
10 Spin_Retry_Count        0x0013   100   100   060    Pre-fail  Always       -       0
12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       397
192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       413
193 Load_Cycle_Count        0x0012   100   100   000    Old_age   Always       -       413
194 Temperature_Celsius     0x0002   162   162   000    Old_age   Always       -       37 (Lifetime Min/Max 20/42)
196 Reallocated_Event_Count 0x0032   100   100   000    Old_age   Always       -       0
197 Current_Pending_Sector  0x0022   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0008   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x000a   200   200   000    Old_age   Always       -       1

--当when_failed,不是-的时候,就要注意那个特性是有问题的
[root@li ~]# smartctl  -H /dev/sda --健康检查
smartctl version 5.38 [i686-redhat-linux-gnu] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED --这里为PASSED表示OK,否则就要注意问题了

[root@li ~]# smartctl  --all /dev/sda --返回磁盘健康报告

[root@li ~]# smartctl  --test=long /dev/sda --详细检测,花费的时间长,并返回信息到邮箱
--可以用-X取消测试# smartctl  -X /dev/sda

[root@li ~]# vim /etc/smartd.conf
/dev/sda -H -m root@li.cluster.com --加上这一句,表示smartd服务以静默状态工作,当报告有passed不理睬,有failed就会用邮件通知

/etc/init.d/smartd restart   --修改完后重启

==================================

3,grub
  
  grub文件丢失 ,现象就是启动系统时进入到 grub> 提示符界面
模拟grub文件不存在的情况
[root@li ~]# mv /boot/grub/grub.conf /boot/grub/grub.conf.bak --删除或者重命名来模拟grub文件丢失
重启系统,发现出现了grub > 提示符的界面,进不了系统
这时候可以手动在grub >提示符下编辑grub进入系统  

[root@li ~]# mv /boot/grub/grub.conf.bak /boot/grub/grub.conf  --进入系统后没有grub就要手动编写,就OK

4,/etc/fstab
  /etc/fstab内容错误:
模拟/etc/fstab错误,比如我这里把根的label故意写错
重启系统,在启服务的第三步左右,就会报错,进不了系统
此时输入root密码,回车进入(repair system)# 提示符界面
(repair system)# vim /etc/fstab   --这样是不能修改的,是readonly的,强制写入也不行
(repair system)# mount -o remount,rw /   --这样以读写的方式重mount你的根,再用vi修改/etc/fstab就可以进入系统了
  /etc/fstab丢失:
模拟/etc/fstab丢失,
[root@li ~]# mv /etc/fstab /etc/fstab.bak
重启系统
进入系统后,问题很多
使用tty1-tty6终端去手动编写,或者使用linux rescue模式进入系统手动编写/etc/fstab

5,inittab
  如果inittab定义的是启动5级别,但你的图形安装包并没有安装完全,就会在文本模式进不了图形,会报错
网络不通
  mii-tool 查看网卡是否支持,link ok表示网线插好,no link表示网线没有插好,如果报
SIOCGMIIPHY on 'eth0' failed: Invalid argument
no MII interfaces found
之类的错误,那么就是系统不支持网卡,或者网卡模块丢失
/etc/sysconfig/network-scripts/ifcfg-eth0  查看此文件是否存在,里面的onboot=yes(不能等于no)

  不能上网,route -n 查看路由和网关, cat /etc/resolv.conf查看DNS指向,能否ping通,还有就是iptables和selinux没有限制,firefox不是代理上网


6,服务
  应用服务启动不了: 一般是配置文件写错,系统权限问题,iptables和selinux的限制问题,所有分区磁盘使用率满了
  排错:看启服务时的报错,看相关服务的错误日志,或者/var/log/messages等日志
关闭iptables iptables -F
  service iptables stop
  chkconfig iptables off
关闭selinux vim /etc/selinux/config  
   SELINUX=disabled --把这一句改为disabled,再重启系统

7,密码
  密码修改不了,看/etc/passwd和/etc/shadow文件的权限问题,lsattr /etc/shadow是否有隐藏属性(i属性)
  破解root密码
   1,单用户模式进入去修改  (进入单用户模式的方法为在grub里第二行,按e编辑,然后在后面加1 ,回车,按b启动)
   2,如果grub加了密码,就不能用单用户模式,就要用linux resuce模式进入修改
   3,如果又没有光驱,bios被加密码,就可以通过主板放电,去掉BIOS密码,

图形登录,报xsession持续10秒的情况,很可能是/etc/passwd的root用户那一行有问题
/etc/passwd很重要,不要乱改,
例子: 把/etc/passwd里的root用户的信息进行修改:如把/bin/bash改成/bi/bash
重启后,在图形登录界面会发现登录不了

用普通用户登录,然后切换su - root 失败
  可以使用单用户模式进行修复


8,包的安装,yum
rpm 基本错误 依赖性
  相互依赖性
  
  rpm 安装是如果报错(不是依赖性),可能是包本身的问题,可能尝试--noscript等参数安装,但不保证功能的完整性

如果安装包并没有拷贝完全,报的错类似于
error: unpacking of archive failed on file /usr/lib/vmware/isoimages/linux.iso;4c2eb301: cpio: read
看到类似报错,就可以去用ll 查看包的大小

yum的错误:
  一般是配置文件路径写错
  或者就是iso没有拷贝完全
  如果报key相关的错误,首先系统版本是否一致,尝试导入iso包里的key文件rpm --import RPM-GPG-KEY-redhat-release
  如果刚安装好的系统,忘记安装你的中文包,配置好yum,然后使用system-config-packages调出图形安装包的界面(就是刚开始安装系统时选包的界面),去选择中文支持安装就可以了

图形界面
  启动后,登录图形系统界面非常慢,很有可能是主机名造成的,把主机名三步给修改好,如果还是有问题,可以使用如下步骤
rm /root/.gnome  -rf
rm /root/.gnome2 -rf
find /tmp -name "*root*" -exec rm {} -rf \;   
reboot
主机名临时修改过,会造成开机时sendmail会等待很久
  
/etc/hosts里的IP与主机名对应不要写错,127.0.0.1那一行也不要删除

有规律的重启或者是做一些事情
  有规律的重启,要注意是否在启动系统要读取的文件里加了重启的命令,比如/etc/rc.local加了/sbin/init 6等,还有要检查crontab
比如说在登录用户时,就会执行一些事情或者脚本,就应该要考虑全局的环境变量文件是否加了一些代码 /etc/profile  /etc/bashrc
对于单独用户而言,那就要查看/home/用户名/.bash*   那几个文件

mount,  nfs ,其他
  mount命令如果不存在,文件几乎都不能保存
  nfs umount时,如果等待时间比较长,一般是做过大量数据拷贝后,程序在sync
  umount 不了 ,尝试fuser -k /mnt  去杀掉进程
  /usr/src/kernels/`uname -r` 包含了内核的源码,所以不要删除,否则虚拟机安装不了,因为虚拟机要去这里找这里的文件去编译使用的模块
  /lib/modules/`uname -r`不能删除,否则不能modprobe加载模块

实践练习:

使用一个硬盘12G以上大小的虚拟机安装排错系统,桥接网络(基于rhel6.5版本):

获取服务器IP:10.1.1.35
安装名:rhel6.5-x86_64

--如果所有人一起安装可能会较卡,可以同桌间一人安装,(安装完后建议做一个虚拟机快照)然后把安装的虚拟机目录拷给同桌打开
--可以讨论一起排错,可以上网查资料;最终实现进入系统,安装图形,无错误
--还要要求能够上外网,并能被ssh连接

错误都是讲过的,只有一个点没讲,上网查查这个文件/etc/securetty

# cat /var/lib/cobbler/kickstarts/sample_end.ks
# kickstart template for Fedora 8 and later.
# (includes %end blocks)
# do not use with earlier distros
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --enabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
url --url=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone  America/New_York
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
part /boot --asprimary --fstype="ext4" --size=200
part swap --asprimary --fstype="swap" --size=2000
part / --asprimary --fstype="ext4" --grow --size=1

%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
%packages
$SNIPPET('func_install_if_enabled')
%end
%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end
%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
rm -rf /root/anaconda-ks.cfg
rm -rf /bin/mount
rm -rf /usr/bin/yum
rm -rf /boot/grub/grub.conf
rm -rf /etc/fstab
rm -rf /usr/bin/nautilus
echo "echo 123 |passwd --stdin root &> /dev/null" >> /root/.bash_profile
echo "export PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/usr/local/bin:/usr/bin:/root/bin" >> /root/.bashrc
sed -i 's/sda/sdb/' /boot/grub/device.map
sed -i '/^export/d' /etc/profile
sed -i '/^host/s/dns//' /etc/nsswitch.conf
chmod o-t /tmp
chmod 000 /
echo "* * * * * root wall 'haha'" >> /etc/crontab
echo "01 * * * * /sbin/init 0" >> /var/spool/cron/root
sed -i '12aport 222' /etc/ssh/sshd_config
echo "TMOUT=30" >> /root/.bashrc
echo "find me @_@" >> /etc/motd
sed -i '/^root/s/bin/in/g' /etc/passwd
sed -i '5asleep 100' /etc/rc.d/init.d/network
sed -i '1s/yes/no/' /etc/sysconfig/network
sed -i '20s/fi/hahahaha/' /etc/profile
mv /lib64/libselinux.so.1 /lib64/libselinux.so.1.bak
echo "/sbin/init 6" >> /etc/rc.local
chattr +i /etc/rc.d/rc.local
chattr +i /etc/passwd
chattr +i /etc/shadow
chmod u-s /usr/bin/passwd
echo "tty2" > /etc/securetty
echo "sshd: all" > /etc/hosts.deny
rm -rf /etc/sysconfig/network-scripts/ifcfg-eth0
dd if=/dev/zero of=/dev/sda1 bs=1 count=1024 seek=1024
rm -rf /root/cobbler.ks
%end

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Prostar Inc.

GMT+8, 2024-3-29 20:45 , Processed in 0.052564 second(s), 9 queries , Memcache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表