linux 硬件管理

Linux硬件管理

总核数 = 物理CPU个数 X 每颗物理CPU的核数
总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数

一般情况,我们认为一颗cpu可以有多核,加上intel的超线程技术(HT)。

Linux cat /proc/cpuinfo 具有相同core id的CPU是同一个core的超线程,具有相同physical id的CPU是同一个CPU封装的线程或核心。

hardware info

1
2
3
4
5
6
7
8
9
getconf LONG_BIT
dmesg
lspci [ -i | -tv ]
ll /sys/class/class_name/
lsusb
lsscsi [ -b | -v ]
lshw
dmidecode
tune2fs -l /dev/sdc

CPU

1
2
3
lscpu
numactl

modules

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
[root@db ~]# clear

[root@db ~]# pwd
/root
[root@db ~]# modinfo r8169
filename: /lib/modules/3.10.0-1062.18.1.el7.x86_64/kernel/drivers/net/ethernet/realtek/r8169.ko.xz
firmware: rtl_nic/rtl8107e-2.fw
firmware: rtl_nic/rtl8107e-1.fw
firmware: rtl_nic/rtl8168h-2.fw
firmware: rtl_nic/rtl8168h-1.fw
firmware: rtl_nic/rtl8168g-3.fw
firmware: rtl_nic/rtl8168g-2.fw
firmware: rtl_nic/rtl8106e-2.fw
firmware: rtl_nic/rtl8106e-1.fw
firmware: rtl_nic/rtl8411-2.fw
firmware: rtl_nic/rtl8411-1.fw
firmware: rtl_nic/rtl8402-1.fw
firmware: rtl_nic/rtl8168f-2.fw
firmware: rtl_nic/rtl8168f-1.fw
firmware: rtl_nic/rtl8105e-1.fw
firmware: rtl_nic/rtl8168e-3.fw
firmware: rtl_nic/rtl8168e-2.fw
firmware: rtl_nic/rtl8168e-1.fw
firmware: rtl_nic/rtl8168d-2.fw
firmware: rtl_nic/rtl8168d-1.fw
license: GPL
softdep: pre: realtek
description: RealTek RTL-8169 Gigabit Ethernet driver
author: Realtek and the Linux r8169 crew <netdev@vger.kernel.org>
retpoline: Y
rhelversion: 7.7
srcversion: 6A480409F7BC52AD7A76C65
alias: pci:v00000001d00008168sv*sd00002410bc*sc*i*
alias: pci:v00001737d00001032sv*sd00000024bc*sc*i*
alias: pci:v000016ECd00000116sv*sd*bc*sc*i*
alias: pci:v00001259d0000C107sv*sd*bc*sc*i*
alias: pci:v00001186d00004302sv*sd*bc*sc*i*
alias: pci:v00001186d00004300sv*sd*bc*sc*i*
alias: pci:v00001186d00004300sv00001186sd00004B10bc*sc*i*
alias: pci:v000010ECd00008169sv*sd*bc*sc*i*
alias: pci:v000010FFd00008168sv*sd*bc*sc*i*
alias: pci:v000010ECd00008168sv*sd*bc*sc*i*
alias: pci:v000010ECd00008167sv*sd*bc*sc*i*
alias: pci:v000010ECd00008161sv*sd*bc*sc*i*
alias: pci:v000010ECd00008136sv*sd*bc*sc*i*
alias: pci:v000010ECd00008129sv*sd*bc*sc*i*
alias: pci:v000010ECd00002600sv*sd*bc*sc*i*
alias: pci:v000010ECd00002502sv*sd*bc*sc*i*
depends:
intree: Y
vermagic: 3.10.0-1062.18.1.el7.x86_64 SMP mod_unload modversions
signer: CentOS Linux kernel signing key
sig_key: 7C:BA:6E:56:2A:CC:BE:D5:25:80:E7:39:32:4E:8A:D4:10:92:CF:1F
sig_hashalgo: sha256
parm: debug:Debug verbosity level (0=none, ..., 16=all) (int)



ll /lib/modules/`uname -r`/kernel
[x@db kernel]$ pwd
/lib/modules/3.10.0-1062.18.1.el7.x86_64/kernel
[x@db kernel]$ modinfo arch/x86/crypto/sha512-ssse3.ko.xz
filename: /lib/modules/3.10.0-1062.18.1.el7.x86_64/kernel/arch/x86/crypto/sha512-ssse3.ko.xz
alias: crypto-sha384
alias: sha384
alias: crypto-sha512
alias: sha512
description: SHA512 Secure Hash Algorithm, Supplemental SSE3 accelerated
license: GPL
retpoline: Y
rhelversion: 7.7
srcversion: 7FA421199BB7545B6354892
depends: sha512_generic
intree: Y
vermagic: 3.10.0-1062.18.1.el7.x86_64 SMP mod_unload modversions
signer: CentOS Linux kernel signing key
sig_key: 7C:BA:6E:56:2A:CC:BE:D5:25:80:E7:39:32:4E:8A:D4:10:92:CF:1F
sig_hashalgo: sha256
[x@db]$ lsmod
[x@db]$ modprobe virtio_blk
[x@db]$ vim /etc/sysconfig/modules/virtio.modules
modprobe virtio_blk
modprobe virtio_scsi
[x@db]$ chmod a+x /etc/sysconfig/modules/virtio.modules
[x@db]$ insmod /lib/modules/`uname -r`/kernel/drivers/char/watchdog/softdog.ko
[x@db]$ rmmod -s softdog
[x@db]$ man 5 modprobe.conf

kernel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@db ]# ll /proc/sys
total 0
dr-xr-xr-x 1 root root 0 Oct 27 10:08 abi
dr-xr-xr-x 1 root root 0 Oct 11 12:23 crypto
dr-xr-xr-x 1 root root 0 Oct 27 10:08 debug
dr-xr-xr-x 1 root root 0 Oct 27 10:08 dev
dr-xr-xr-x 1 root root 0 Oct 11 12:23 fs
dr-xr-xr-x 1 root root 0 Oct 11 12:23 kernel
dr-xr-xr-x 1 root root 0 Oct 11 12:23 net
dr-xr-xr-x 1 root root 0 Oct 27 10:08 user
dr-xr-xr-x 1 root root 0 Oct 11 12:23 vm

[x@db]$ sysctl -a
[x@db]$ sysctl -w
[x@db]$ vim /etc/sysctl.conf
net.ipv4.ip_forward = 1

network

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
iwconfig
hwconfig
ethtool
lspci| grep -i net
sar -n DEV 1 2 //观察网卡流量


@ mii-tool
mii-tool -v
mii-tool -w
mii-tool -F 100baseTx-FD eth0 //将eth0改为100M,全双工工作模式
mii-tool -r eth0 //恢复网卡工作模式
ethtool eth0 //查询网卡基本设置
ethtool -s eth0 autoneg off speed 100 duplex full //eth0设置为:100M,全双工,非协商


@ ifconfig
ifconfig -h //打印帮助信息
ifconfig -a //打印当前网卡信息
ifconfig eth0 192.168.0.1 netmask 255.255.255.0 //设置eth0 IP及掩码
ifconfig eth0:0 192.168.0.2 netmask 255.255.255.0 //设置eth0的第二个IP
ifconfig eth0:1 down //禁用eth0:0
ifconfig eth0 up //启用eth0
ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx //修改网卡MAC地址
ifconfig eth0 promisc //设置网卡工作于混杂模式下
iwconfig eth0 essid "tao" //设置无线网卡的essid为“tao”
iwconfig eth0 mode Managed //设置无线网卡工作在Managed模式下
iwconfig eth0 mode Ad-hoc //设置无线网卡工作在Ad-hoc模式下
iwconfig eth0 freq 2.422G //设置无线网卡工作频率

设备文件

  • 字符型设备文件
  • 块设备文件
  • 网络设备文件

udev(device manager)[1][2]

1
2
3
4
udevadm info -a -p /sys/class/net/eth0
cat /etc/udev/rules.d/70-persistent-net.rules
ls -l /dev
ls -l /sys/class/scsi_device

disk

1
2
3
fdisk
smartctl
dd if=/dev/zero bs=512 count=100 | od -c
1
2
3
sg_map -x (ll /sys/block/)
echo "- - -" > /sys/class/scsi_host/hostN/scan
echo 1> /sys/class/fc_host/hostN/issue_lip
1
2
3
4
5
6
7
8
9
10
11
12
# 查看存储供应商参数及型号
lsblk -S
cat /sys/block/sdx/device/vendor
cat /sys/block/sdx/device/model

# 查看设备uuid
lsscsi -i
blkid
ll /dev/disk/by-id
ll /dev/disk/by-path
/lib/udev/scsi_id --whitelisted --device=/dev/sd*
/lib/udev/scsi_id -s 3 -g -u -d /dev/sd*

多路径[3]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# rhel multipath
multipath -ll

# EMC powerpath
powermt display dev=all

# ultrapath
upadmin show vlun

# hitachi hdlm
dlnkmgr view -path
dlnkmgr view -drv
dlnkmgr view -sys
dlnkmgr view -lu
dlnkmgr view -item -lu //查看存储SN和LUN_ID

linux安装powerpath[4][5]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 安装软件
rpm -ivh EMCPower.LINUX-6.0.1.00.00-043.RHEL6.x86_64.rpm
# 注册license
emcpreg -add key A3DF-3BDD-UHYT-CD6F-EV74-KJUT
emcpreg -list
powermt check_registration
# 查看服务
ps -ef |grep power
service powerpath status
# 重启主机
reboot
# 用emc存储管理命令显示设备
powermt display dev=all
# 显示设备
ls -l /dev/emcpower*

Oracle绑定EMC设备规则rule

1
2
3
4
5
6
7
8
9
10
cat >> /etc/udev/rules.d/99-oracle-asmdevices.rules <<  EOF
SUBSYSTEM=="block", KERNEL=="emcpowera", GROUP="asmadmin", OWNER="grid", MODE="0660"
SUBSYSTEM=="block", KERNEL=="emcpowerb", GROUP="asmadmin", OWNER="grid", MODE="0660"
EOF


/sbin/udevadm control --reload-rules
/sbin/udevadm trigger --type=devices --action=change
ls -ltr /dev/emc*
ASM 磁盘搜索路径需要改为/dev/emc*

multipath[6][7]

1
2
3
4
5
6
7
8
9
10
11
12
13
yum install -y device-mapper*
modprobe dm-multipath
modprobe dm-round-robin
service multipathd start
multipath -v2
# 删除
multipath -F
# 查看wwid
cat /etc/multipath/bindings
multipath -v3
multipath -ll
ls -l /dev/mapper/*

raid

1
2
3
4
5
6
7
8
9
10
11
12
./MegaCli64 -FwTermLog -Dsply -aALL > /tmp/ttylog.txt	创建 RAID 控制器日志(tty)

./MegaCli64 -PDList -aALL > /tmp/disks.txt 使用有关已安装的 RAID 控制器、虚拟磁盘和硬盘的信息创建列表

./MegaCli64 -LDInfo -LALL -aALL > /tmp/LDinfo.txt 使用有关现有 RAID 卷和配置的信息创建列表

./MegaCli64 -AdpAllInfo -aALL > /tmp/Adapterinfo.txt 使用有关 RAID 控制器设置的信息创建列表

./MegaCli64 -AdpBbuCmd -aALL > /tmp/Battery.txt 创建 RAID 控制器的电池状态的详细列表(充电状态、学习周期等)。

./MegaCli64 -AdpEventLog -IncludeDeleted -f deleted.txt -aALL 使用自第一次控制器初始化以来的所有信息创建 RAID 控制器日志(tty)(注意:此文件将始终保存在 MegaCLI 根文件夹中)

hba

Linux

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
lspci | grep -i fibre
lspci -vvv | grep -i fibre
systool -av -c fc_host (ubuntu sysfsutils)

@ 读取sys文件

# HBA是否online和wwn号
[root@361way.com ~]# cat /sys/class/fc_host/host4/port_state
Online
[root@361way.com ~]# cat /sys/class/fc_host/host4/port_name
0x10000090fa9b1724
#查看具体的HBA卡型号信息
[root@361way.com ~]# cat /sys/class/scsi_host/host4/modelname
AJ763B/AH403A
[root@361way.com ~]# cat /sys/class/scsi_host/host4/modeldesc
HP 8Gb Dual Channel PCI-e 2.0 FC HBA
#常看ROM版本
[root@irora09s ~]# cat /sys/class/scsi_host/host4/option_rom_version
5.20x13

AIX

1
2
lsdev -Cc adapter -S a | grep fcs
lscfg -pvl fcs_name

HPUX

1
2
ioscan -fnC fc
fcmsutil /dev/fcd0

Reference


  1. linux.com Udev: Introduction-device-management-modern-linux ↩︎

  2. csdn: redhat 7.x 、redhat 6.x查看硬盘UUID方法 ↩︎

  3. 51cto: 深入理解iSCSI的2种多路径访问方式 ↩︎

  4. 多路径软件查看命令及 EMC 绑定方法参考 ↩︎

  5. Linux 6.5下安装EMC powerpath多路径软件安装 ↩︎

  6. csdn: Linux下多路径multipath ↩︎

  7. oschina: multipath配置指南 ↩︎