zabbix介紹
zabbix簡介
zabbix
是一個基於WEB界面的提供分布式系統監視以及網絡監視功能的企業級的開源解決方案。
zabbix
能監視各種網絡參數,保證服務器系統的安全運營;並提供靈活的通知機制以讓系統管理員快速定位/解決存在的各種問題。
zabbix
由2部分構成,zabbix server
與可選組件zabbix agent
。
zabbix server
可以通過SNMP
,zabbix agent
,ping
,端口監視等方法提供對遠程服務器/網絡狀態的監視,數據收集等功能,它可以運行在Linux,Ubuntu,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。
zabbix agent
需要安裝在被監視的目標服務器上,它主要完成對硬件信息或與操作系統有關的內存,CPU等信息的收集。
zabbix server
可以單獨監視遠程服務器的服務狀態;同時也可以與zabbix agent
配合,可以輪詢zabbix agent
主動接收監視數據(agent方式),同時還可被動接收zabbix agent
發送的數據(trapping方式)。
另外zabbix server
還支持SNMP (v1,v2),可以與SNMP軟件(例如:net-snmp)等配合使用。
zabbix特點
zabbix的主要特點:
- 安裝與配置簡單,學習成本低
- 支持多語言(包括中文)
- 免費開源
- 自動發現服務器與網絡設備
- 分布式監視以及WEB集中管理功能
- 可以無agent監視
- 用戶安全認證和柔軟的授權方式
- 通過WEB界面設置或查看監視結果
- email等通知功能
Zabbix主要功能:
- CPU負荷
- 內存使用
- 磁盤使用
- 網絡狀況
- 端口監視
- 日志監視
zabbix配置文件
zabbix配置文件有兩種:
- 服務器端配置文件(/usr/local/etc/zabbix_server.conf)
- 客戶端配置文件(/usr/local/etc/zabbix_agentd.conf)
- zabbix代理配置文件(/usr/local/etc/zabbix_proxy.conf)
服務器端配置文件zabbix_server.conf常用配置參數:
參數 | 作用 |
---|---|
LogFile | 設置服務端日志文件存放路徑 |
ListenIP | 設置服務端監聽IP |
ListenPort | 設置服務端監聽的端口號 |
PidFile | 設置服務端進程號文件存放路徑 |
DBHost | 指定zabbix的數據庫服務器IP |
DBName | 指定zabbix使用的數據庫庫名 |
DBUser | 指定zabbix數據庫登錄用戶 |
DBPassword | 指定zabbix數據庫登錄密碼 |
DBPort | 指定zabbix數據庫端口號 |
User | 設置zabbix以什么用戶的身份運行 |
AlertScriptsPath | 設置告警腳本存放路徑 |
ExternalScripts | 外部腳本存放路徑 |
客戶端配置文件zabbix_agentd.conf常用配置參數:
參數 | 作用 |
---|---|
Server | 指定zabbix服務器的IP或域名 |
ServerActive | 指定zabbix服務器的IP或域名 |
Hostname | 指定本機的主機名,此項必須與web界面配置項一致 |
UnsafeUserParameters | 是否啟用自定義監控項,可選值為{1 | 0} |
UserParameter | 指定自定義監控腳本參數 |
LogFile | 設置客戶端日志文件存放路徑 |
zabbix服務端部署
zabbix下載
訪問網站zabbix官網--->點擊下載
選擇Sources--->點擊下載
使用xftp傳到本機
zabbix服務端安裝
zabbix
官方幫助文檔:https://www.zabbix.com/manuals
環境說明:
環境 | IP | 要安裝的應用 |
---|---|---|
服務端 | 192.168.110.30 | lamp架構 zabbix_server zabbix_agent |
因為zabbix
是用php
語言開發的,所以必須先部署lamp
架構,使其能夠支持運行php
網頁
LAMP部署方法和介紹詳情請見:利用shell腳本實現lamp部署 + LAMP介紹和部署流程
開始部署
//安裝依賴包
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel libxml2 libxml2-devel curl-devel
//可以使用wget下載zabbix,也可以通過上面的方法使用xftp傳到當前目錄
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.2/zabbix-5.2.6.tar.gz
//解壓zabbix安裝包
[root@localhost src]# tar xf zabbix-5.2.6.tar.gz
//創建zabbix用戶和組
[root@localhost src]# useradd -r -M -s /sbin/nologin zabbix
[root@localhost src]# id zabbix
uid=991(zabbix) gid=988(zabbix) groups=988(zabbix)
//配置zabbix數據庫
#設置環境變量
[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost ~]# source /etc/profile.d/mysql.sh
#連接數據庫
[root@localhost src]# mysql -uroot -p
Enter password: (這里輸入的是設置的密碼123456)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.31 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@192.168.110.30 identified by 'zabbiix123!';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123!
!';
Query OK, 0 rows affected, 2 warnings (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
//導入文件到數據庫
[root@localhost src]# cd /usr/src/zabbix-5.2.6/database/mysql/
[root@localhost mysql]# ls
data.sql double.sql images.sql Makefile.am Makefile.in schema.sql
#導入sql數據表
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
//連接數據庫,驗證
[root@localhost mysql]# mysql -uroot -p
Enter password: (輸入123456)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.31 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)
mysql> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
.....
.....
| usrgrp |
| valuemaps |
| widget |
| widget_field |
+----------------------------+
170 rows in set (0.00 sec)
mysql> quit
Bye
//編譯安裝zabbix
[root@localhost ~]# cd /usr/src/zabbix-5.2.6
[root@localhost zabbix-5.2.6]# ./configure --enable-server \
> --enable-agent \
> --with-mysql \
> --with-net-snmp \
> --with-libcurl \
> --with-libxml2
#成功界面如下
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
[root@localhost zabbix-5.2.6]# make install
zabbix服務端配置
//查看日志文件
[root@localhost ~]# ls /usr/local/etc/
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d
//修改服務端配置文件
#設置數據庫信息
[root@localhost ~]# vim /usr/local/etc/zabbix_server.conf
### Option: DBPassword
# Database password.
# Comment this line if no password is used.
#
# Mandatory: no
# Default:
# DBPassword=
DBPassword=zabbix123! //添加這一行,設置zabbix數據庫連接密碼
#啟動服務端server和客戶端agentd
[root@localhost ~]# zabbix_server
zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
#執行時報錯,解決報錯
[root@localhost ~]# ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64
#啟動
[root@localhost ~]# zabbix_server
[root@localhost ~]# zabbix_agentd
#10050和10051端口已經起來了
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
zabbix web界面安裝與配置
zabbix web界面安裝前配置
//修改/etc/php.ini的配置並重啟php-fpm
[root@localhost ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost ~]# systemctl restart php-fpm
//把ui里的文件拷貝到新創建的zabbix目錄下
[root@localhost ~]# mkdir /usr/local/apache/htdocs/zabbix
[root@localhost ~]# cp -a /usr/src/zabbix-5.2.6/ui/* /usr/local/apache/htdocs/zabbix/
[root@localhost ~]# chown -R apache.apache /usr/local/apache/htdocs
//配置apache虛擬主機
[root@localhost ~]# vim /usr/local/apache/conf/extra/vhosts.conf
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/zabbix"
ServerName www.leidazhuang.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
<Directory "/usr/local/apache/htdocs/zabbix">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
//設置zabbix/conf目錄的權限,讓zabbix有權限生成配置文件zabbix.conf.php
[root@localhost ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwxrwx. 3 apache apache 94 Mar 29 17:21 /usr/local/apache/htdocs/zabbix/conf
//重啟apache服務
[root@localhost ~]# /usr/local/apache/bin/apachectl -t
Syntax OK
[root@localhost ~]# /usr/local/apache/bin/apachectl restart
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
開始安裝zabbix web界面
- 在windows主機上修改/etc/hosts文件,添加域名與IP的映射
- 在瀏覽器上訪問域名,本文設置的域名為zabbix.example.com,你需要修改成你自己的域名
- 恢復zabbix/conf目錄的權限為755
訪問ip 192.168.110.30
進入安裝頁面 ---> 點擊next下一步
檢測是否都是ok ---> 點擊next下一步
輸入—授權的ip地址—數據庫名字(zabbix)—用戶(默認:zabbix)—密碼(zabbix123!) ---> 點擊next下一步
注意: 如果連接不上,那么可能是selinx沒有關閉(setenforce 0)
輸入Host Port ---> 點擊next下一步
設置時區樣式 ---> 點擊next下一步
開始安裝 ---> 安裝完成后 ---> 點擊Finishi完成
自動跳轉用戶登錄界面
恢復zabbix/conf目錄的權限為755
[root@localhost ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxr-xr-x. 3 apache apache 117 Apr 7 23:46 /usr/local/apache/htdocs/zabbix/conf
登錄zabbix
zabbix默認登錄用戶名和密碼:
用戶名 | 密碼 |
---|---|
Admin | zabbix |
輸入用戶名和密碼登錄zabbix
注意:輸入密碼的時候一定要仔細哦,注意大寫!!!
登錄成功
設置zabbix開機自啟
zabbix的源碼提供了系統服務腳本,在/usr/src/zabbix-5.2.6/misc/init.d/目錄下,我的系統是RedHat的,所以選擇fedora下的腳本復制到/etc/init.d下
[root@localhost ~]# cd /usr/src/zabbix-5.2.6/misc/init.d/fedora/core5/
[root@localhost core5]# ls
zabbix_agentd zabbix_server
[root@localhost core5]# cp -a zabbix_server /etc/init.d/
[root@localhost core5]# cp -a zabbix_agentd /etc/init.d/
//添加到開啟自啟動文件
#服務端
[root@localhost core5]# chkconfig --add zabbix_server
[root@localhost core5]# chkconfig zabbix_server on
[root@localhost core5]# chkconfig --list|grep zabbix_server
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
zabbix_server 0:off 1:off 2:on 3:on 4:on 5:on 6:off
#客戶端
[root@localhost core5]# chkconfig --add zabbix_agentd
[root@localhost core5]# chkconfig zabbix_agentd on
[root@localhost core5]# chkconfig --list|grep zabbix_agentd
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
zabbix_agentd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
//重啟測試一下
#重啟
[root@localhost ~]# reboot
#關閉selinx和防火牆
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
#啟動apache
[root@localhost ~]# /usr/local/apache/bin/apachectl start
#查看端口
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
通過網頁測試