Parakushtet
Hapi 1: Përditësoni sistemin
Hapi 2: Instaloni paketat e kërkuara
Hapi 3: Vendosni bazën e të dhënave
Hapi 4: Inicializoni masterin
Hapi 5: Inicializoni klientin
Hapi 6: Konfiguro klientin
Hapi 7: Shtoni klientin në konfigurimin master
Hapi 8: Komandat dhe kontrollet e personalizuara
Icinga2 është një sistem i fuqishëm monitorimi dhe kur përdoret në një model master-klient, ai mund të zëvendësojë nevojën për kontrolle monitorimi të bazuara në NRPE. Modeli master-klient është më i sigurt për arsye të ndryshme . Ai gjithashtu lejon monitorim më të shpërndarë duke lejuar që kontrollet të modifikohen në një server dhe të përhapen te të tjerët. Ai gjithashtu jep një vendndodhje të centralizuar për ndryshime.
Për shembull: Le të themi se keni 4 serverë të ndryshëm ueb të balancuar me ngarkesë. Nëse e dini se do të keni një rritje të ngarkesës (ndoshta një shitje ose diçka për të cilën parashikoni shumë aktivitet), mund të dëshironi të rrisni nivelet në të cilat përdorimi i lartë i CPU-së paralajmëron administratorët e sistemit. Nëse jeni duke përdorur kontrolle NRPE, do t'ju duhet të shkoni në secilin server dhe të modifikoni /etc/nrpe.d/common_commands.cfgdokumentin në secilin prej tyre. Në modelin master-klient, thjesht mund të modifikoni përkufizimet e tyre të hostit në /etc/icinga2/repository.d/hosts/dosje, më pas ringarkoni Icinga. Kontrollet do të përhapen në çdo server dhe do të merren automatikisht. Ju gjithashtu mund të shtoni kontrolle shumë lehtë duke modifikuar /etc/icinga2/repository.d/services/skedarët, dhe ato automatikisht do të përhapen dhe do të njihen, për sa kohë që shtojcat ekzistojnë në serverët e klientit.
Parakushtet
- Një shembull i serverit me Icinga2 dhe Icingaweb2 tashmë të instaluar dhe konfiguruar ( udhëzime ) të emërtuar
icinga2master.example.com.
- Një shembull i ri i serverit Vultr CentOS 6 ose 7 që dëshironi të monitoroni me emër
icinga2client.example.com.
- Qasje Sudo.
Disa nga ky udhëzues do të pasqyrojnë udhëzimet e instalimit të listuara më sipër, por kjo duhet të bëhet në makinën e klientit dhe jo në makinën e serverit.
Hapi 1: Përditësoni sistemin
Shtoni repon "ICINGA" në sistemin e klientit për të instaluar paketat Icinga.
sudo cat > /etc/yum.repos.d/ICINGA-release.repo << 'EOF'
[icinga-stable-release]
name=ICINGA (stable release for epel)
baseurl=http://packages.icinga.org/epel/$releasever/release/
enabled=1
gpgcheck=1
gpgkey=http://packages.icinga.org/icinga.key
EOF
Hapi 2: Instaloni paketat e kërkuara
Instaloni paketat e kërkuara.
# CentOS 6
sudo yum -y install icinga2 mysql-server mysql icinga2-ido-mysql nagios-plugins-disk nagios-plugins-load nagios-plugins-procs nagios-plugins-ssh nagios-plugins-users nagios-plugins-swap nagios-plugins-ping icingacli
# CentOS 7
sudo yum -y install icinga2 mariadb-server mysql icinga2-ido-mysql nagios-plugins-disk nagios-plugins-load nagios-plugins-procs nagios-plugins-ssh nagios-plugins-users nagios-plugins-swap nagios-plugins-ping icingacli
CentOS 7 përdor MariaDB në vend të MySQL, kështu që paketat e nevojshme janë paksa të ndryshme. Nisni shërbimet dhe vendosni ato të fillojnë në nisje.
sudo chkconfig icinga2 on
sudo service icinga2 start
Vendosni shërbimin MySQL të fillojë në nisje dhe ta nisni atë tani në mënyrë që ta sigurojmë atë.
# CentOS 6
sudo chkconfig mysqld on
sudo service mysqld start
#CentOS 7
sudo systemctl enable mariadb.service
sudo systemctl start mariadb.service
Siguroni instalimin MySQL/MariaDB. Të dy CentOS 6 dhe 7 përdorin të njëjtën komandë.
sudo mysql_secure_installation
Gjatë procesit, përgjigjuni pyetjeve siç tregohet:
Enter current password for root (enter for none): Enter
Set root password? [Y/n]: Y
New password: $newRootPassword
Re-enter new password: $newRootPassword
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y
Vini re $newRootPasswordse do t'ju duhet disa herë, dhe është një dhimbje për ta rivendosur.
Hapi 3: Vendosni bazën e të dhënave
Ju duhet të krijoni icingaemrin e përdoruesit dhe të importoni skemën në bazën e të dhënave. Kjo bëhet në të njëjtën mënyrë si në CentOS 6 ashtu edhe në 7.
sudo mysql -u root -p
>CREATE DATABASE icinga;
>GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON icinga.* TO 'icinga'@'localhost' IDENTIFIED BY '$someIcingaPassword';
>exit
Më pas, importoni skemën në bazën e të dhënave që sapo keni krijuar.
sudo mysql -u root -p icinga < /usr/share/icinga2-ido-mysql/schema/mysql.sql
Do t'ju duhet të vendosni $newRootPasswordfjalëkalimin MySQL/MariaDB që keni përdorur gjatë mysql_secure_installationkomandës së mësipërme, jo atë $someIcingaPasswordqë sapo keni krijuar - ai përdoret më vonë.
Aktivizo idomodulin (bazën e të dhënave).
sudo icinga2 feature enable ido-mysql
Do t'ju duhet të redaktoni /etc/icinga2/features-enabled/ido-mysql.confskedarin për të shtuar informacionin e bazës së të dhënave. Ju mund ta bëni këtë me komandën e mëposhtme.
sudo vi /etc/icinga2/features-enabled/ido-mysql.conf
Në atë skedar, gjeni rreshtat që komentohen (filloni me //).
//user = "icinga"
//password = "icinga"
//host = "localhost"
//database = "icinga"
...dhe modifikojini duke përdorur përdoruesin/fjalëkalimin që sapo keni krijuar.
user = "icinga"
password = "$someIcingaPassword"
host = "localhost"
database = "icinga"
Sigurohuni që të hiqni komentet e rreshtave duke hequr dy prerjet fillestare.
Më pas, rinisni shërbimin për të marrë ndryshimet.
sudo service icinga2 restart
Ju do të duhet të shtoni një lidhje midis serverit të klientit dhe masterit Icinga2 që është konfiguruar tashmë. Ju do të duhet ta bëni këtë duke përdorur ose Firewalld në CentOS 7, ose IPTables në CentOS 6 ose 7.
# CentOS 6
sudo vi /etc/sysconfig/iptables
...
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5665 -j ACCEPT
...
#Icinga2 Master
-A OUTPUT -p tcp -m state --state NEW -m tcp --dport 5665 -j ACCEPT
sudo iptables restart
# CentOS 7
sudo firewall-cmd --add-port=5665/tcp --permanent
sudo firewall-cmd --reload
Tani, modifikoni skedarin e hosteve për të shtuar masterin si një emër domeni lokal.
sudo vi /etc/hosts
...
$masterIP icinga2master icinga2master.example.com
Hapi 4: Inicializoni masterin
Ky hap duhet të bëhet në masterin Icinga2. Do t'ju duhet ta inicializoni atë si master dhe më pas të krijoni një kërkesë për nënshkrimin e certifikatës që klienti juaj do ta përdorë për të komunikuar.
sudo icinga2 node wizard
Kjo do të ekzekutojë magjistarin e nyjeve, i cili do të bëjë disa pyetje. Ekrani do të duket si më poshtë dhe përgjigjet që do të jepni janë të renditura.
Welcome to the Icinga 2 Setup Wizard!
We'll guide you through all required configuration details.
Please specify if this is a satellite setup ('n' installs a master setup) [Y/n]: n
Starting the Master setup routine...
Please specify the common name (CN) [icinga2-master1.localdomain]: icinga2master.example.com
Checking for existing certificates for common name 'icinga2master.example.com'...
Certificates not yet generated. Running 'api setup' now.
information/cli: Generating new CA.
information/base: Writing private key to '/var/lib/icinga2/ca/ca.key'.
information/base: Writing X509 certificate to '/var/lib/icinga2/ca/ca.crt'.
information/cli: Generating new CSR in '/etc/icinga2/pki/icinga2master.example.com.csr'.
information/base: Writing private key to '/etc/icinga2/pki/icinga2master.example.com.key'.
information/base: Writing certificate signing request to '/etc/icinga2/pki/icinga2master.example.com.csr'.
information/cli: Signing CSR with CA and writing certificate to '/etc/icinga2/pki/icinga2master.example.com.crt'.
information/cli: Copying CA certificate to '/etc/icinga2/pki/ca.crt'.
Generating master configuration for Icinga 2.
information/cli: Adding new ApiUser 'root' in '/etc/icinga2/conf.d/api-users.conf'.
information/cli: Enabling the 'api' feature.
Enabling feature api. Make sure to restart Icinga 2 for these changes to take effect.
information/cli: Dumping config items to file '/etc/icinga2/zones.conf'.
information/cli: Created backup file '/etc/icinga2/zones.conf.orig'.
Please specify the API bind host/port (optional):
Bind Host []: <hit enter>
Bind Port []: <hit enter>
information/cli: Created backup file '/etc/icinga2/features-available/api.conf.orig'.
information/cli: Updating constants.conf.
information/cli: Created backup file '/etc/icinga2/constants.conf.orig'.
information/cli: Updating constants file '/etc/icinga2/constants.conf'.
information/cli: Updating constants file '/etc/icinga2/constants.conf'.
information/cli: Updating constants file '/etc/icinga2/constants.conf'.
Done.
Now restart your Icinga 2 daemon to finish the installation!
Më pas, rinisni Icinga2 për të marrë ndryshimet.
sudo service icinga2 restart
Tani që është master, mund ta përdorni për të gjeneruar vargun e kërkesës për nënshkrimin e certifikatës.
sudo icinga2 pki ticket --cn icinga2client.example.com
Ju do të merrni një varg $pkiString. Kopjojeni atë varg, pasi do t'ju duhet tek klienti.
Hapi 5: Inicializoni klientin
Drejtoni magjistarin e nyjeve për të gjeneruar certifikatat dhe për t'u lidhur me masterin.
sudo icinga2 node wizard
Do të dalë me një faqe të ngjashme me sa më sipër. Kjo faqe është paraqitur më poshtë me përgjigjet e përfshira.
Welcome to the Icinga 2 Setup Wizard!
We'll guide you through all required configuration details.
Please specify if this is a satellite setup ('n' installs a master setup) [Y/n]: Y
Starting the Node setup routine...
Please specify the common name (CN) [icinga2client.example.com]:
Please specify the master endpoint(s) this node should connect to:
Master Common Name (CN from your master setup): icinga2master.example.com
Do you want to establish a connection to the master from this node? [Y/n]: Y
Please fill out the master connection information:
Master endpoint host (Your master's IP address or FQDN): icinga2master.example.com
Master endpoint port [5665]: 5665
Add more master endpoints? [y/N]: N
Please specify the master connection for CSR auto-signing (defaults to master endpoint host):
Host [icinga2master.example.com]: icinga2master.example.com
Port [5665]: 5665
information/cli: Created backup file '/etc/icinga2/pki/icinga2client.example.com.key.orig'.
information/cli: Created backup file '/etc/icinga2/pki/icinga2client.example.com.crt.orig'.
information/base: Writing private key to '/etc/icinga2/pki/icinga2client.example.com.key'.
information/base: Writing X509 certificate to '/etc/icinga2/pki/icinga2client.example.com.crt'.
information/cli: Fetching public certificate from master (icinga2master.example.com, 5665):
Certificate information:
Subject: CN = icinga2master.example.com
Issuer: CN = Icinga CA
Valid From: Jan 10 21:08:37 2017 GMT
Valid Until: Jan 7 21:08:37 2032 GMT
Fingerprint: FE 72 AB F3 18 A5 12 E0 0C 5D 94 8B 96 C4 57 3B 00 5C E0 04
Is this information correct? [y/N]: Y
information/cli: Received trusted master certificate.
Please specify the request ticket generated on your Icinga 2 master.
(Hint: # icinga2 pki ticket --cn 'icinga2client.example.com'): $pkiString
information/cli: Requesting certificate with ticket '$pkiString'.
warning/cli: Backup file '/etc/icinga2/pki/icinga2client.example.com.crt.orig' already exists. Skipping backup.
information/cli: Writing signed certificate to file '/etc/icinga2/pki/icinga2client.example.com.crt'.
information/cli: Writing CA certificate to file '/etc/icinga2/pki/ca.crt'.
Please specify the API bind host/port (optional):
Bind Host []: <enter key>
Bind Port []: <enter key>
Accept config from master? [y/N]: Y
Accept commands from master? [y/N]: Y
information/cli: Disabling the Notification feature.
Disabling feature notification. Make sure to restart Icinga 2 for these changes to take effect.
information/cli: Enabling the Apilistener feature.
warning/cli: Feature 'api' already enabled.
information/cli: Created backup file '/etc/icinga2/features-available/api.conf.orig'.
information/cli: Generating local zones.conf.
information/cli: Dumping config items to file '/etc/icinga2/zones.conf'.
information/cli: Created backup file '/etc/icinga2/zones.conf.orig'.
information/cli: Updating constants.conf.
information/cli: Created backup file '/etc/icinga2/constants.conf.orig'.
information/cli: Updating constants file '/etc/icinga2/constants.conf'.
information/cli: Updating constants file '/etc/icinga2/constants.conf'.
Done.
Now restart your Icinga 2 daemon to finish the installation!
Vazhdoni dhe rinisni Icinga2 për të marrë ndryshimet.
sudo icinga2 restart
Kjo mund të jetë bërë tashmë, por duhet të siguroheni që komanda dhe veçoritë API janë aktivizuar.
sudo icinga2 feature enable command
sudo icinga2 feature enable api
If they weren't enabled, it will say "feature enabled", so you'll need to restart the Icinga2 daemon. But first, you need to change ownership of the files in the /etc/icinga2 directory, as some of them have the wrong permissions after running the node wizard. They should all have their owner and group set to icinga. Change the permissions by using the following command:
sudo chown -R icinga:icinga /etc/icinga2/
Now, you can restart the Icinga2 daemon.
sudo service icinga2 restart
The client configuration requires editing a few different files.
/etc/icinga2/zones.conf: Contains the endpoints (servers) and zones that contain them. This is how the servers are partitioned. Make sure the client names match the server names.
/etc/icinga2/icinga2.conf: You are accepting commands and configs from the master, so you need to do a minor edit on this file to avoid duplicate command definitions.
First, we're going to modify the zones.conf file to define the server and the zone it's in, as well as creating a "global" zone for command definitions that are universal to ALL servers, instead of unique to each (such as disk checks).
sudo vi /etc/icinga2/zones.conf
object Zone clientZone {
endpoints = [ "icinga2master.example.com" ]
}
object Zone "global-templates" { # Add global templates zone
global = true
}
object Endpoint NodeName {
host = "$icinga2clientIP"
}
object Zone ZoneName {
endpoints = [ NodeName ]
parent = clientZone
}
It is important to know, there can only be 2 nodes per zone at the moment. You can make as many zones as you wish, but if there are more than 2 nodes per zone there is a chance that the Icinga2 service will not work properly. This is not a problem on the client, unless you already have 2 nodes in the zone clientZone, in which case you will need to make another zone name.
Now, make the modification in the /etc/icinga2/icinga2.conf file. You need to comment out the line include_recursive "conf.d".
sudo vi /etc/icinga2/icinga2.conf
...
//include_recursive "conf.d"
...
Verify config to ensure that everything is formatted correctly.
sudo icinga2 daemon -C
If you get permissions problems, it's likely because the item is owned by root:root. Chown to icinga:icinga to resolve.
sudo chown -R icinga:icinga /etc/icinga2/
There are other issues with the configs, generally the information given from the output of the sudo icinga2 daemon -C command will be verbose enough to track them down. Addressing every potential issue that arises is outside the scope of this guide.
If the verification succeeds, go ahead and reload the service:
sudo service icinga2 restart
You'll need to give the icinga user sudo permissions so that the commands can be run. These sudo permissions will be restricted to the specific plugin directory. This can just be put at the end of the file.
sudo vi /etc/sudoers
...
Defaults:icinga !requiretty
icinga ALL=(ALL) NOPASSWD: /usr/lib64/nagios/plugins/
Tani konfigurimi i klientit ka përfunduar zyrtarisht. Nuk duhet të bëni më modifikime, çdo kontroll shërbimi do të konfigurohet në master dhe do të përhapet deri te klienti. Sidoqoftë, do t'ju duhet të instaloni çdo shtojcë shtesë që mund t'ju nevojitet. Plug-in-et mund të shkruhen gjithashtu duke përdorur python, perl, BASH, PHP dhe gjuhë të tjera të shkruara.
Hapi 7: Shtoni klientin në konfigurimin master
Do t'ju duhet të ktheheni te masteri për të konfiguruar klientin në mënyrë që të mund të lidhet. Ka disa hapa që do të duhet të ndërmerren:
- Shto konfigurimin e hostit në
repository.d.
- Shto host në zonë si pikë përfundimtare.
- Konfiguro çdo kontroll për klientin. Kjo është pak jashtë fushëveprimit të këtij udhëzuesi, unë do të jap vetëm një shpjegim bazë të hapave të përfshirë.
Konfigurimi i hostit do të futet në /etc/icinga2/repository.d/hosts/icinga2client.example.com.confskedar.
sudo vi /etc/icinga2/repository.d/hosts/icinga2client.example.com.conf
object Host "icinga2client.example.com" {
import "satellite-host"
address = "$icinga2clientIP"
vars.os = "Linux"
}
sudo chown icinga:icinga /etc/icinga2/repository.d/hosts/icinga2client.example.com.conf
Tani hosti ekziston në konfigurimin e klientit, por duhet të vendoset në një zonë. Kjo zonë do të jetë në /etc/icinga2/repository.d/zonesdosje, me të njëjtin emër si emri i zonës për ta bërë më të lehtë ndjekjen.
sudo vi /etc/icinga2/repository.d/zones/clientZone.conf
object Zone "clientZone" {
endpoints = [ "icinga2client.example.com" ]
parent = "icinga2master.example.com"
}
Tjetra, duhet të shtoni global-templateszonën.
sudo vi /etc/icinga2/repository.d/zones/global-templates.conf
object Zone "global-templates" {
global = true
}
Së fundi, shtoni pikën fundore të klientit në mënyrë që grupi i pikave fundore "clientZone" të plotësohet kur të ekzekutohet.
sudo vi /etc/icinga2/repository.d/endpoints/icinga2client.example.com.conf
#Change values to match the host you're adding
object Endpoint "icinga2client.example.com" {
host = "$icinga2clientIP"
}
Për t'u siguruar që nuk ka probleme me lejet, vazhdoni dhe ndryshoni përsëri zotëruesin/grupin.
sudo chown -R icinga:icinga /etc/icinga2
Verifikoni ndryshimet e konfigurimit për t'u siguruar që nuk ka më probleme.
sudo icinga2 daemon -C
Nëse verifikimi ka sukses, vazhdoni me ringarkimin.
sudo service icinga2 restart
Nëse vizitoni faqen tuaj të internetit të Icinga2, do të shihni se serveri bëhet i aksesueshëm.
Hapi 8: Komandat dhe kontrollet e personalizuara
Mund të hasni gabime në lidhje me "komanda nuk u gjet" ose "kontrolli nuk është përcaktuar". Këtu hyn në lojë zona e modeleve globale. Ju do të duhet të kopjoni konfigurimin në /etc/icinga2/conf.d/skedarë dhe t'i vendosni ato në /etc/icinga2/zones.d/global-templates/skedarë. Për shembull, për të krijuar një komandë "check_software", do t'ju duhet të bëni sa më poshtë.
sudo mkdir /etc/icinga2/zones.d/global-templates
sudo vi /etc/icinga2/zones.d/global-templates/commands.conf
object CheckCommand "check_software" {
import "plugin-check-command"
command = [ "/usr/bin/sudo", PluginDir + "/software_service_check.sh" ]
}
software_service_check.shDosja do të duhet të ekzistojnë në /usr/lib64/nagios/pluginsdosje në klientin .
Më pas, shtoni kontrollin e shërbimit në /etc/icinga2/repository.d/hosts/services.confskedar.
sudo vi /etc/icinga2/repository.d/hosts/services/services.conf
apply Service "Check Software Service" {
import "mail-service"
check_command = "check_software" # This check command is the same name as the one you defined in global-templates/commands.conf
assign where host.vars.client_endpoint # This will apply to every client server. If you need it to be more restrictive, you should look into custom variables
}
Do t'ju duhet të ndryshoni përsëri lejet.
sudo chown -R icinga:icinga /etc/icinga2
Pastaj, ri-verifikoni konfigurimin.
sudo icinga2 daemon -C
Më në fund, nëse ka sukses, ringarkoni:
sudo service icinga2 restart
urime! Tani po përdorni Icinga2 në një model master-klient dhe tani mund të shmangni përdorimin e kontrolleve të pasigurta NRPE!