zabbix_support_for_mdadm

개요

최근 curry의 디스크 하나가 고장나 디스크를 교체했다.

하지만 디스크 고장을 우연히 발견하였고, 조치하였지만 이에대한 방지대책이 필요하다.

생각

mdraid에 대한 모니터링이 필요하다고 생각한다.

방법은 두가지로 나누어 보았다.

  1. zabbix 템플릿 추가하기.
  2. mdadm 에 내장된 Email-alert 기능 사용하기.

1번으로 진행하기로 하였다.

이유는 우리는 zabbix 모니터링 서버와 zabbix 에이전트가 이미 모니터링 중이니 일관성 있게 zabbix가 모니터링 하는게 낫다고 생각하였다.

2번으로 진행하게 된다면 추가로 25번 포트를 열어야 하며 MUA(Mail User Agent), MTA(Mail Trasport Agent)가 필요하기 때문에 추가적인 패키지 설치가 필요하기 때문에 1번으로 진행하는게 낫다고 생각하였다.

zabbix용 mdraid 모니터링 템플릿 지원, 설정 방법은 아래 링크를 참조한다. * https://share.zabbix.com/cat-server-hardware/template-md-raid * https://github.com/krom/zabbix_template_md

적용대상

  1. griffin : debian7.5 + mdadm 3.2.5-5
  2. thomas : debian8.2 + mdadm 3.3.2-5
  3. curry : debian8.2 + mdadm 3.3.2-5

총 3대에 적용할 것이다.

시험서버 준비

프로덕션에 적용하기 전 시험서버에서 충분히 검증 후 적용하는 것은 기본이다.

Zabbix Client

  • hostname : mdadm
  • IP : 192.168.0.233
  • debian 버전 : 8.11(Jessie)
  • mdadm 버전 : 3.3.2-5
  • Raid Disk : xvdb1(10G) + xvdc1(10G) = md0(mdraid 1)

현재 mdraid 상태.:

root@mdadm:~# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 xvdc1[1] xvdb1[0]
      10476544 blocks super 1.2 [2/2] [UU]

unused devices: <none>

zabbix agent를 설치한다.:

root@mdadm:~# apt install zabbix-agent

zabbix 서버가 모니터링 할수 있도록 설정을 변경한다.:

root@mdadm:~# vi /etc/zabbix/zabbix_agentd.conf
- Server=127.0.0.1
+ Server=192.168.0.246

root@mdadm:~# /etc/init.d/zabbix-agent restart
[ ok ] Restarting zabbix-agent (via systemctl): zabbix-agent.service.

Zabbix Server

  • hostname : zabbix
  • IP : 192.168.0.246
  • debian 버전 : 8.11(Jessie)
  • mdadm 버전 : 3.2-1

관리자 웹 페이지에 접속하여 아래와 같이 호스트를 추가한다.

  • (상단메뉴)Configuration 클릭
  • Host 클릭
  • Create host 클릭
  • Host name : mdadm 입력
  • Agent interfaces : (IP address) 192.168.0.233 입력
  • Templates 탭 클릭
  • Select -> Template OS Linux 선택 -> Add 클릭
  • Host 탭 클릭 -> Add

시험서버 준비 완료!

Zabbix용 mdraid 모니터링 템플릿 추가 및 설정

zabbix용 mdraid 템플릿에서 지원하는 모니터링 기능은 아래와 같다.

  • md.discover - LLD(Low Level Discovery) 데이터 (MD RAID 및 디스크) 감지
  • md.degraded [*] - 특정 RAID에 대한 성능이 저하 된 디스크 수
  • md.sync_action [*] - 특정 RAID의 현재 동기화 상태
  • md.raid_disks [*] - 특정 RAID에 대한 모든 디스크 수

Zabbix Client 설정

root@mdadm:~# curl -Ls https://git.io/fN9H5 | sudo tee /etc/zabbix/zabbix_agentd.conf.d/userparameter_md.conf UserParameter=md.discover,ls /sys/class/block | awk ‘BEGIN{printf “{“data”:[“}; /^md[0-9]+$/ {printf c”{“{#MDNAME}”:”“$1”“}”;c=”,”}; END{print “]}”}’ UserParameter=md.degraded[*],cat /sys/block/$1/md/degraded UserParameter=md.sync_action[*],cat /sys/block/$1/md/sync_action UserParameter=md.raid_disks[*],cat /sys/block/$1/md/raid_disks

root@mdadm:~# /etc/init.d/zabbix-agent restart [ ok ] Restarting zabbix-agent (via systemctl): zabbix-agent.service.

Zabbix Server 설정

템플릿 파일을 내 로컬PC에 저장하기 위해 git clone하였다.:

gwangseok@gwangbian:~$ git clone https://github.com/krom/zabbix_template_md.git

프로젝트 디렉토리를 살펴보자.:

gwangseok@gwangbian:~$ ls -l zabbix_template_md/
합계 92
-rw-r--r-- 1 gwangseok gwangseok 35141  1월 16 13:09 LICENSE
-rw-r--r-- 1 gwangseok gwangseok   990  1월 16 13:09 Makefile
-rw-r--r-- 1 gwangseok gwangseok  1993  1월 16 13:09 README.md
drwxr-xr-x 2 gwangseok gwangseok   108  1월 16 13:09 dist
-rw-r--r-- 1 gwangseok gwangseok 12108  1월 16 13:09 template_md_2.0.xml
-rw-r--r-- 1 gwangseok gwangseok 12595  1월 16 13:09 template_md_2.4.xml
-rw-r--r-- 1 gwangseok gwangseok 12783  1월 16 13:09 template_md_3.0.xml
-rw-r--r-- 1 gwangseok gwangseok   343  1월 16 13:09 userparameter_md.conf
  • 우리 zabbix는 3.2버전 이므로 내가 필요한 파일은 template_md_3.0.xml 이다.

이제 zabbix 관리자 웹페이지로 접속한다. * 상단메뉴의 Configuration -> Templates 를 클릭한다. * 상단 우측 메뉴의 Import를 클릭한다. * 파일선택 -> 홈-> zabbix_template_md -> template_md_3.0.xml을 선택한다. * Import를 클릭한다. 이렇게 하면 MD-RAID 모니터링을 위한 템플릿이 추가된 것이다.

이제 MD-RAID 템플릿을 특정 호스트(나의경우 mdadm)에게 적용해보자. * 상단메뉴의 Configuration -> Host 클릭 * mdadm 클릭 -> Templates 로 이동 * Select -> Template MD Soft RAID 클릭 -> Add -> Update

이렇게 하면 zabbix서버가 mdadm호스트의 MD_RAID장치 모니터링을 시작한다.

검증

mdadm의 레이드 디스크 중 하나를 detact 하여 zabbix가 이를 감지하는지 확인한다.

(in jennings).:

root@jennings:~# xl block-detach 29 xvdc
libxl: error: libxl_device.c:952:device_backend_callback: unable to remove device with path /local/domain/0/backend/qdisk/29/51744
libxl: error: libxl.c:1995:device_addrm_aocomplete: unable to remove vbd with id 51744
libxl_device_disk_remove failed.
  • block detach에 실패하였다.

xenstore 장치를 확인하였다.:

root@jennings:~# xenstore-ls /local/domain/29/device/vbd
51712 = ""
 backend = "/local/domain/0/backend/qdisk/29/51712"
 backend-id = "0"
 state = "4"
 virtual-device = "51712"
 device-type = "disk"
 ring-ref = "9"
 event-channel = "18"
 protocol = "x86_64-abi"
 feature-persistent = "1"
51728 = ""
 backend = "/local/domain/0/backend/qdisk/29/51728"
 backend-id = "0"
 state = "4"
 virtual-device = "51728"
 device-type = "disk"
 ring-ref = "364"
 event-channel = "21"
 protocol = "x86_64-abi"
 feature-persistent = "1"
  • xvdc가 detach되었다.

xl list –long으로 확인하였다.:

root@jennings:~# xl list -l 29 |less
...
"disks": [
{
    "pdev_path": "/localdisk/96c9d35a-9db9-4899-9594-76dfde0c42bf",
    "vdev": "xvda",
    "format": "qcow2",
    "readwrite": 1
},
{
    "pdev_path": "/localdisk/d964b17b-87f1-4f7b-8750-326c819cc66e",
    "vdev": "xvdb",
    "format": "qcow2",
    "readwrite": 1
  • xvdc가 detach되었다. 그럼 왜 xl은 실패 로그를 띄웠을까..

(in mdadm) VM에서 확인하였다.:

root@mdadm:~# fdisk -l

Disk /dev/xvda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc3617af3

Device     Boot   Start      End  Sectors  Size Id Type
/dev/xvda1         2048  1953791  1951744  953M 82 Linux swap / Solaris
/dev/xvda2 *    1953792 21485567 19531776  9.3G 83 Linux

Disk /dev/xvdb: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x820dbc44

Device     Boot Start      End  Sectors Size Id Type
/dev/xvdb1       2048 20971519 20969472  10G fd Linux raid autodetect

Disk /dev/md0: 10 GiB, 10727981056 bytes, 20953088 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

root@mdadm:~# dmesg |tail -n 3
[72695.244176] vbd vbd-51744: 16 Device in use; refusing to close
[72695.245583] vbd vbd-51744: failed to write error node for device/vbd/51744 (16 Device in use; refusing to close)
[72705.258492] block xvdc: device/vbd/51744 was hot-unplugged, 1 stale handles
  • VM에서도 xvdc가 detach되었다.

RAID 상태를 보았다.:

root@mdadm:~# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 xvdc1[1] xvdb1[0]
      10476544 blocks super 1.2 [2/2] [UU]

unused devices: <none>
  • mdstat에는 여전히 xvdc가 존재하는 것으로 본다.
  • block-detach가 문제가 있는 것 같다.
  • xen을 통하지 않고 미러 디스크 중 하나의 디스크만 장착한 상태로 부팅하자.

미러 디스크 2개중 하나의 디스크만 장착한 상태로 부팅하였다.:

root@mdadm:~# cat /proc/mdstat
Personalities : [raid1]
md0 : active (auto-read-only) raid1 xvdb1[0]
      10476544 blocks super 1.2 [2/1] [U_]

unused devices: <none>

Zbbix서버에서 확인 결과 Issue에 같이 잘 감지한다.:

mdadm-test  MD md0 is degraded on mdadm-test    2019-01-16 23:13:51 1m 21s      No
  • 모니터링이 잘 된다.

프로덕션 적용

시험서버에서 검증이 되었으니 프로덕션에 적용한다.

  • Zabbix Server : MD-RAID 모니터링용 템플릿 추가 완료.
  • griffin, curry, thomas : zabbix-agent 설정 완료.
  • griffin, curry, thomas : MD-RAID 템플릿 추가 완료.

이제 우리 서버를 더 꼼꼼하게 모니터링 할 수 있게 되었다.