您好,登錄后才能下訂單哦!
Zabbix 概述
Zabbix 是一個(gè)高度集成的企業(yè)級(jí)開源網(wǎng)絡(luò)監(jiān)控解決方案,與 Cacti、Nagios 類似,提供分布式監(jiān)控以及集中的 Web 管理界面。由 zabbix serve r端與 zabbix agent 組成。被監(jiān)控對(duì)象只有支持 SNMP 協(xié)議或者運(yùn)行 Zabbix_agents 代理程序即可。Zabbix 的官方網(wǎng)址為 http://www.zabbix.com/ ,軟件可以自由下載使用。
Zabbix 具備常見商業(yè)監(jiān)控軟件所具備的功能:主機(jī)性能檢測網(wǎng)絡(luò)設(shè)備性能監(jiān)控、數(shù)據(jù)庫性能監(jiān)控、ftp等同于協(xié)議的監(jiān)控,能夠利用靈活的可定制警告機(jī)制,運(yùn)行用戶對(duì)事件發(fā)送基于 E-mail 的警告,可以保證相關(guān)維護(hù)人員對(duì)問題作出快速響應(yīng),還可以利用存儲(chǔ)數(shù)據(jù)提供杰出的報(bào)表及實(shí)時(shí)的圖形化數(shù)據(jù)處理。
Zabbix 特點(diǎn)
支持自動(dòng)發(fā)現(xiàn)網(wǎng)絡(luò)設(shè)備和服務(wù)器
支持分布式監(jiān)控
可設(shè)置報(bào)警閥值
可通過多種方式進(jìn)行數(shù)據(jù)收集
可定制的報(bào)警方式
實(shí)時(shí)的繪圖功能
通過web監(jiān)控系統(tǒng)與設(shè)置
案例環(huán)境,如表所示。
主機(jī) 操作系統(tǒng) IP地址 主要操作
Zabbix服務(wù)器 Centos 7 192.168.66.146 搭建LAMP 架構(gòu),部署zabbix-sever
Linux客戶機(jī) Centos 7 192.168.66.145 部署zabbix-agent
解決中文亂碼的軟件包鏈接:
鏈接:https://pan.baidu.com/s/1ObFt9zepWO9l05k-f79ZfQ
提取碼:nxy3
Zabbix 通過 C/S 模式采集數(shù)據(jù),通過 B/S 模式在 Web 端展示和配置。其中 Zabbix_server 可以運(yùn)行在 CentOS 、RHEL 、SUSE 、Ubuntu 等 Linux 系統(tǒng)上,還需要使用 LAMP 平臺(tái)來承載數(shù)據(jù)庫和 Web 界面。
一. 在監(jiān)控端部署 LAMP 架構(gòu)
1.關(guān)閉防火墻
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
2.安裝 LAMP 所需的軟件包
[root@localhost ~]# yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash
3.修改配置文件
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf //httpd 的主配置文件
95 ServerName www.yun.com:80 //設(shè)置servername
163 <IfModule dir_module>
164 DirectoryIndex index.html index.php //頁面首頁類型支持 index.php
編輯 /etc/php.ini 配置文件,設(shè)置時(shí)區(qū)
[root@localhost ~]# vim /etc/php.ini
878 date.timezone = PRC //設(shè)置中國時(shí)區(qū)
4.啟動(dòng) httpd 服務(wù)和 maruadb 服務(wù),并查看端口。
[root@localhost ~]# systemctl start httpd.service
[root@localhost ~]# systemctl start mariadb.service
[root@localhost ~]# netstat -ntap | egrep '(3306|80)' //查看3306和80端口
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 4630/mysqld
tcp6 0 0 :::80 :::* LISTEN 4351/httpd
5.初始化數(shù)據(jù)庫的配置
[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.Enter current password for root (enter for none): //回車進(jìn)入
OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.Set root password? [Y/n] y //設(shè)置root密碼
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.Remove anonymous users? [Y/n] n //是否刪除匿名用戶 n
... skipping.Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] n //運(yùn)行遠(yuǎn)程登錄
... skipping.By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.Remove test database and access to it? [Y/n] n //刪除測試數(shù)據(jù)庫 n
... skipping.Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.Reload privilege tables now? [Y/n] y //重新加載
... Success!Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.Thanks for using MariaDB!
6.數(shù)據(jù)庫初始化完成后,即可登錄數(shù)據(jù)庫
[root@localhost ~]# mysql -uroot –p //使用root 用戶登錄數(shù)據(jù)庫
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.60-MariaDB MariaDB ServerCopyright (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)]> create database zabbix character set utf8 collate utf8_bin; //創(chuàng)建zabbix 數(shù)據(jù)庫,被設(shè)置字符集為簡體中文
Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> show databases; //查看數(shù)據(jù)庫
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)MariaDB [(none)]> grant all privileges on *.* to 'zabbix'@'%' identified by 'admin123';
//創(chuàng)建zabbix用戶,所有庫、表都給zabbix 管理,密碼為:admin123
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> flush privileges; //刷新數(shù)據(jù)庫
Query OK, 0 rows affected (0.00 sec)
使用創(chuàng)建用戶zabbix登錄數(shù)據(jù)庫
[root@localhost html]# mysql -uzabbix -p
Enter password:
ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)使用 zabbix 用戶登錄數(shù)據(jù)庫失敗,其原因是有空用戶名稱占用導(dǎo)致本地?zé)o法連接,解決方法為刪除空用戶名
以root 用戶登錄數(shù)據(jù)庫,刪除空用戶名
[root@localhost html]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.60-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; //查看當(dāng)前用戶
+--------+-----------------------+
| user | host |
+--------+-----------------------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost | //存在兩個(gè)空用戶名
| root | localhost |
| | localhost.localdomain |
| root | localhost.localdomain |
+--------+-----------------------+
7 rows in set (0.00 sec)MariaDB [(none)]> drop user ''@localhost; //刪除空用戶
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> drop user ''@localhost.localdomain;
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> quit
Bye
此時(shí)退出,再以 zabbix 用戶登錄數(shù)據(jù)庫
[root@localhost html]# mysql -uzabbix -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.60-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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)
7. 測試 php ,能否使用 zabbix 用戶連接數(shù)據(jù)庫
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# vim index.php 編輯php首頁<?php
phpinfo();
?>
使用瀏覽器訪問監(jiān)控端的 IP 地址,即192.168.66.146. 查看 php 首頁
將 php 首頁改為測試連接數(shù)據(jù)庫
[root@localhost html]# vim index.php
<?php
$link=mysql_connect('192.168.66.146','zabbix','admin123');
if($link) echo "<h2>Success!!!</h2>";
else echo "Fail!!";
mysql_close();
?>使用 zabbix 用戶連接數(shù)據(jù)庫,連接成功輸出:Success!!! ,連接失敗則輸出:Fail!! 信息
再次使用瀏覽器訪問測試
到此 LAMP 平臺(tái)部署已經(jīng)完成,接下來在監(jiān)控端部署 Zabbix _server 的服務(wù)。
二 . 部署 Zabbix_server 服務(wù)
1 .安裝與 php 相關(guān)的軟件包
[root@localhost html]# yum install php-bcmath php-mbstring –y
安裝 zabbix 的yum 源,自動(dòng)產(chǎn)生 repo 文件
[root@localhost html]# rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm
獲取http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm
警告:/var/tmp/rpm-tmp.85LcDm: 頭V4 RSA/SHA512 Signature, 密鑰 ID a14fe591: NOKEY
準(zhǔn)備中... ################################# [100%]
正在升級(jí)/安裝...
1:zabbix-release-3.5-1.el7 ################################# [100%]
安裝 zabbix-server-mysql 和 zabbix-web-mysql
[root@localhost html]# yum install zabbix-server-mysql zabbix-web-mysql –y
2. 初始化數(shù)據(jù)庫模塊,生成數(shù)據(jù)庫文件,注意密碼不要輸成 root
[root@localhost html]# zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -p zabbix
Enter password: //密碼為 admin123
3.(1)更改配置文件(這些過濾的內(nèi)容是配置文件中自動(dòng)配置好的,不需要更改,只有數(shù)據(jù)庫登錄密碼需要更改)
[root@localhost html]# grep -n '^'[a-Z] /etc/zabbix/zabbix_server.conf
38:LogFile=/var/log/zabbix/zabbix_server.log //日志文件路徑
49:LogFileSize=0 //日志文件大小
72:PidFile=/var/run/zabbix/zabbix_server.pid //pid 文件路徑
82:SocketDir=/var/run/zabbix
101:DBName=zabbix //數(shù)據(jù)庫名稱
117:DBUser=zabbix //數(shù)據(jù)庫用戶
357:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
475:Timeout=4 //超時(shí)信息
518:AlertScriptsPath=/usr/lib/zabbix/alertscripts //腳本文件路徑
529:ExternalScripts=/usr/lib/zabbix/externalscripts //擴(kuò)展性腳本文件
565:LogSlowQueries=3000 //慢日志文件
更改數(shù)據(jù)庫登錄密碼
[root@localhost html]# vim /etc/zabbix/zabbix_server.conf
125 DBPassword=admin123
(2)修改時(shí)區(qū)
[root@localhost html]# vim /etc/httpd/conf.d/zabbix.conf
20 php_value date.timezone Asia/Shanghai //修改為上海的時(shí)區(qū)
(3)修正圖表中文亂碼
[root@localhost html]# vim /usr/share/zabbix/include/defines.inc.php
:%s /graphfont/kaiti/g //將 graphfont 全文替換為 kaiti
復(fù)制相應(yīng)的字體文件到 /usr/share/zabbix/fonts/
[root@localhost html]# yum install lrzsz –y //lrzsz 工具可以在windows 和Linux 系統(tǒng)之間傳輸文件,
[root@localhost html]# mkdir /aaa
[root@localhost html]# cd /aaa
[root@localhost aaa]# ls
[root@localhost aaa]# rz[root@localhost aaa]# ls
php-bcmath-5.4.16-42.el7.x86_64.rpm STKAITI.TTF
php-mbstring-5.4.16-42.el7.x86_64.rpm
[root@localhost aaa]# cp STKAITI.TTF /usr/share/zabbix/fonts/
4啟動(dòng) zabbix-server 服務(wù),并查看端口
[root@localhost aaa]# systemctl start zabbix-server.service
[root@localhost aaa]# systemctl enable zabbix-server.service //開機(jī)自啟動(dòng)
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@localhost aaa]# netstat -an | grep 10051 //zabbix 的端口為10051
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN
tcp6 0 0 :::10051 :::* LISTEN
由于修改過配置文件,重啟 httpd 服務(wù)
[root@localhost aaa]# systemctl restart httpd.service
5.服務(wù)重啟后,訪問 http://192.168.66.146/zabbix ,安裝 zabbix 后登錄。
測試數(shù)據(jù)庫的連通性,測試連通成功會(huì)顯示 OK 字樣。如下圖所示
添加主機(jī)信息
使用默認(rèn)用戶 Admin ,密碼 zabbix 登錄
啟動(dòng)中文界面,Zabbix Web 管理界面自帶多種語言包,默認(rèn)使用的語言為英語。將 Zabbix 語言切換到中文版本
三 . 部署 zabbix_agent 服務(wù)(在被監(jiān)控端搭建)
Agent 的作用就是獲得 host 數(shù)據(jù),然后把收集的數(shù)據(jù)發(fā)送給 Server(主動(dòng)模式)或者是 Server 主動(dòng)來拿取數(shù)據(jù)(被動(dòng)模式)。
1.關(guān)閉防火墻
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.serviceRemoved symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
2. 安裝 yum 源,安裝 zabbix-agent 服務(wù)
[root@localhost ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm
獲取http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm
警告:/var/tmp/rpm-tmp.hITfvK: 頭V4 RSA/SHA512 Signature, 密鑰 ID a14fe591: NOKEY
準(zhǔn)備中... ################################# [100%]
正在升級(jí)/安裝...
1:zabbix-release-3.5-1.el7 ################################# [100%][root@localhost ~]# yum install zabbix-agent –y
3.更改 zabbix_agent 配置文件
[root@localhost ~]# grep -n '^'[a-Z] /etc/zabbix/zabbix_agentd.conf
13:PidFile=/var/run/zabbix/zabbix_agentd.pid
32:LogFile=/var/log/zabbix/zabbix_agentd.log
43:LogFileSize=0
98:Server=127.0.0.1
139:ServerActive=127.0.0.1
150:Hostname=Zabbix server
268:Include=/etc/zabbix/zabbix_agentd.d/*.conf
指定服務(wù)器的 IP地址
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
98 Server=192.168.66.146
139 ServerActive=192.168.66.146
150 Hostname=test
4.啟動(dòng) zabbix-agent 服務(wù)并查看端口
[root@localhost ~]# systemctl start zabbix-agent.service
[root@localhost ~]# systemctl enable zabbix-agent.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
[root@localhost ~]# netstat -natp | grep 10050
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 54896/zabbix_agentd
tcp6 0 0 :::10050 :::* LISTEN 54896/zabbix_agentdserver 端的端口為:10051,agent 端口為:10050
此時(shí) zabbix-server 和 zabbix-agent 都配置完成,并啟動(dòng)服務(wù),到zabbix 的 web 頁面,添加被監(jiān)控主機(jī)。
創(chuàng)建主機(jī)。Host 是 Zabbix 監(jiān)控的基本載體,所有監(jiān)控項(xiàng)目都是基于 Host ??蓮摹芭渲谩?–> “主機(jī)”-> “創(chuàng)建主機(jī)”。
四 . 部署郵件發(fā)送服務(wù)(在監(jiān)控端配置郵件報(bào)警)
1.安裝 mailx 郵件軟件包
[root@localhost aaa]# yum install mailx –y
更改配置文件
[root@localhost aaa]# vim /etc/mail.rc //注意如使用網(wǎng)易或qq郵箱需要開啟客戶端授權(quán)碼進(jìn)行第三方登錄
set from=1947…@qq.com //qq郵箱地址
set smtp=smtp.qq.com
set smtp-auth-user=1947….@qq.com
set smtp-auth-password=ahixbfxiuztjcfjb //第三方授權(quán)碼
set smtp-auth=login
qq郵箱的第三方授權(quán)碼獲得方法如下,進(jìn)入qq郵箱,選擇“設(shè)置” ,然后“賬戶”
發(fā)送郵件測試
[root@localhost aaa]# echo "this is zabbix" | mail -s "testmail" 1947….@qq.com //測試發(fā)送郵件,查看是否能收到
2.編寫發(fā)郵件腳本
[root@localhost aaa]# cd /usr/lib/zabbix/
[root@localhost zabbix]# ls
alertscripts externalscripts
[root@localhost zabbix]# cd alertscripts/
[root@localhost alertscripts]# ls
[root@localhost alertscripts]# vim mail.sh#!/bin/bash
#send mail
messages=`echo $3 | tr '\r\n' '\n'`
subject=`echo $2 | tr '\r\n' '\n'`
echo "${messages}" | mail -s "${subject}" $1 >>/tmp/mailx.log 2>&1
給腳本執(zhí)行權(quán)限
[root@localhost alertscripts]# mv mail.sh mailx.sh
[root@localhost alertscripts]# touch /tmp/mailx.log
[root@localhost alertscripts]# chown -R zabbix.zabbix /tmp/mailx.log
[root@localhost alertscripts]# chmod +x /usr/lib/zabbix/alertscripts/mail.sh
[root@localhost alertscripts]# chown -R zabbix.zabbix /usr/lib/zabbix/
測試發(fā)郵件腳本
[root@localhost alertscripts]# ./mailx.sh 1947…..@qq.com "yum" "heihei"
總結(jié):
Zabbix 是一個(gè)企業(yè)級(jí)的、開源的、分布式的監(jiān)控套件,可以監(jiān)控網(wǎng)絡(luò)和服務(wù)的狀態(tài)。
Zabbix 可以利用數(shù)據(jù)提供圖形化的報(bào)告,還具有靈活的告警機(jī)制。
Zabbix 可以使用 Zabbix Web 管理頁面進(jìn)行管理配置。
Zabbix 自帶多種監(jiān)控模板可以直接使用。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。