分类 Linux 下的文章

基于mysubmail接口发送短信、电话语音通知。创建脚本后可以通过crontab -e每小时或半小时运行一次,例如:
/30 * python /etc/weed/checkRAID.py
可以在raid出现异常状态时快速获知及时处理,避免故障扩大。

# -*- coding: utf-8 -*-
#!/usr/bin/python
import os
import requests

node = '香港vps-nvmenode-1'
error = 0

def get_status(value):
    try:
        status = value.split(": ")
        return status[1].strip()
    except:
        return False
    

def send_warning():
    global node

    # 语音通知
    voice_url = 'http://api.mysubmail.com/voice/send.json'
    voice_params = { 'appid': '*****',
                      'to': '13200000000',
                      'content': '紧急事态:'+node+'硬盘状态异常,请立即检查',
                      'signature': '**************'
                   }
    #voice_res = requests.post(voice_url, data=voice_params)
    # print voice_res.text

    # 短信通知
    message_url = 'http://api.mysubmail.com/message/send.json'
    message_params = { 'appid': '*****',
                       'to': '13200000000',
                       'content': '【XXX】紧急事态:'+node+'硬盘状态异常,请立即检查',
                       'signature': '**************'
                     }
    message_res = requests.post(message_url, data=message_params)
    # print(message_res.text)


# 检查RAID状态,注意/dev/md10是变动参数,自行fdisk -l查看你的软列阵磁盘名称,如raid1则为/dev/md1
raidinfos = os.popen('mdadm -D /dev/md10').readlines()
for raidinfo in raidinfos:
    raidinfo = raidinfo.strip('\n')
    print(raidinfo)

    if "State : " in raidinfo:
        status = get_status(raidinfo)
        if status != 'active' and status != 'active, checking':
            error = 1

    if "Failed Devices : " in raidinfo:
        status = get_status(raidinfo)
        if status != '0':
            error = 1

    if "Active Devices : " in raidinfo:
        status = get_status(raidinfo)
        if status != '2':
            error = 1

# 发送通知
if error == 1:
    send_warning()

如果RAID0用作CEPH OSD,则建议禁用磁盘级的缓存,也就是磁盘标签上写的那个256MB缓存:

# /opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp -DisDskCache -Immediate -Lall -aAll
                                     
Set Disk Cache Policy to Disabled on Adapter 0, VD 0 (target id: 0) success
Set Disk Cache Policy to Disabled on Adapter 0, VD 1 (target id: 1) success
Set Disk Cache Policy to Disabled on Adapter 0, VD 2 (target id: 2) success
Set Disk Cache Policy to Disabled on Adapter 0, VD 4 (target id: 4) success
Set Disk Cache Policy to Disabled on Adapter 0, VD 5 (target id: 5) success
Set Disk Cache Policy to Disabled on Adapter 0, VD 7 (target id: 7) success
Set Disk Cache Policy to Disabled on Adapter 0, VD 8 (target id: 8) success

- 阅读剩余部分 -

我的CEPH OSD因为列阵卡不支持直通是基于RAID0的,最近ceph性能不足,排查过程iostat观察发现有一些盘r_await或w_await持续1000多,这就需要换盘了。ceph存储一份数据如果是默认3副本,那么就会3份副本写完才会完成写入,如果有1个osd延迟很高,就会影响整体写入速度。

首先可以运行 ceph-volume lvm list 查看osd对应的盘符,如果是bcache,则需要再运行lsblk查看在哪个盘符下。然后查看是哪个盘符,以及盘位,进行更换重建。

- 阅读剩余部分 -

今天接客户反映有台服务器下行速度有问题,一看交换机端口下行跑满了,但是在系统里iftop端口流量很低、很正常。

随后检查上联华为交换机,发现所有端口都有不同程度的错包情况、每个端口下行都跑的很高,部分没有客户的、都没开机的只是端口开着下行都在跑。

检查arp没有问题,猜测可能交换机问题,毕竟有两三年没重启了,虽然不知道原因,但保存临时配置重启了下交换机就恢复了。

其他可能的原因排查:https://support.huawei.com/enterprise/zh/knowledge/EKB1000601298

tcpdump是Linux下的截获分析网络数据包的工具,对优化系统性能有很大参考价值。

安装

tcpdump不是默认安装的,在CentOS下安装:

yum install tcpdump

在Ubuntu下安装:

apt-get install tcpdump

默认启动

tcpdump

普通情况下,直接启动tcpdump将监视第一个网络接口上所有流过的数据包。

- 阅读剩余部分 -

安装

1 加载系统的bcache模块:

lsmod | grep bcache
modprobe bcache

2 如果出现错误:

modprobe: FATAL: Module bcache not found.

则需要升级内核:https://www.cnweed.com/archives/4311/
因为bcache在kernel 3.10版本才进入主线,所以我们要保证CentOS的内核版本大于3.10

3 编译安装

yum install -y git gcc-c++ pkgconfig libblkid-devel
git clone https://evilpiepirate.org/git/bcache-tools.git
cd bcache-tools/
make
make install

- 阅读剩余部分 -