Zabbix之一---企業級監控服務Zabbix部署與配置


一、業務布局:

  

 二、整體布局

  

三、Zabbix監控概述:

官方文檔:https://www.zabbix.com/cn/features

  

 適用於任何IT基礎架構、服務、應用程序和資源的解決方案

  

1、數據采集:周期性時序數據

(1)主機/對象:服務器、路由器、交換機、存儲、防火牆、IP、PORT、URL、自定義監控對象...

(2)采集目標:監控項,指標數據(metrics data)

2、數據存儲:

(1)存儲系統:

  SQL: MySQL/MariaDB(Zabbix)
  NoSQL:Redis(Open-falcon)
  rrd: Round Robin Database(Cacti)

(2)數據:

  歷史數據: 每個監控項采集到的每個監控值
  趨勢數據: 趨勢表里主要保留某個監控項一個小時內歷史數據的最大值、最小值和平均值以及該監控項一個小時內所采集到的數據個數。

(3)閾值:severity,可按照等級實現層級報警

(4)告警:email, 短信, 微信,語音,故障自治愈

3、四大核心任務:

(1)采集:zabbix-server, zabbix-proxy,zabbix-agent

    Agentless:SNMP,Telnet,ssh,IPMI, JMX,
    Agent:zabbixagent

(2)存儲: zabbixdatabase

(3)展示:zabbixweb

      graph -> screen -> slideshow(將多個screen以幻燈片的方式進行輪流展示)

(4)告警:

  host (host groups) <-templates
  host -> items -> triggers -> action (條件-conditions, 操作-operations)

實戰一:zabbix的搭建與部署

1、配置zabbix-server倉庫並安裝

zabbix官方安裝地址參考:https://www.zabbix.com/cn/download?zabbix=4.0&os_distribution=centos&os_version=7&db=mysql&ws=apache

1、配置zabbix倉庫

[root@localhost yum.repos.d]# cat zabbix.repo 
[zabbix]
name=Zabbix Official Repository - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/\$basearch/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591
 
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/\$basearch/
enabled=1
gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX
gpgcheck=1
 
[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/$basearch/debuginfo/
enabled=0
gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=1

2、安裝Zabbix server,Web前端,agent

# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-get

2、安裝並初始化數據庫

1、安裝服務端數據庫,啟動數據庫並設置為開機啟動。

# yum clean all
# yum install mariadb-server  -y
# chown mysql.mysql /var/lib/mysql -R  # 將數據庫的所有者和所屬組權限進行修改。
# systemctl start mariadb
# systemctl  enable mariadb

2、創建初始化數據庫

(1)vim /etc/my.cnf.d/mariadb-server.cnf 配置文件

[server]
skip_name_resolve = on
innodb_file_per_table = on
innodb_buffer_pool_size = 256M   #buffer緩存大小
max_connections = 2000   #最大連接數
log-bin = master-log    #二進制日志

 (2)創建zabbix數據庫並授權。

[root@computer-2 ~]# mysql
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@'192.168.7.%' identified by '123456';

(3)在mysql客戶端測試連接數據庫

[root@computer-2 network-scripts]# mysql -p123456 -uzabbix  -h192.168.7.100
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

3、初始化架構和數據

1、導入初始架構和數據,系統將提示您輸入新創建的密碼。

# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p -h192.168.7.100 zabbix  # 指定本地的IP地址,不默認就會指向本地localhost

(1)初始化架構和數據時抱有以下錯誤,可以查看數據庫是否存在兩個zabbix用戶賬號,可以刪除空的賬號就可以重新初始化架構和數據。

[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p -h192.168.7.100 zabbix
Enter password: 
ERROR 1045 (28000): Access denied for user 'zabbix'@'zabbix' (using password: YES)

(2)進入到數據庫中查看此時的IP地址和用戶名稱

[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select user,host from mysql.user;
+--------+-------------+
| user   | host        |
+--------+-------------+
| root   | 127.0.0.1   |
| zabbix | 192.168.7.% |
| root   | ::1         |
|        | localhost   |
| root   | localhost   |
|        | zabbix      |  # 將此空的user刪除即可。
| root   | zabbix      |
+--------+-------------+
7 rows in set (0.00 sec)

MariaDB [(none)]> drop user ''@zabbix;  # 刪除空的user數據
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> Ctrl-C -- exit!
Aborted

4、為Zabbix server配置數據庫

1、編輯配置文件 /etc/zabbix/zabbix_server.conf

ListenPort=10051  # zabbix的端口10051
DBHost=192.168.7.100  # 數據庫對外提供的IP地址
DBName=zabbix  # 默認即可
DBUser=zabbix  # 默認即可
DBPassword=123456 # 數據庫密碼
DBPort=3306   # 數據庫服務端口

2、為Zabbix前端配置PHP,修改為本地的上海時區

編輯配置文件 /etc/httpd/conf.d/zabbix.conf

        php_value max_execution_time 300
        php_value memory_limit 128M
        php_value post_max_size 16M
        php_value upload_max_filesize 2M
        php_value max_input_time 300
        php_value max_input_vars 10000
        php_value always_populate_raw_post_data -1
        php_value date.timezone Asia/Shanghai  # 最后一行注釋的改為上海時區

3、啟動Zabbix server和agent進程,並設置為開機啟動

# systemctl restart zabbix-server zabbix-agent httpd
# systemctl enable zabbix-server zabbix-agent httpd

 查看監聽端口狀態:10050是agent端口,10051是zabbix端口,3306是數據庫端口。

4、修改前端web的配置文件

 在以下配置文件中可以查詢IP地址、zabbix服務器名稱、密碼等信息是否正確,如果需要修改數據庫連接,只需要在配置文件中修改即可

[root@zabbix ~]# cp   /usr/share/zabbix/conf/zabbix.conf.php.example /usr/share/zabbix/conf/zabbix.conf.php
[root@zabbix ~]# vim  /usr/share/zabbix/conf/zabbix.conf.php

5、重啟mariadb數據庫和Zabbix server和agent進程

# systemctl restart zabbix-server zabbix-agent httpd mariadb

5、zabbix初始化設置

(1)開始登陸zabbix的web頁面:192.168.7.100/zabbix/index.php

如果彈出以下窗口則證明安裝成功!Zabbix 前端已經就緒!默認的用戶名是 Admin,密碼是zabbix

(2)檢查以下配置有無錯誤

 (3)開始設置數據庫連接

 (4)命名zabbix名稱

 (5)驗證自己輸入無誤后直接下一步

 (6)開始登陸,賬號:Admin  密碼:zabbix

(7)進入zabbix界面

(8)status of zabbix 儀表盤分析

 

Zabbix server is running Yes 192.168.7.100:10051
Number of hosts (enabled/disabled/templates) 91 1 / 0 / 90
Number of items (enabled/disabled/not supported) 88 82 / 0 / 6
Number of triggers (enabled/disabled [problem/ok]) 50 50 / 0 [0 / 50]
Number of users (online) 2 1
Required server performance, new values per second 1.24

 

① 監控主機:已經啟用被監控的主機數量,已經配置好缺被禁止主機數,自帶模板數

② 監控項:啟用多少指標,禁用多少指標,不支持的指標

③ 觸發器數量:啟用,禁用,處於有問題的

④ 當前zabbix有幾個用戶:現在是一個是來賓,一個是管理員

⑤ 重點關注的nvps 每秒的新值(根據我們定義的監控項,每秒采集過來多少新數據,平均值):

 

(9)用戶管理設置,可以設置為中文模式,以及修改zabbix的登陸密碼

此時改為中文后,監控的圖形界面就會是亂碼,我們應該怎么處理呢?下圖是亂碼位置:

答:方法很簡單,只需要在windows系統中尋找一個楷體文件即可:控制面板---->字體----->楷體 常規字體(復制到windows桌面上,等會傳到linux指定的文件夾目錄下)

 (1)查詢linux系統原有字體配置文件:

[root@zabbix fonts]# find / -name defines.inc.php
/usr/share/zabbix/include/defines.inc.php

[root@zabbix fonts]# vim /usr/share/zabbix/include/defines.inc.php 
define('ZBX_GRAPH_FONT_NAME',           'graphfont'); // font file name  # 將graphfont改為自己復制windows系統的字體名稱:simkai
define('ZBX_FONT_NAME', 'graphfont');  # 將graphfont改為自己復制windows系統的字體名稱:simkai

(2)查詢graphfont文件存放的路徑

[root@zabbix fonts]# find / -name graphfont*  # 查詢存放的字體文件路徑,將windows系統的字體存放在此目錄下
/usr/share/zabbix/assets/fonts/graphfont.ttf
[root@zabbix ~]# cd /usr/share/zabbix/assets/fonts/
[root@zabbix fonts]# rz -E # 將下載的windows文件傳到linux指定的目錄下。
rz waiting to receive.
[root@zabbix fonts]# ll
total 11512
lrwxrwxrwx 1 root root 33 Feb 16 10:00 graphfont.ttf -> /etc/alternatives/zabbix-web-font
-rw-r--r-- 1 root root 11785184 Jun 11 2009 simkai.ttf   # windows系統的字體名稱

(3)此時刷新zabbix界面,亂碼部分已解決。

6、被監控node zabbix的安裝配置

 1、在node1主機上配置zabbix倉庫。

[root@computer-2 yum.repos.d]# cat zabbix.repo 
[zabbix]
name=Zabbix Official Repository - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/\$basearch/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591
 
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/\$basearch/
enabled=1
gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX
gpgcheck=1
 
[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/$basearch/debuginfo/
enabled=0
gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=1

2、安裝zabbix-agent包

[root@node1 ~]# yum install zabbix-agent -y

3、配置zabbix-agent文件:

[root@node1 ~]# vim /etc/zabbix/zabbix_agentd.conf

(1) EnableRemoteCommands=0 是否允許執行遠程命令,默認是不允許的,有安全風險 

 (2)修改以下配置文件信息

Server=192.168.7.100   # zabbix服務端的IP地址
Hostname=192.168.7.101 # 本機node1主機的IP地址,或者起一個與zabbix服務器端不重名的名稱
ListenPort=10050    # 本機監聽的端口
ListenIP=0.0.0.0   # 允許監聽在本機的地址,0.0.0.0 是監聽所有

4、配置完zabbix-agent后,重啟zabbix-agent,且查看此時監聽的端口

[root@node1 ~]# systemctl restart zabbix-agent  # 重啟zabbix-agent
[root@node1 ~]# ss -nlt  # 查看10050端口是否被監聽
State       Recv-Q Send-Q                           Local Address:Port                                          Peer Address:Port              
LISTEN      0      100                                  127.0.0.1:25                                                       *:*                  
LISTEN      0      128                                          *:10050                                                    *:*                  
LISTEN      0      128                                          *:22                                                       *:*                  
LISTEN      0      100                                      [::1]:25                                                    [::]:*                  
LISTEN      0      128                                       [::]:22                                                    [::]:*  

7、將node1主機加入到監控中

(1)先添加一個主機群組host groups

  添加一個Linux servers 的host groups

 (2)創建主機

  將node1主機添加到主機群組中

 (2)添加模板,可以搜索linux關鍵字,可以添加到Template OS Linux

 (3)此時可以看到添加的node1已經提示變綠色圖標

 

 

  

  

  

 

  

 

 

  

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM