ค้นหาเว็บไซต์

วิธีติดตั้ง Nagios ใน RHEL, Rocky และ AlmaLinux


Nagios เป็นเครื่องมือตรวจสอบโอเพ่นซอร์สที่ยอดเยี่ยม ซึ่งมอบสภาพแวดล้อมการตรวจสอบที่ครอบคลุมมากขึ้น เพื่อคอยจับตาดูเครื่องจักร/เครือข่ายทั้งหมดของคุณเสมอ ไม่ว่าคุณจะอยู่ในศูนย์ข้อมูลของคุณหรือเพียงแค่ ห้องทดลองขนาดเล็กของคุณ

ด้วย Nagios คุณสามารถตรวจสอบโฮสต์ระยะไกลและบริการของพวกเขาจากระยะไกลได้ในหน้าต่างเดียว โดยจะแสดง คำเตือน และ บ่งชี้ หากมีสิ่งผิดปกติเกิดขึ้นใน เซิร์ฟเวอร์ ของคุณ ซึ่งจะช่วยให้เราตรวจพบปัญหาบางอย่างก่อนที่จะเกิดขึ้นในที่สุด ช่วยให้เราลดเวลาหยุดทำงานและความสูญเสียทางธุรกิจ

เมื่อเร็วๆ นี้ Nagios เปิดตัวเวอร์ชันล่าสุด Nagios Core 4.4.9 และ ปลั๊กอิน Nagios 2.3.3 ที่เสถียรล่าสุดเมื่อวันที่ 4 ตุลาคม 2022 .

บทความนี้มีจุดมุ่งหมายเพื่อแนะนำคำแนะนำง่ายๆ เกี่ยวกับวิธีการติดตั้งและกำหนดค่า Nagios Core เวอร์ชันล่าสุดจากแหล่งที่มา (tarball) บนการกระจายแบบอิง RHEL และ RHEL เช่น CentOS Stream, Rocky Linux, AlmaLinux และ Fedora

ภายใน 30 นาที คุณจะตรวจสอบเครื่องภายในของคุณ ไม่มีขั้นตอนการติดตั้งขั้นสูง มีเพียงการติดตั้งพื้นฐานที่จะทำงานได้ 100% บนเซิร์ฟเวอร์ Linux ส่วนใหญ่ในปัจจุบัน

โปรดทราบ: คำแนะนำในการติดตั้งที่แสดงที่นี่เขียนขึ้นจากการกระจาย RHEL 9.0 Linux

การติดตั้งปลั๊กอิน Nagios Core และ Nagios ใน Linux

หากคุณทำตามคำแนะนำเหล่านี้อย่างถูกต้อง คุณจะได้ข้อมูลต่อไปนี้

  • Nagios และปลั๊กอินจะถูกติดตั้งภายใต้ไดเร็กทอรี /usr/local/nagios
  • Nagios จะได้รับการกำหนดค่าเพื่อตรวจสอบบริการบางอย่างของเครื่องของคุณ (การใช้งานดิสก์, โหลด CPU, ผู้ใช้ปัจจุบัน, กระบวนการทั้งหมด< ฯลฯ)
  • เว็บอินเทอร์เฟซของ Nagios จะมีให้บริการที่ http://localhost/nagios

ขั้นตอนที่ 1: ติดตั้งแพ็คเกจ Apache และ PHP

เราจำเป็นต้องติดตั้ง Apache, PHP, และไลบรารีบางตัวเช่น gcc, glibc, glibc-common , และ GD ไลบรารี่และไลบรารีการพัฒนาก่อนที่จะติดตั้ง Nagios ด้วยซอร์ส และในการทำเช่นนั้น เราสามารถใช้ตัวติดตั้งแพ็คเกจ yum ได้

yum install -y httpd httpd-tools php gcc glibc glibc-common gd gd-devel make net-snmp

ขั้นตอนที่ 2: สร้างผู้ใช้และกลุ่ม Nagios

สร้างผู้ใช้ nagios ใหม่โดยใช้คำสั่ง useradd และบัญชีกลุ่ม nagcmd และตั้ง รหัสผ่าน

[root@tecmint]# useradd nagios
[root@tecmint]# groupadd nagcmd

จากนั้น เพิ่มทั้งผู้ใช้ nagios และผู้ใช้ apache ไปยังกลุ่ม nagcmd โดยใช้คำสั่ง usermod

[root@tecmint]# usermod -G nagcmd nagios
[root@tecmint]# usermod -G nagcmd apache

ขั้นตอนที่ 3: ดาวน์โหลดปลั๊กอิน Nagios Core และ Nagios

สร้างไดเร็กทอรีสำหรับการติดตั้ง Nagios และการดาวน์โหลดทั้งหมดในอนาคต

[root@tecmint]# mkdir /root/nagios
[root@tecmint]# cd /root/nagios

ตอนนี้ดาวน์โหลดแพ็คเกจ Nagios Core และ Nagios Plugins ล่าสุดด้วยคำสั่ง wget

wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.9.tar.gz
wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz

ขั้นตอนที่ 4: แยกปลั๊กอิน Nagios Core และ Nagios

เราจำเป็นต้องแยกแพ็คเกจที่ดาวน์โหลดมาด้วยคำสั่ง tar ดังนี้

tar -xf nagios-4.4.9.tar.gz
tar -xf nagios-plugins-2.3.3.tar.gz

เมื่อคุณแตกไฟล์ tarball เหล่านี้ โฟลเดอร์ใหม่สองโฟลเดอร์จะปรากฏในไดเร็กทอรีนั้น

ls -l

total 13804
drwxrwxr-x 21 root root     4096 Nov 17 02:22 nagios-4.4.9
-rw-r--r--  1 root root 11339450 Nov 17 03:08 nagios-4.4.9.tar.gz
drwxr-xr-x 15 root root     4096 Mar 11  2020 nagios-plugins-2.3.3
-rw-r--r--  1 root root  2782610 Mar 11  2020 nagios-plugins-2.3.3.tar.gz

ขั้นตอนที่ 5: การติดตั้งและกำหนดค่า Nagios Core

ขั้นแรก เราจะกำหนดค่า Nagios Core และเพื่อดำเนินการดังกล่าว เราจำเป็นต้องไปที่ไดเร็กทอรี Nagios และเรียกใช้ไฟล์กำหนดค่าหากทุกอย่างเป็นไปด้วยดี ไฟล์จะแสดงผลลัพธ์ใน สิ้นสุดเป็นเอาต์พุตตัวอย่าง

cd nagios-4.4.9/
./configure --with-command-group=nagcmd

Creating sample config files in sample-config/ ...


*** Configuration summary for nagios 4.4.9 2022-11-16 ***:

 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagcmd
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
    Install ${includedir}:  /usr/local/nagios/include/nagios
                Lock file:  /run/nagios.lock
   Check the result directory:  /usr/local/nagios/var/spool/checkresults
           Init directory:  /lib/systemd/system
  Apache conf.d directory:  /etc/httpd/conf.d
             Mail program:  /usr/bin/mail
                  Host OS:  linux-gnu
          IOBroker Method:  epoll

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

หลังจากกำหนดค่าแล้ว เราจำเป็นต้อง คอมไพล์ และ ติดตั้ง ไบนารีทั้งหมดด้วยคำสั่ง make all และ make install จะติดตั้งไลบรารี่ที่จำเป็นทั้งหมดในเครื่องของคุณ และเราจะดำเนินการต่อไปได้

make all
make install
*** Main program, CGIs and HTML files installed ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

  make install-init
     - This installs the init script in /lib/systemd/system

  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file

  make install-config
     - This installs sample config files in /usr/local/nagios/etc

make[1]: Leaving directory '/root/nagios/nagios-4.4.9'

คำสั่งต่อไปนี้จะติดตั้ง สคริปต์เริ่มต้น สำหรับ Nagios

make install-init

เพื่อให้ Nagios ทำงานจากบรรทัดคำสั่ง เราจำเป็นต้องติดตั้ง โหมดคำสั่ง

make install-commandmode

ถัดไป ติดตั้งไฟล์ Nagios ตัวอย่าง โปรดเรียกใช้คำสั่งต่อไปนี้

make install-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

*** Config files installed ***

Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

ขั้นตอนที่ 6: การปรับแต่งการกำหนดค่า Nagios

เปิดไฟล์ “contacts.cfg” ด้วยตัวแก้ไขที่คุณเลือก และตั้งค่า ที่อยู่อีเมล ที่เชื่อมโยงกับคำจำกัดความผู้ติดต่อของ nagiosadmin เพื่อรับการแจ้งเตือนทางอีเมล

vi /usr/local/nagios/etc/objects/contacts.cfg
###############################################################################
#
CONTACTS
#
###############################################################################

Just one contact defined by default - the Nagios admin (that's you)
This contact definition inherits a lot of default values from the
'generic-contact' template which is defined elsewhere.

define contact {

    contact_name            nagiosadmin             ; Short name of user
    use                     generic-contact         ; Inherit default values from generic-contact template (defined above)
    alias                   Nagios Admin            ; Full name of user
    email                   [email  ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}

ขั้นตอนที่ 7: ติดตั้งและกำหนดค่าเว็บอินเตอร์เฟสสำหรับ Nagios

เราเสร็จสิ้นการกำหนดค่าทั้งหมดในแบ็กเอนด์แล้ว ตอนนี้เราจะกำหนดค่าเว็บอินเตอร์เฟสสำหรับ Nagios ด้วยคำสั่งต่อไปนี้ คำสั่งด้านล่างจะกำหนดค่าเว็บอินเตอร์เฟสสำหรับ Nagios และผู้ดูแลระบบเว็บจะถูกสร้างขึ้น “nagiosadmin

make install-webconf

ในขั้นตอนนี้ เราจะสร้างรหัสผ่านสำหรับ “nagiosadmin ” หลังจากดำเนินการคำสั่งนี้ โปรดระบุ รหัสผ่านสองครั้ง และจำไว้ เนื่องจากรหัสผ่านนี้จะถูกใช้เมื่อคุณเข้าสู่ระบบอินเทอร์เฟซเว็บของ Nagios

htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

รีสตาร์ท Apache เพื่อให้การตั้งค่าใหม่มีผล

systemctl restart httpd

ขั้นตอนที่ 8: รวบรวมและติดตั้งปลั๊กอิน Nagios

ไปที่นั่นและกำหนดค่าและติดตั้งตามคำแนะนำด้านล่าง

cd /root/nagios
cd nagios-plugins-2.3.3
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

ขั้นตอนที่ 9: ตรวจสอบไฟล์การกำหนดค่า Nagios

ตอนนี้เราเสร็จสิ้น การกำหนดค่า Nagios แล้ว และถึงเวลาตรวจสอบความถูกต้องแล้ว โปรดใส่คำสั่งต่อไปนี้ หากทุกอย่างดำเนินไปอย่างราบรื่นก็จะปรากฏขึ้นคล้ายกับผลลัพธ์ด้านล่าง

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 4.4.9
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2022-11-16
License: GPL

Website: https://www.nagios.org
Reading configuration data...
   Read main config file okay...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
	Checked 8 services.
	Checked 1 hosts.
	Checked 1 host groups.
	Checked 0 service groups.
	Checked 1 contacts.
	Checked 1 contact groups.
	Checked 24 commands.
	Checked 5 time periods.
	Checked 0 host escalations.
	Checked 0 service escalations.
Checking for circular paths...
	Checked 1 hosts
	Checked 0 service dependencies
	Checked 0 host dependencies
	Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

ขั้นตอนที่ 10: เพิ่มบริการ Nagios ให้กับการเริ่มต้นระบบ

เพื่อให้ Nagios ทำงานระหว่างการรีบูตเครื่อง เราจำเป็นต้องเปิดใช้งาน nagios และ httpd เมื่อเริ่มต้นระบบโดยใช้คำสั่ง systemctl

systemctl enable nagios
systemctl enable httpd

จากนั้น รีสตาร์ท Nagios เพื่อให้การตั้งค่าใหม่มีผล

systemctl restart nagios

ขั้นตอนที่ 11: อนุญาต Nagios Web ในไฟร์วอลล์

ในการเข้าถึงเว็บอินเตอร์เฟสของ Nagios คุณต้องเปิดพอร์ต Apache โดยรันคำสั่งต่อไปนี้:

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

ขั้นตอนที่ 12: เข้าสู่ระบบเว็บอินเตอร์เฟส Nagios

Nagios ของคุณพร้อมใช้งานแล้ว โปรดเปิดในเบราว์เซอร์ของคุณด้วย “http://Your-server-IP-address/nagios ” หรือ “http://FQDN/nagios ” และระบุชื่อผู้ใช้ “nagiosadmin ” และ รหัสผ่าน

เว็บแดชบอร์ด Nagios

มุมมองโฮสต์

ภาพรวมของ นากิออส

มุมมองบริการ

มุมมองกระบวนการ

ยินดีด้วย! คุณได้ติดตั้งและกำหนดค่า Nagios และ ปลั๊กอิน เรียบร้อยแล้ว คุณเพิ่งเริ่มต้นการเดินทางสู่การติดตามผล

การอัพเกรด Nagios 3.x เป็น Nagios Core 4.x

หากคุณใช้งาน Nagios เวอร์ชันเก่า อยู่แล้ว คุณสามารถ อัปเกรด ได้ตลอดเวลา ในการทำเช่นนั้น คุณเพียงแค่ต้องดาวน์โหลดไฟล์เก็บถาวร tar แหล่งที่มาของ nagios ล่าสุด และกำหนดค่าตามที่แสดงด้านล่าง

systemctl stop nagios
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.9.tar.gz
tar -zxvf nagios-4.4.9.tar.gz
cd nagios-4.4.9
./configure
make all
make install
systemctl start nagios
บทสรุป

เพียงเท่านี้ในบทความต่อๆ ไป ฉันจะแสดงให้คุณเห็นวิธีการเพิ่ม Linux, Windows, เครื่องพิมพ์, สวิตช์, <และอุปกรณ์ไปยังเซิร์ฟเวอร์ตรวจสอบ Nagios

หากคุณประสบปัญหาขณะติดตั้ง โปรดติดต่อเราผ่านทางความคิดเห็น จนกว่าจะคอยติดตามและเชื่อมต่อกับ Tecmint และอย่าลืม ถูกใจ และ แชร์ เราเพื่อเผยแพร่ไปทั่ว

อ่านเพิ่มเติม:

  • วิธีเพิ่มโฮสต์ Linux ให้กับ Nagios Monitoring Server
  • วิธีเพิ่มโฮสต์ Windows ไปยัง Nagios Monitoring Server