Seseorang Sys-Admin atau Network Administrator perlu tools untuk memonitoring apakah service pada sebuah server down atau up dan jaringan tertentu terputus dan sebagainya. Nagios salah satu perangkat lunak yang bisa dipergunakan untuk memenuhi kebutuhan ini dan di Nagios bisa memberikan Alert bila ada yang down lewat visual nya berbasis Web-GUI dan Alert melalui Email, SMS, Telegram maupun Whatsapp.
Disini akan dibahas bagaimana cara menginstall dan config Nagios di CentOS 6.8 64bit…
Cara Install dan Basic Config…
- Install CentOS 6.8 64bit seperti biasa.
- Update System dan Install packages yang diperlukan
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm # rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm # yum update -y # yum -y install nagios nagios-plugins-all nagios-plugins-nrpe nrpe ndoutils php httpd gd gd-devel gcc glibc glibc-common
- Jalankan service HTTPD dan NAGIOS juga jangan lupa aktifkan kedua service ini saat booting pertamakali server dihidupkan.
# service httpd start && service nagios start && service nrpe start && chkconfig httpd on && chkconfig nagios on && chkconfig nrpe on
- Matikan service yang tidak diperlukan
# service rpcbind stop && service postfix stop && chkconfig rpcbind off && chkconfig postfix off
- Aktifkan SWAP setidaknya 2GB
# dd if=/dev/zero of=/swap bs=1024 count=2097152 # mkswap /swap && chown root. /swap && chmod 0600 /swap && swapon /swap # echo /swap swap swap defaults 0 0 >> /etc/fstab # echo vm.swappiness = 0 >> /etc/sysctl.conf && sysctl -p
- Membuat user dan password untuk masuk ke Web-GUI Nagios, disini dengan contoh user nagiosadmin. User boleh diganti dengan apa saja namun bila username di rubah harus rubah config di /etc/nagios/cgi.cfg
# htpasswd -c /etc/nagios/passwd nagiosadmin
- Edit file /etc/nagios/nrpe.cfg dan tambahkan IP server-nya
allowed_hosts=127.0.0.1 192.168.3.237
- Edit file /etc/sysconfig/iptables dan tambahkan baris sebagai berikut
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT
sebelum baris…
-A INPUT -j REJECT --reject-with icmp-host-prohibited
kemudian copy /etc/sysconfig/iptables dan replace ke /etc/sysconfig/iptables.old
- Basic Configure… terlebih dahulu back-up semua file config default-nya…
# cp /etc/nagios/nagios.cfg /etc/nagios/nagios.cfg.old # cp /etc/nagios/objects/commands.cfg /etc/nagios/objects/commands.cfg.old # cp /etc/nagios/objects/templates.cfg /etc/nagios/objects/templates.cfg.old
- Edit file config /etc/nagios/nagios.cfg dan setelah baris cfg_file=/etc/nagios/objects/templates.cfg tambahkan baris cfg_file=/etc/nagios/objects/services.cfg…
[...] cfg_file=/etc/nagios/objects/templates.cfg cfg_file=/etc/nagios/objects/services.cfg [...]
- Buat file config /etc/nagios/objects/services.cfg sebagai default service ping yang akan di check oleh nagios apapun hardware-nya, dan isinya…
# Define a host for the local machine define service { use local-service host_name * is_volatile 0 check_period 24x7 normal_check_interval 1 retry_check_interval 1 notifications_enabled 1 notification_interval 1 notification_period 24x7 notification_options w,u,c,r service_description PING check_command check_ping!100.0,20%!500.0,60% } - Terakhir sebagai langah final, restart semua service
# service nagios restart && service nrpe restart && service iptables restart
- Akses Web-GUI dengan cara http://IP/nagios dan masukkan username beserta password-nya… kenudian pilih menu pada sisi kiri click Tactical Overview kondisi dimana Monitoring Features harus tanda centang dan hijau…

Menambahkan Host dan Group yang di Monitoring…
- Contoh:ada 4 perangkat, 2 unit server dan 2 unit router, dibagi 2 group yaitu Servers dan Routers yang dimana untuk routers akan di monitoring hanya down/up yaitu service default (ping) sedangkan untuk server selain hanya down/up perangkat melainkan di monitoring service port HTTP, SSH dan FTP.Untuk router, sebut saja Mikrotik di IP 192.168.3.254 dan Mikrotik-Tester di IP 192.168.3.100, sedangkan server pertama adalah server nagios sendiri di IP 192.168.3.237 dan server selanjutnya diberi nama mirror dengan IP 192.168.3.110.
- Sebelum membuat file config untuk Host, sebaiknya buat file config untuk Host Groups, sesuai rencana sebelumnya ada Servers Host Groups dan Routers Host Groups, setelah file config Host Groups maka pada file config host bisa ditambahkan baris hostgroups dan di susul nama group. Berikut isi file config di /etc/nagios/hostgroups.cfg….
define hostgroup{ hostgroup_name linux-servers alias Linux Servers } define hostgroup{ hostgroup_name router alias Router } - Buat config untuk group router dengan nama file /etc/nagios/routers.cfg dengan memakai templates generic-router dan isinya…
#Host define host{ use generic-router host_name mikrotik alias Mikrotik address 192.168.3.254 check_command check-host-alive check_period 24x7 notification_interval 0 notification_period 24x7 notification_options d,u,r icon_image router.png statusmap_image router.png hostgroups router } define host{ use generic-router host_name mikrotik-tester alias Mikrotik-Tester address 192.168.3.200 check_command check-host-alive check_period 24x7 notification_interval 0 notification_period 24x7 notification_options d,u,r icon_image router.png statusmap_image router.png hostgroups router } - Buat config untuk group server dengan nama file /etc/nagios/servers.cfg karena server-server tersebut maka dengan memakai templates linux-server. Kemudian untuk service checking port HTTP, SSH maupun FTP maka bawahnya tambahan command service dengan host_name beranggotakan server yang akan di moniroting service-nya, dan isinya…
#Host define host{ use linux-server host_name nagios alias Nagios Server address 192.168.3.237 check_command check-host-alive check_perio 24x7 notification_interval 0 notification_period 24x7 notification_options d,u,r icon_image linux40.png statusmap_image linux40.png hostgroups linux-servers } define host{ use linux-server host_name mirror alias Mirror Server address 192.168.3.110 check_command check-host-alive check_period 24x7 notification_interval 0 notification_period 24x7 notification_options d,u,r icon_image linux40.png statusmap_image linux40.png hostgroups linux-servers } #Service define service{ use local-service host_name nagios,mirror is_volatile 0 check_period 24x7 normal_check_interval 1 retry_check_interval 1 notification_interval 0 notification_period 24x7 notification_options w,u,c,r service_description SSH check_command check_ssh } define service{ use local-service host_name nagios,mirror is_volatile 0 check_period 24x7 normal_check_interval 1 retry_check_interval 1 notification_interval 0 notification_period 24x7 notification_options w,u,c,r service_description HTTP check_command check_http } define service{ use local-service host_name nagios,mirror is_volatile 0 check_period 24x7 normal_check_interval 1 retry_check_interval 1 notification_interval 0 notification_period 24x7 notification_options w,u,c,r service_description FTP check_command check_ftp } - Kemudian rubah config pada file /etc/nagios/nagios.cfg dan tambahkan baris…
cfg_file=/etc/nagios/hostgroups.cfg cfg_file=/etc/nagios/servers.cfg cfg_file=/etc/nagios/routers.cfg
- Final-nya check keseluruhan file-file config dan pastikan tidak ada error
# nagios -v /etc/nagios/nagios.cfg
- Terakhir restart service nagios
# service nagios restart
- Lihat pada web click menu kiri mulai Hosts, Services dan Host Groups…

