找到SM Master节点所在的机器的方法

通过sminfo确认master的guid,然后使用ibstat在每台局域网中的机器上执行,找到对应的Port

sminfo 

sminfo: sm lid 62 sm guid <strong>0x98039b0300e24101</strong>, activity count 1932118 priority 14 state 3 SMINFO_MASTER

ibstat

CA 'mlx4_0'
        CA type: MT4099
        Number of ports: 2
        Firmware version: 2.36.5150
        Hardware version: 1
        Node GUID: 0x0002c903001996a0
        System image GUID: 0x0002c903001996a3
        Port 1:
                State: Active
                Physical state: LinkUp
                Rate: 40
                Base lid: 67
                LMC: 0
                SM lid: 62
                Capability mask: 0x0251486a
                Port GUID: 0x0002c903001996a1
                Link layer: InfiniBand
        Port 2:
                State: Active
                Physical state: LinkUp
                Rate: 40
                Base lid: 64
                LMC: 0
                SM lid: 62
                Capability mask: 0x02514868
                Port GUID: 0x0002c903001996a2
                Link layer: InfiniBand
CA 'mlx4_1'
        CA type: MT4099
        Number of ports: 2
        Firmware version: 2.42.5000
        Hardware version: 1
        Node GUID: 0x0002c90300449310
        System image GUID: 0x0002c90300449313
        Port 1:
                State: Active
                Physical state: LinkUp
                Rate: 40
                Base lid: 5
                LMC: 0
                SM lid: 62
                Capability mask: 0x02514868
                Port GUID: 0x0002c90300449311
                Link layer: InfiniBand
        Port 2:
                State: Active
                Physical state: LinkUp
                Rate: 40
                Base lid: 9
                LMC: 0
                SM lid: 62
                Capability mask: 0x02514868
                Port GUID: 0x0002c90300449312
                Link layer: InfiniBand

Centos环境中更新grub 选项的正确方法

新公司的工作是开发管理VM的插件,类似于实现nova中的libvirtdriver

在处理SR-IOV设备时需要打开宿主机的iommu
网上的方法就是修改grub

grub在centos中有两个位置
/etc/default/grub
/boot/grub2/grub.cfg
以前我都是简单粗暴的个性/boot/grub2/grub.cfg 现在发现并不合理

正确的方法是
修改/etc/default/grub
然后执行:

dracut --regenerate-all --force
grub2-mkconfig -o /boot/grub2/grub.cfg
reboot

编写命令行程序增加自动补全功能

最近正在编写一套完整的存储系统,涉及到命令行程序,需要增加自动补全功能以提高用户体验
这里用到了bash-completion工具可以直接yum装一下。

在/etc/bash_completion.d/ 目录下添加任意文件名文件,如flystor
比如你有如下命令树:

set 
   net 
      ip
      dns
      gw
   option
      hostname
      date

即当打完set用双击tab 应该可以显示二层net option两个子命令,如输入为set net 双击tab则应该出现 ip dns gw的提示,并且所有命令都带有自动补全功能

对应flystor文件中的内容为:

function _sms()
{
        local cur prev

        COMPREPLY=()
        cur="${COMP_WORDS[COMP_CWORD]}"
        prev="${COMP_WORDS[COMP_CWORD-1]}"

        case "${prev}" in
           set)
                COMPREPLY=( $(compgen -W "net option" ${cur}) )
                return 0
                ;;
           net)
                COMPREPLY=( $(compgen -W "ip dns gw" ${cur}) )
                return 0
                ;;
           option)
                COMPREPLY=( $(compgen -W "hostname date" ${cur}) )
                return 0
                ;;
        esac
}

代码初潜易懂,但这样写就很实用了。

完成后需要退出当前用户重新登录即可生效。

使用awk命令,并设定分割符为2个或以上的空格

因为要parse smbstatus的输出

117873  nobody       nobody       myhomepc (ipv4:192.168.199.2:62084)  SMB3_02

因为myhompc (ipv4:192.168.199.2:62084) 归属于同一项machine, 如果简单用awk会将其分割为两列

如果-F 直接指定为’  ‘则会产生多个多余的列,因为前面nobody之间,有多个空格

因此我们的分割条件就变为了两个或以上的空格

本以为只能通过脚本来实现,结果一查发现awk竟然直接支持

awk -F '[[:space:]][[:space:]][[:space:]]*'

 

非交互式创建自签名证书

生成根证书的私钥,des3是加密算法,用其签发服务器端证书或者客户端证书,主要在于使用-passout pass:yourpassword 和-passinpass:yourpassword来指定密码

openssl genrsa -passout pass:4444 -des3 -out server.key 1024

生成服务器端签名请求证书(csr证书)
其中C是Country,ST是state,L是local,O是Organization,OU是Organization Unit,CN是common name

openssl req -new -passin pass:4444 -key server.key -out server.csr -subj /C=CN/ST=Shanghai/L=Shanghai/O=wyq/OU=wyq/CN=wyq.me/emailAddress=i@wyq.me

生成自签名证书,有效期设置为10年

cp server.key server.key.orig
openssl rsa -in server.key.orig -out server.key -passin pass:4444
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt

测试UDEV

使用udevadm test可以进行udev的测试
但其只接受udevadm info -q path -n /dev/sdb1 的输出作为参数

[root@node1 ~]# udevadm info -q path -n /dev/sdb1
/devices/pci0000:00/0000:00:10.0/host0/target0:0:1/0:0:1:0/block/sdb/sdb1
[root@node1 ~]# udevadm test --action=add /devices/pci0000:00/0000:00:10.0/host0/target0:0:1/0:0:1:0/block/sdb/sdb1
calling: test
version 219
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

=== trie on-disk ===
tool version:          219
file size:         7259752 bytes
header size             80 bytes
strings            1887992 bytes
nodes              5371680 bytes
Load module index
Created link configuration context.
timestamp of '/etc/udev/rules.d' changed
Reading rules file: /usr/lib/udev/rules.d/10-dm.rules
Reading rules file: /usr/lib/udev/rules.d/11-dm-lvm.rules
Reading rules file: /usr/lib/udev/rules.d/13-dm-disk.rules
Reading rules file: /usr/lib/udev/rules.d/40-redhat.rules
Reading rules file: /usr/lib/udev/rules.d/42-usb-hid-pm.rules
Reading rules file: /usr/lib/udev/rules.d/50-rbd.rules
Reading rules file: /etc/udev/rules.d/50-sms.rules
Reading rules file: /usr/lib/udev/rules.d/50-udev-default.rules
Reading rules file: /usr/lib/udev/rules.d/60-alias-kmsg.rules
Reading rules file: /usr/lib/udev/rules.d/60-cdrom_id.rules
Reading rules file: /usr/lib/udev/rules.d/60-ceph-by-parttypeuuid.rules
Reading rules file: /usr/lib/udev/rules.d/60-drm.rules
Reading rules file: /usr/lib/udev/rules.d/60-keyboard.rules
Reading rules file: /usr/lib/udev/rules.d/60-net.rules
Reading rules file: /usr/lib/udev/rules.d/60-persistent-alsa.rules
Reading rules file: /usr/lib/udev/rules.d/60-persistent-input.rules
Reading rules file: /usr/lib/udev/rules.d/60-persistent-serial.rules
Reading rules file: /usr/lib/udev/rules.d/60-persistent-storage-tape.rules
Reading rules file: /usr/lib/udev/rules.d/60-persistent-storage.rules
Reading rules file: /usr/lib/udev/rules.d/60-persistent-v4l.rules
Reading rules file: /usr/lib/udev/rules.d/60-raw.rules
Reading rules file: /etc/udev/rules.d/60-sms.rules
Reading rules file: /usr/lib/udev/rules.d/61-accelerometer.rules
Reading rules file: /usr/lib/udev/rules.d/63-md-raid-arrays.rules
Reading rules file: /usr/lib/udev/rules.d/64-btrfs.rules
Reading rules file: /usr/lib/udev/rules.d/65-md-incremental.rules
Reading rules file: /usr/lib/udev/rules.d/69-dm-lvm-metad.rules
Reading rules file: /usr/lib/udev/rules.d/70-mouse.rules
Reading rules file: /etc/udev/rules.d/70-persistent-ipoib.rules
Reading rules file: /usr/lib/udev/rules.d/70-power-switch.rules
Reading rules file: /usr/lib/udev/rules.d/70-touchpad.rules
Reading rules file: /usr/lib/udev/rules.d/70-uaccess.rules
Reading rules file: /usr/lib/udev/rules.d/71-biosdevname.rules
Reading rules file: /usr/lib/udev/rules.d/71-seat.rules
Reading rules file: /usr/lib/udev/rules.d/73-idrac.rules
Reading rules file: /usr/lib/udev/rules.d/73-seat-late.rules
Reading rules file: /usr/lib/udev/rules.d/75-net-description.rules
Reading rules file: /usr/lib/udev/rules.d/75-probe_mtd.rules
Reading rules file: /usr/lib/udev/rules.d/75-tty-description.rules
Reading rules file: /usr/lib/udev/rules.d/78-sound-card.rules
Reading rules file: /usr/lib/udev/rules.d/80-drivers.rules
Reading rules file: /usr/lib/udev/rules.d/80-net-name-slot.rules
Reading rules file: /usr/lib/udev/rules.d/80-net-setup-link.rules
Reading rules file: /usr/lib/udev/rules.d/81-kvm-rhel.rules
Reading rules file: /usr/lib/udev/rules.d/84-nm-drivers.rules
Reading rules file: /usr/lib/udev/rules.d/85-nm-unmanaged.rules
Reading rules file: /usr/lib/udev/rules.d/90-alsa-tools-firmware.rules
Reading rules file: /usr/lib/udev/rules.d/90-iprutils.rules
Reading rules file: /usr/lib/udev/rules.d/90-vconsole.rules
Reading rules file: /usr/lib/udev/rules.d/91-drm-modeset.rules
Reading rules file: /usr/lib/udev/rules.d/95-ceph-osd.rules
Reading rules file: /usr/lib/udev/rules.d/95-dm-notify.rules
Reading rules file: /usr/lib/udev/rules.d/95-udev-late.rules
Reading rules file: /usr/lib/udev/rules.d/98-kexec.rules
Reading rules file: /usr/lib/udev/rules.d/98-rdma.rules
Reading rules file: /usr/lib/udev/rules.d/99-systemd.rules
rules contain 49152 bytes tokens (4096 * 12 bytes), 15467 bytes strings
2466 strings (32321 bytes), 1723 de-duplicated (17598 bytes), 744 trie nodes used
GROUP 6 /usr/lib/udev/rules.d/50-udev-default.rules:52
IMPORT '/sbin/blkid -o udev -p /dev/sdb1' /usr/lib/udev/rules.d/60-ceph-by-parttypeuuid.rules:26
starting '/sbin/blkid -o udev -p /dev/sdb1'
'/sbin/blkid -o udev -p /dev/sdb1'(out) 'ID_PART_ENTRY_SCHEME=gpt'
'/sbin/blkid -o udev -p /dev/sdb1'(out) 'ID_PART_ENTRY_NAME=X0Hu3Mr1'
'/sbin/blkid -o udev -p /dev/sdb1'(out) 'ID_PART_ENTRY_UUID=a04af164-70cb-42b9-924b-6038ccec87ac'
'/sbin/blkid -o udev -p /dev/sdb1'(out) 'ID_PART_ENTRY_TYPE=ebd0a0a2-b9e5-4433-87c0-68b6b72699c7'
'/sbin/blkid -o udev -p /dev/sdb1'(out) 'ID_PART_ENTRY_NUMBER=1'
'/sbin/blkid -o udev -p /dev/sdb1'(out) 'ID_PART_ENTRY_OFFSET=32768'
'/sbin/blkid -o udev -p /dev/sdb1'(out) 'ID_PART_ENTRY_SIZE=4096000'
'/sbin/blkid -o udev -p /dev/sdb1'(out) 'ID_PART_ENTRY_DISK=8:16'
'/sbin/blkid -o udev -p /dev/sdb1' [3610] exit with return code 0
LINK 'disk/by-parttypeuuid/ebd0a0a2-b9e5-4433-87c0-68b6b72699c7.a04af164-70cb-42b9-924b-6038ccec87ac' /usr/lib/udev/rules.d/60-ceph-by-parttypeuuid.rules:29
LINK 'disk/by-path/pci-0000:00:10.0-scsi-0:0:1:0-part1' /usr/lib/udev/rules.d/60-persistent-storage.rules:68
IMPORT builtin 'blkid' /usr/lib/udev/rules.d/60-persistent-storage.rules:82
probe /dev/sdb1 raid offset=0
LINK 'disk/by-partuuid/a04af164-70cb-42b9-924b-6038ccec87ac' /usr/lib/udev/rules.d/60-persistent-storage.rules:96
LINK 'disk/by-partlabel/X0Hu3Mr1' /usr/lib/udev/rules.d/60-persistent-storage.rules:97
RUN '/tmp/tt %k' /etc/udev/rules.d/60-sms.rules:1
handling device node '/dev/sdb1', devnum=b8:17, mode=0660, uid=0, gid=6
preserve permissions /dev/sdb1, 060660, uid=0, gid=6
preserve already existing symlink '/dev/block/8:17' to '../sdb1'
found 'b8:17' claiming '/run/udev/links/\x2fdisk\x2fby-partlabel\x2fX0Hu3Mr1'
creating link '/dev/disk/by-partlabel/X0Hu3Mr1' to '/dev/sdb1'
preserve already existing symlink '/dev/disk/by-partlabel/X0Hu3Mr1' to '../../sdb1'
found 'b8:17' claiming '/run/udev/links/\x2fdisk\x2fby-parttypeuuid\x2febd0a0a2-b9e5-4433-87c0-68b6b72699c7.a04af164-70cb-42b9-924b-6038ccec87ac'
creating link '/dev/disk/by-parttypeuuid/ebd0a0a2-b9e5-4433-87c0-68b6b72699c7.a04af164-70cb-42b9-924b-6038ccec87ac' to '/dev/sdb1'
preserve already existing symlink '/dev/disk/by-parttypeuuid/ebd0a0a2-b9e5-4433-87c0-68b6b72699c7.a04af164-70cb-42b9-924b-6038ccec87ac' to '../../sdb1'
found 'b8:17' claiming '/run/udev/links/\x2fdisk\x2fby-partuuid\x2fa04af164-70cb-42b9-924b-6038ccec87ac'
creating link '/dev/disk/by-partuuid/a04af164-70cb-42b9-924b-6038ccec87ac' to '/dev/sdb1'
preserve already existing symlink '/dev/disk/by-partuuid/a04af164-70cb-42b9-924b-6038ccec87ac' to '../../sdb1'
found 'b8:17' claiming '/run/udev/links/\x2fdisk\x2fby-path\x2fpci-0000:00:10.0-scsi-0:0:1:0-part1'
creating link '/dev/disk/by-path/pci-0000:00:10.0-scsi-0:0:1:0-part1' to '/dev/sdb1'
preserve already existing symlink '/dev/disk/by-path/pci-0000:00:10.0-scsi-0:0:1:0-part1' to '../../sdb1'
created db file '/run/udev/data/b8:17' for '/devices/pci0000:00/0000:00:10.0/host0/target0:0:1/0:0:1:0/block/sdb/sdb1'
.ID_FS_TYPE_NEW=
ACTION=add
DEVLINKS=/dev/disk/by-partlabel/X0Hu3Mr1 /dev/disk/by-parttypeuuid/ebd0a0a2-b9e5-4433-87c0-68b6b72699c7.a04af164-70cb-42b9-924b-6038ccec87ac /dev/disk/by-partuuid/a04af164-70cb-42b9-924b-6038ccec87ac /dev/disk/by-path/pci-0000:00:10.0-scsi-0:0:1:0-part1
DEVNAME=/dev/sdb1
DEVPATH=/devices/pci0000:00/0000:00:10.0/host0/target0:0:1/0:0:1:0/block/sdb/sdb1
DEVTYPE=partition
ID_BUS=scsi
ID_FS_TYPE=
ID_MODEL=VMware_Virtual_S
ID_MODEL_ENC=VMware\x20Virtual\x20S
ID_PART_ENTRY_DISK=8:16
ID_PART_ENTRY_NAME=X0Hu3Mr1
ID_PART_ENTRY_NUMBER=1
ID_PART_ENTRY_OFFSET=32768
ID_PART_ENTRY_SCHEME=gpt
ID_PART_ENTRY_SIZE=4096000
ID_PART_ENTRY_TYPE=ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
ID_PART_ENTRY_UUID=a04af164-70cb-42b9-924b-6038ccec87ac
ID_PART_TABLE_TYPE=gpt
ID_PATH=pci-0000:00:10.0-scsi-0:0:1:0
ID_PATH_TAG=pci-0000_00_10_0-scsi-0_0_1_0
ID_REVISION=1.0
ID_SCSI=1
ID_TYPE=disk
ID_VENDOR=VMware_
ID_VENDOR_ENC=VMware\x2c\x20
MAJOR=8
MINOR=17
SUBSYSTEM=block
TAGS=:systemd:
USEC_INITIALIZED=244571
run: '/tmp/tt sdb1'
Unload module index
Unloaded link configuration context.


对gluster进行dd操作,参数带oflag=direct时对于某些文件的性能特别差

测试时对gluster的volume进行dd(带oflag=direct),有时会出现某些文件名的文件性能特别差。
gluster的弹性hash算法,决定了在使用非EC类型的卷时,文件是会随机落到某些盘上,不同文件名的文件所对应的subvolume不同,即所落的盘不一样。这就对磁盘的性能有一定的要求,当出现此现象时,一般可以总结为有坏盘,慢盘,或磁盘的write cache未打开。

通过dmesg |grep sdb来检测盘是否有打开wirte cache
如没有,可通过hdparm或sdparm来进行enable处理

如何制作自动自定义的安装程序包

需求很简单,有很多rpm要安装,但客户是傻瓜式的,要求只提供一个安装包。
于是提炼出来就是rpm包统一压缩在zip中,shell脚本来负责安装。但这样会有两个文件,不符合客户要求
大牛JS给出好方法:

1. 准备压缩包

比如命名为up.zip
放在当前目录下

2. 创建install.sh

#!/bin/sh
mkdir tmp
sed -n -e '1,/^exit 0$/!p' $0 > tmp/up.zip 2>/dev/null

压缩和执行的步骤

exit 0

注意:exit 0之后绝对不能有任何的字符,不然会出现各种问题

3. 生成bin文件

cat install.sh up.zip > exup.bin
chmod +x excu.bin

程序可以取任意名字,压缩方式也可以是tar gz之类的,只要shell中的解压和安装方式正确就可以了。
同样的原理可以做很多事情~就看你的想象力了

Linux下tree命令详解

tree命令的记录
中文解释:tree
功能说明:以树状图列出目录的内容。
语  法:tree [-aACdDfFgilnNpqstux][-I <范本样式>][-P <范本样式>][目录…]
补充说明:执行tree指令,它会列出指定目录下的所有文件,包括子目录里的文件。
参  数:
-a 显示所有文件和目录。
-A 使用ASNI绘图字符显示树状图而非以ASCII字符组合。
-C 在文件和目录清单加上色彩,便于区分各种类型。
-d 显示目录名称而非内容。
-D 列出文件或目录的更改时间。
-f 在每个文件或目录之前,显示完整的相对路径名称。
-F 在执行文件,目录,Socket,符号连接,管道名称名称,各自加上”*”,”/”,”=”,”@”,”|”号。
-g 列出文件或目录的所属群组名称,没有对应的名称时,则显示群组识别码。
-i 不以阶梯状列出文件或目录名称。
-I<范本样式> 不显示符合范本样式的文件或目录名称。
-l 如遇到性质为符号连接的目录,直接列出该连接所指向的原始目录。
-n 不在文件和目录清单加上色彩。
-N 直接列出文件和目录名称,包括控制字符。
-p 列出权限标示。
-P<范本样式> 只显示符合范本样式的文件或目录名称。
-q 用”?”号取代控制字符,列出文件和目录名称。
-s 列出文件或目录大小。
-t 用文件和目录的更改时间排序。
-u 列出文件或目录的拥有者名称,没有对应的名称时,则显示用户识别码。
-x 将范围局限在现行的文件系统中,若指定目录下的某些子目录,其存放于另一个文件系统上,则将该子目录予以排除在寻找范围外。