티스토리 뷰

Linux

MON tools 설치

CHOMAN 2015. 6. 4. 13:53

mon 깔기


prel 모듈이 필요하다라고 함

 

cd /usr/include
h2ph -r -l .



 

아래왜 같이 존나게 올라가면서 실행되면 정상

 


 

 


필요한 perl 모듈 설치

 

Time::Period PRYAN/Period-1.20.tar.gz
Time::HiRes J/JH/JHI/Time-HiRes-1.59.tar.gz

wget 
http://search.cpan.org/CPAN/authors/id/P/PR/PRYAN/Period-1.20.tar.gz
wget http://search.cpan.org/CPAN/authors/id/J/JH/JHI/Time-HiRes-1.9719.tar.gz

perl Makefile.PL
make; make install;

 

 

mon 다운받기

wget wget ftp://ftp.kernel.org/pub/software/admin/mon/mon-1.2.0.tar.gz

yum install mon 으로 해도 다운은 된다. (하지만 소스설치로 해본다) Cent os 5.4 는 안되네 헐

그냥 압출풀고 
cd mon.d/
make; make install


mon 디렉토리 구조

 

mon ---- alert.d : 각종 alert 데몬이 들어있는 디렉토리
clients : mon 클라이언트 데몬이 있는 디렉토리
doc : 메뉴얼이 들어있는 디렉토리
etc : 설정화일이 들어있는 디렉토리
mon.d : 모니터링 프로그램이 들어있는 디렉토리
muxpect : 멀티플렉스 TCP라는 기능을 위해 개발되어지고 있는 프로그램
state.d : pid 가 들어갈 자리
utils : mon 용 유틸리티가 들어있는 자리

 

 

폴더하나 생성후 기본적으로 필요한 설정파일들 복사

 

mkdir /etc/mon 
cp etc/example.cf /etc/mon/mon.cf 
cp etc/auth.cf /etc/mon/auth.cf

 

 

/etc/service 에 해당 포트 등록 ( 머 대부분 등록이 되어 있는듯 한데...)

 

mon 2583/tcp #MON
mon 2583/udp #MON traps

 

 

/etc/mon/mon.cf (몇번 해보면 쉽다 근데 httpd는 잘 되는 mysql이 안되어서 개 삽질중임)

 

### Extremely basic mon.cf file
### global options
cfbasedir = /etc/mon
alertdir = /usr/local/src/mon-1.2.0/alert.d
mondir = /usr/local/src/mon-1.2.0/mon.d
maxprocs = 20
histlength = 100
randstart = 30s
authtype = getpwnam
### group definitions (hostnames or IP addresses)
hostgroup servers XXX.XXX.250.98 (자기 자신 체크할려면 127.0.0.1) 넣어준다
hostgroup localhost 127.0.0.1
hostgroup samba1 127.0.0.1
watch localhost
service mysql
interval 5s
monitor msql-mysql.monitor --mode=mysql --username=root --password=100dedi@ --database=mysql
period wd {Sun-Sat}
alert down.echo.alert "service down"
upalert up.echo.alert "service alive"
service http
interval 5s
monitor http.monitor
period wd {Sun-Sat}
alert echo.alert "service down"
upalert echo.alert "service alive"
watch samba1
service samba
interval 5s
monitor samba.monitor -u 삼바계정 -p 패스워드
period wd {Sun-Sat}
alert echo.alert "service down"
upalert echo.alert "service alive"
watch dns1
service dns
interval 5s
monitor dns.monitor -caching_only -query kensei.pe.kr:A
period wd {Sun-Sat}
alert down.echo.alert "service down"
upalert up.echo.alert "service alive"
### See /usr/share/doc for the original example...

 

 

간단하게 로그 찍을 스크립트 작성 뭐 보니깐 로그 찍는 스크립트는 제공안하는듯 함

 

cd /usr/local/src/mon-1.2.0/alert.d
cat echo.alert
#!/bin/sh
echo "`date`$*" >> /var/log/echo.alert.log;
ctrl + D <저장>

chmod 755 echo.alert.log ; 실행권한주기

 

 

이중화 구성이 되어 있다면 아래와 같이 특정 데몬 다운시 Heartbeat 를 종료해주는 스크립트를 만들자!

 

#!/bin/sh
IPADDR=`grep "IPADDR=" /etc/sysconfig/network-scripts/ifcfg-eth0 | awk -F'=' '{ print $2 }'`
echo "`date`$*" >> /var/log/smileserv.alert.log;
# heartbeat daemon check
PSID=$(ps ax |grep heartbeat |grep -v grep | awk '{print $1}')
if [ "$PSID" == "" ]; then
exit
else
logger "[$IPADDR] `hostname` alert heartbeat stop."
/etc/init.d/heartbeat stop
fi

 

 

서비스 올라왔을때 스크립트 만들자!

 

#!/bin/sh
IPADDR=`grep "IPADDR=" /etc/sysconfig/network-scripts/ifcfg-eth0 | awk -F'=' '{ print $2 }'`
logger "[$IPADDR] `hostname` upalert "
echo "`date`$*" >> /var/log/smileserv.alert.log;

 

 

서비스 실행

 

/usr/local/src/mon-1.2.0/mon -f -c /etc/mon/mon.cf

 

 

실행하기 힘드니 스크립트 하나 만들자 

vim /etc/init.d/mon (실행권한 755)

 

#!/bin/bash
MON_HOME=/usr/local/src/mon-1.2.0 # 본인이 설치한 폴더위치
MON_CF=/etc/mon # mon.cf 설정파일이 들어갈 위치
case "$1" in
start)
if [ -f $MON_HOME/mon.pid ]; then
echo "mon already started"
exit
fi
echo "Starting Mon"
$MON_HOME/mon -c $MON_CF/mon.cf -L $MON_HOME -P $MON_HOME/mon.pid &
;;
stop)
if [ -f $MON_HOME/mon.pid ]; then
echo "Stopping Mon"
kill -9 `cat $MON_HOME/mon.pid`
rm -f $MON_HOME/mon.pid
else
echo "no server pid, server doesn't seem to run"
fi
;;
status)
echo "doing good"
;;
*)
echo "Usage: $0 {start|stop|status|reload|restart}"
exit 1
esac
exit 0

 

이까지만 하면 apache 올렸다가 내렸다가 하면 작동 잘 된다 mysql 을 구성해볼려고 하는데 죽어도 안되네

각 서비스 데몬 체크시 뭐 별도로 perl 모듈이 부가적으로 필요한것이 많다.

 

mon (mysql 모니터링)

 

This monitor required the perl5 modules DBI, DBD::mysql, and DBD::mSQL, available from CPAN 
(
http://www.cpan.org/). ← 여기 사이트 찾아가보면 perl 관련해서 잡다한거 많다.

wget http://www.cpan.org/modules/by-module/Convert/Convert-BER-1.3101.tar.gz (이건 안 깔아도 되는듯?)
wget 
http://www.cpan.org/modules/by-module/DBI/DBI-1.608.tar.gz
wget http://www.cpan.org/modules/by-module/DBD/DBD-mysql-4.011.tar.gz

wget http://www.cpan.org/modules/by-module/DBD/Msql-Mysql-modules-1.2219.tar.gz

마지막꺼는 위에꺼 2개 합쳐놓은 통합판이라나? DBI 도 있고 DBD-mysql 도 있고 DBD-msql 도 같이 포함된거 같다.

 

 

DBI 설치

 

perl Makefile.PL
make
make test (test 이건 할 필요 없는듯 하다)
make install

rpm 으로 설치
yum install *DBI*

DBI 확인
[root@localhost ~]# perl -MDBI -e 'print "$DBI::VERSION\n"'
1.607

뭔가 버젼이 깔끔하게 떠 준다면 잘 깔린듯? 하다

 

 

DBD::mysql 설치
- 문제는 이거 같기도 하고 설치가 된거 같은데 잘 안된다

 

perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config --libs="-L/usr/local/mysql/lib/mysql -lmysqlclient
-lcrypt -lnsl -lm" --cflags= -I/usr/local/mysql/include/mysql

perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config

perl Makefile.PL --mysql_config=/usr/local/mysql_5.1.41/bin/mysql_config --libs="-L/usr/local/mysql_5.1.41/lib/mysql 
-lmysqlclient -lcrypt -lnsl -lm" --cflags= -I/usr/local/mysql_5.1.41/include/mysql --testhost=localhost --testdb=test 
--testuser=root --testpassword=100dedi@

make; make install

rpm 으로 설치 (그냥 윰으로 깔리면 그냥 까는게 간편할지도)
yum install *DBD*

DBD::mysql 확인

[root@localhost src]# perl -MDBD::mysql -e 'print "$DBD::mysql::VERSION\n"'
4.005

이거 역시 버젼이 깔끔하게 떠주신다.

 

 

모니터링 당하는 쪽 DB 작업 (디비 인증을 위한 모니터링용 계정 /  패스워드 / 테이블 생성)
 - 내 생각에 계정을 새로 생생해도 되나 기존의 root 계정이나 mysql DB로 체크해도 된다..

 

GRANT ALL PRIVILEGES ON test.* TO 'monitoring_user'@'%' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
CREATE DATABASE test
use test;
CREATE TABLE example ( id INT, data VARCHAR(100));

 

 

 http 웹 80번은 쉽게 체크가 되는데 mysql 은 좀 잘 안되는경우 발생한다.
뭔가 이유없이 모를때는 /etc/ld.so.conf 에

 

include ld.so.conf.d/*.conf
/usr/bin/
/lib
/usr/lib
/usr/local/lib
/usr/local/mysql/bin
/usr/local/mysql/lib/mysql # 이 경로가 아마 무슨 libmysqlclient.so 경로인데 적어줘야 함

 

 

samba.monitor 는 없다 인터넷 찾아가서 하나 얻어온다

 

#!/usr/bin/perl
#
# Test SMB Connections using smbclient, you'll need Samba
# Just tries to get a list of shares from the box
#
# For use with "mon".
#
# smb.monitor -p password -u username host1 [ hostN... ]
#
# Copyright (C) 2005, David Busby
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
exit 0 if (!@ARGV);
use
Getopt::Std;
getopts ("p:u:");
# Samba Default
#my $resolve_order = "lmhosts hosts wins bcast"
my $resolve_order = 'wins bcast';
my $debug_level = 1;
my %bad;
# Check the hosts
foreach my $host (@ARGV)
{
my $res = do
{
my $x;
my $cmd = "/usr/bin/smbclient -d $debug_level -L $host -R '$resolve_order' -U '$opt_u\%$opt_p' 2>&1";
my $buf = `$cmd`;
$x->{status} = $?;
$x->{buffer} = $buf;
$x;
};
if ($res->{status}!=0)
{
$bad{$host} = $res;
}
}
# Write messages about the failures
foreach my $h (keys %bad)
{
print "SMB FAILURE: $h $bad{$h}->{status} - $bad{$h}->{buffer}\n";
}
exit scalar(keys(%bad));

 

 

dns.monitor 사용할려면 Net::DNS 모듈 필요 이것도 머 cpan 사이트에 있다 ㅋ

패키지 이름은 perl-Net-DNS 이다. 

yum install perl-Net-DNS
- rpm으로 깔아도 될것이다!

모니터링 아이피의 경우 자신의 공인아이피를 적어줘도 되고 127.0.0.1 루프백 주소를 써도 되는거 같은데
이건 아마 conf 에 셋팅된 아이피나 설정상의 차이가 있을뿐... 오묘한 차이일뿐 ...
기능은 잘 작동하는듯 하다...


[출처] SYSTEM Engineer 깽애니네 (리눅스, 윈도우, 보안, DDOS, 네트워크, 프로그래밍) - http://chonnom.com/bbs/board.php?bo_table=B25&wr_id=18

 

참고 사이트

http://mon.wiki.kernel.org/index.php/Main_Page

http://www.netexpertise.eu/en/mysql/mysql-failover.html

http://sites.google.com/site/kjalleda/mysqlfailover

http://innu.pe.kr/tt/439

'Linux' 카테고리의 다른 글

mon.cf 예제들...  (0) 2015.06.04
cron (crontab)  (0) 2015.06.04
rsync 동기화 설정  (0) 2015.06.04
NTP(Network Time Protocol) 서버 구축  (0) 2015.06.04
error getting update info: Cannot retrieve repository metadata  (0) 2015.06.04
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/03   »
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
글 보관함