自宅サーバ時代の「サーバ管理」
サーバの管理
MRTGによるシステムの監視
MRTGの構築(サーバ側:MainServer)
- (1) インストール
-
# yum install mrtg
Installed: mrtg.i386 0:2.14.5-2 - (2) 監視されるクライアント側のSNMPの設定
-
- (ⅰ)SNMPのインストール
- (ⅱ)SNMPの設定
- (ⅲ)自動起動
# rpm -qa | grep net-snmp
net-snmp-libs-5.3.1-11.fc6
net-snmp-5.3.1-15.fc6
net-snmp-utils-5.3.1-15.fc6com2sec zodiac_network 192.168.1.0/24 zodiac_community
group zodiac_group v1 zodiac_network
group zodiac_group v2c zodiac_network
view zodiac_view included .1
access zodiac_group “” any noauth exact zodiac_view none none# service snmpd start
# chkconfig snmpd on - (3) MRTGの設定
-
- (ⅰ)cfgファイルの設定
- (ⅱ)定期的なグラフの更新
# cd /etc/mrtg/
# cfgmaker zodiac_community@MainServer –output=./MainServer.cfg
# vi MainServer.cfg
### Global Config Options
WorkDir: /var/www/mrtg/MainServer
Language: eucjp
IconDir: /mrtg/icons/### Global Defaults
#—————–
# eth0 traffic
#—————–
Target[eth0]: 2:zodiac_community@MainServer:
SetEnv[eth0]: MRTG_INT_IP=”192.168.1.1″ MRTG_INT_DESCR=”eth0″
MaxBytes[eth0]: 12500000
Title[eth0]: Traffic Analysis for 2 — MainServer.ogino.tk
PageTop[eth0]: Traffic Analysis for 2 — MainServer.ogino.tk#——————
# cpu load average
#——————
Target[la]: 1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.3:zodiac_community@MainServer:
ThreshMaxI[la]:50
SetEnv[la]: EMAIL=”root@localhost”
URL=”http://192.168.1.1/mrtg/MainServer/la.html”
MaxBytes[la]: 100
Title[la]: Load Average
PageTop[la]: CPU Load Average on MainServer.ogino.tk
YLegend[la]: CPU Load Average
ShortLegend[la]: %
LegendI[la]:1min avrg.
LegendO[la]:15min avrg.
#——————
# memory usage
#——————
Target[mem]: 1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.4.0:zodiac_community@MainServer:
ThreshMaxI[mem]:80
SetEnv[mem]: EMAIL=”root@localhost”
URL=”http://192.168.1.1/mrtg/MainServer/mem.html”
MaxBytes[mem]: 190748
Title[mem]: Memory Usage “real” and “swap”
PageTop[mem]: Memory Usage “real” and “swap” on MainServer.ogino.tk
YLegend[mem]: Memory Usage
ShortLegend[mem]: kbyte
LegendI[mem]:real Available.
LegendO[mem]:swap Available.# vi /etc/crontab
*/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/MainServer.cfg
*/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/BackupServer.cfg
*/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/WWWServer.cfg
MRTG(監視されるクライアント側:SubmainServerの設定)
- (1) インストール
-
# tar -zxvf net-snmp-5.2.5.tar.tar
# cd net-snmp-5.2.5
# ./configure –prefix=/usr
# make
# make test
# umask 022
# make install
# ls -l /usr/sbin/snmpd
# ls -l /usr/sbin/snmptrapd
-rwxr-xr-x 1 root root 366287 8月 21 18:22 /usr/sbin/snmptrapd - (2) 設定
-
# vi /usr/share/snmp/snmpd.conf
com2sec zodiac_network 192.168.1.0/24 zodiac_community
group zodiac_group v1 zodiac_network
group zodiac_group v2c zodiac_networkview zodiac_view included .1
access zodiac_group “” any noauth exact zodiac_view none none
- (3) 動作確認
-
# /usr/sbin/snmpd
# snmpwalk -v 2c localcom localhost .1.3.6.1.4.1.2021
# kill `ps -ef | grep snmpd | grep -v grep | awk ‘{print $2}’` - (4) 自動起動
-
# service snmpd start
# chkconfig snmpd on
MRTG(監視されるクライアント側:BackupServerの設定)
- (1) インストール
-
# rpm -qa | grep net-snmp
net-snmp-5.1.1-2
net-snmp-utils-5.1.1-2 - (2) 設定
-
# vi /etc/snmp/snmpd.conf
com2sec zodiac_network 192.168.1.0/24 zodiac_communitygroup zodiac_group v1 zodiac_network
group zodiac_group v2c zodiac_networkview zodiac_view included .1
access zodiac_group “” any noauth exact zodiac_view none none
- (3) 自動起動
-
# service snmpd start
# chkconfig snmpd on
Nagiosによるシステムの監視
Nagiosの構築(サーバ側:MainServer)
- (1) インストール
-
- (ⅰ)Nagios本体
- (ⅱ)プラグイン
$ tar -zxvpf nagios-3.0.3.tar.tar
$ su –# groupadd nagcmd
# /usr/sbin/groupadd nagcmd
# /usr/sbin/usermod -G nagcmd △△△△
# /usr/sbin/usermod -G nagcmd ○○○○
# exit$ cd nagios-3.0.3
$ ./configure –prefix=/usr/local/nagios –with-command-group=nagcmd
$ make all
$ su# make install
# make install-init
# make install-commandmode
# make install-config$ tar -zxvpf nagios-plugins-1.4.12.tar.gz
$ cd nagios-plugins-1.4.12
$ ./configure
–with-apt-get-command:
–with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
–with-ping-command: /bin/ping -n -U -w %d -c %d %s
–with-ipv6: yes
–with-mysql: no
–with-openssl: yes
–with-gnutls: no
–enable-extra-opts: no
–with-perl: /usr/bin/perl
–enable-perl-modules: no
–with-cgiurl: /nagios/cgi-bin
–with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin$ make
$ su
# make install - (2) Webサーバの設定
-
- (ⅰ)Apacheの設定ファイル
# vi /etc/httpd/conf/httpd.conf
ScriptAlias /nagios/cgi-bin/ /usr/local/nagios/sbin/AllowOverride AuthConfig Options ExecCGI Order allow,deny Allow from all Alias /nagios/ /usr/local/nagios/share/ AllowOverride AuthConfig Options None Order allow,deny Allow from all
# /etc/init.d/httpd restart
- (ⅱ)ユーザ及びパスワードの作成
# vi /usr/local/nagios/share/.htaccess
AuthName “Nagios Access”
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
require valid-user# cp /usr/local/nagios/share/.htaccess /usr/local/nagios/sbin/
# su nagios
$ htpasswd -c /usr/local/nagios/etc/htpasswd.users ○○○○
New password:
Re-type new password:
Adding password for user ○○○○# chmod 755 /usr/local/nagios/ ←/usr/local/nagios/が700であったのでPermissionエラーが出たので変更する。
- (3) Nagiosの設定
-
- (ⅰ)メイン設定ファイル
- (ⅱ)CGI設定ファイル
- (ⅲ)リソース設定ファイル
# su nagios
$ cd /usr/local/nagios/etc/
$ vi nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg$ vi cgi.cfg
authorized_for_system_information=○○○○ ←nagiosadminを○○○○に変更
authorized_for_configuration_information=○○○○
authorized_for_system_commands=○○○○
authorized_for_all_services=○○○○
authorized_for_all_hosts=○○○○
authorized_for_all_service_commands=○○○○
authorized_for_all_host_commands=○○○○host_unreachable_sound=hostdown.wav
←#をとる
host_down_sound=hostdown.wav
service_critical_sound=critical.wav
service_warning_sound=warning.wav
service_unknown_sound=warning.wav
normal_sound=noproblem.wav$ vi resource.cfg ←最初からファイルが存在する
- (4) 監視オブジェクトの設定
-
通知先の定義 contacts.cfg
# su nagios
$ cd /usr/local/nagios/etc/object/
$ vi contacts.cfgdefine contact{ contact_name ○○○○ use generic-contact alias Nagios Admin email nagios@ogino.tk } define contactgroup{ contactgroup_name admins alias Nagios Administrators members ○○○○ }
- (5) 設定の確認とNagiosの起動
-
- (ⅰ)設定の確認
- (ⅱ)Nagiosの起動及び自動起動
$ /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors: 0$ /etc/init.d/nagios start
# chkconfig nagios on
# chkconfig –list nagios
nagios 0:off 1:off 2:on 3:on 4:on 5:on 6:off