支持分布式監控
    可設置報警閥值
    可通過多種方式進行數據收集
    可定制的報警方式
    實時的繪圖功能
    通過web監控系統與設置

案例環境,如表所示。

主機                      操作系統                  IP地址                         主要操作

Zabbix服務器       Centos 7                     192.168.66.146           搭建LAMP 架構,部署zabbix-sever

Linux客戶機          Centos 7                     192.168.66.145           部署zabbix-agent

解決中文亂碼的軟件包鏈接:

鏈接:https://pan.baidu.com/s/1ObFt9zepWO9l05k-f79ZfQ
提取碼:nxy3

         Zabbix 通過 C/S 模式采集數據,通過 B/S 模式在 Web 端展示和配置。其中 Zabbix_server 可以運行在 CentOS 、RHEL 、SUSE 、Ubuntu 等 Linux 系統上,還需要使用 LAMP 平臺來承載數據庫和 Web 界面。

一. 在監控端部署 LAMP 架構

1.關閉防火墻

[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                                                 //設置servername

163 <IfModule dir_module>
164     DirectoryIndex index.html index.php                                 //頁面首頁類型支持 index.php

編輯 /etc/php.ini 配置文件,設置時區

[root@localhost ~]# vim /etc/php.ini

878 date.timezone = PRC                               //設置中國時區

4.啟動 httpd 服務和 maruadb 服務,并查看端口。

[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.初始化數據庫的配置    

[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):                   //回車進入
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                                 //設置root密碼
New
Re-enter new
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         //運行遠程登錄
  … 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              //刪除測試數據庫 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.數據庫初始化完成后,即可登錄數據庫

[root@localhost ~]# mysql -uroot –p                //使用root 用戶登錄數據庫
Enter
Welcome to the MariaDB monitor.  Commands end with ; or \\\\g.
Your MariaDB connection id is 6
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)]> create database zabbix character set utf8 collate utf8_bin;         //創建zabbix 數據庫,被設置字符集為簡體中文
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;                //查看數據庫
——————–
| 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';  

//創建zabbix用戶,所有庫、表都給zabbix 管理,
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;                //刷新數據庫
Query OK, 0 rows affected (0.00 sec)

使用創建用戶zabbix登錄數據庫

[root@localhost html]# mysql -uzabbix -p
Enter
ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using )

使用 zabbix 用戶登錄數據庫失敗,其原因是有空用戶名稱占用導致本地無法連接,解決方法為刪除空用戶名

以root 用戶登錄數據庫,刪除空用戶名

[root@localhost html]# mysql -uroot -p
Enter
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;                //查看當前用戶
——– ———————–
| user   | host                  |
——– ———————–
| zabbix | %                     |
| root   | 127.0.0.1             |
| root   | ::1                   |
|        | localhost             |                                    //存在兩個空用戶名
| 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

此時退出,再以 zabbix 用戶登錄數據庫

[root@localhost html]# mysql -uzabbix -p
Enter
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 用戶連接數據庫

[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# vim index.php                  編輯php首頁

<?php
   phpinfo();
?>

使用瀏覽器訪問監控端的 IP 地址,即192.168.66.146. 查看 php 首頁

將 php 首頁改為測試連接數據庫

[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 用戶連接數據庫,連接成功輸出:Success!!!  ,連接失敗則輸出:Fail!! 信息

再次使用瀏覽器訪問測試

到此 LAMP 平臺部署已經完成,接下來在監控端部署 Zabbix _server 的服務。

二 . 部署 Zabbix_server 服務

1 .安裝與 php 相關的軟件包 

[root@localhost html]# yum install php-bcmath php-mbstring –y

安裝 zabbix 的yum 源,自動產生 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
準備中…                          ################################# [100%]
正在升級/安裝…
    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. 初始化數據庫模塊,生成數據庫文件,注意密碼不要輸成 root

[root@localhost html]# zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -p zabbix
Enter          //密碼為 admin123

3.(1)更改配置文件(這些過濾的內容是配置文件中自動配置好的,不需要更改,只有數據庫登錄密碼需要更改)

[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                                                                         //數據庫名稱
117:DBUser=zabbix                                                                           //數據庫用戶
357:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log    
475:Timeout=4                                                                                   //超時信息
518:AlertScriptsPath=/usr/lib/zabbix/alertscripts                       //腳本文件路徑
529:ExternalScripts=/usr/lib/zabbix/externalscripts                   //擴展性腳本文件
565:LogSlowQueries=3000                                                               //慢日志文件

更改數據庫登錄密碼

[root@localhost html]# vim /etc/zabbix/zabbix_server.conf

125 DBPassword=admin123

(2)修改時區

[root@localhost html]# vim /etc/httpd/conf.d/zabbix.conf

20          php_value date.timezone Asia/Shanghai               //修改為上海的時區

(3)修正圖表中文亂碼

[root@localhost html]# vim /usr/share/zabbix/include/defines.inc.php

:%s /graphfont/kaiti/g          //將 graphfont 全文替換為 kaiti

復制相應的字體文件到 /usr/share/zabbix/fonts/

[root@localhost html]# yum install lrzsz –y       //lrzsz 工具可以在windows 和Linux 系統之間傳輸文件,

[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啟動 zabbix-server 服務,并查看端口

[root@localhost aaa]# systemctl start zabbix-server.service
[root@localhost aaa]# systemctl enable zabbix-server.service                  //開機自啟動
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 服務

[root@localhost aaa]# systemctl restart httpd.service

5.服務重啟后,訪問 http://192.168.66.146/zabbix  ,安裝 zabbix 后登錄。

測試數據庫的連通性,測試連通成功會顯示 OK 字樣。如下圖所示

添加主機信息

使用默認用戶 Admin ,密碼 zabbix  登錄

啟動中文界面,Zabbix Web 管理界面自帶多種語言包,默認使用的語言為英語。將 Zabbix 語言切換到中文版本

三 . 部署 zabbix_agent 服務(在被監控端搭建)

Agent 的作用就是獲得 host 數據,然后把收集的數據發送給 Server(主動模式)或者是 Server 主動來拿取數據(被動模式)。

1.關閉防火墻

[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. 安裝 yum 源,安裝 zabbix-agent 服務

[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
準備中…                          ################################# [100%]
正在升級/安裝…
    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

指定服務器的 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.啟動 zabbix-agent 服務并查看端口

[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_agentd

server 端的端口為:10051,agent 端口為:10050

此時 zabbix-server 和 zabbix-agent 都配置完成,并啟動服務,到zabbix 的 web 頁面,添加被監控主機。

創建主機。Host  是 Zabbix 監控的基本載體,所有監控項目都是基于 Host 。可從“配置” –> “主機”-> “創建主機”。

四 . 部署郵件發送服務(在監控端配置郵件報警)

1.安裝 mailx 郵件軟件包

[root@localhost aaa]# yum install mailx –y

更改配置文件

[root@localhost aaa]# vim /etc/mail.rc               //注意如使用網易或qq郵箱需要開啟客戶端授權碼進行第三方登錄

set from=1947…@qq.com                             //qq郵箱地址
set smtp=smtp.qq.com
set smtp-auth-user=1947….@qq.com
set smtp-auth-password=ahixbfxiuztjcfjb        //第三方授權碼
set smtp-auth=login

qq郵箱的第三方授權碼獲得方法如下,進入qq郵箱,選擇“設置” ,然后“賬戶”

發送郵件測試

[root@localhost aaa]# echo "this is zabbix" | mail -s "testmail" 1947….@qq.com         //測試發送郵件,查看是否能收到

2.編寫發郵件腳本

[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

給腳本執行權限

[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/

測試發郵件腳本

[root@localhost alertscripts]# ./mailx.sh 1947…..@qq.com "yum" "heihei"

總結:

Zabbix 是一個企業級的、開源的、分布式的監控套件,可以監控網絡和服務的狀態。

Zabbix 可以利用數據提供圖形化的報告,還具有靈活的告警機制。

Zabbix 可以使用 Zabbix Web 管理頁面進行管理配置。

Zabbix 自帶多種監控模板可以直接使用。

更多關于云服務器域名注冊,虛擬主機的問題,請訪問三五互聯官網:m.shinetop.cn

贊(0)
聲明:本網站發布的內容(圖片、視頻和文字)以原創、轉載和分享網絡內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。郵箱:3140448839@qq.com。本站原創內容未經允許不得轉載,或轉載時需注明出處:三五互聯知識庫 » 部署 Zabbix 集中監控系統 (基于 LAMP 架構)

登錄

找回密碼

注冊

主站蜘蛛池模板: 亚洲熟女乱一区二区三区| 亚洲人成网网址在线看| 中国女人熟毛茸茸A毛片| 国产一区日韩二区欧美三区| 在线观看潮喷失禁大喷水无码| 亚洲国产精品午夜福利| 最近中文字幕免费手机版| 亚洲国产高清在线观看视频| 国产久久热这里只有精品| 国产日韩久久免费影院| 少妇真人直播免费视频| 亚洲日韩一区二区| 日本一区三区高清视频| 免费观看全黄做爰大片国产| 清纯唯美人妻少妇第一页| 精品无人乱码一区二区三区的优势| 日韩av片无码一区二区三区| 国产成人a在线观看视频免费| 亚洲 小说区 图片区 都市| 国产天堂亚洲国产碰碰| 9lporm自拍视频区| 少妇人妻偷人精品视频| 亚洲an日韩专区在线| 久久久av波多野一区二区| 人妻丝袜无码专区视频网站| 无码日韩av一区二区三区| 国产成人不卡一区二区| 性姿势真人免费视频放| 无码 人妻 在线 视频| 18禁精品一区二区三区| 亚洲 a v无 码免 费 成 人 a v| 韩国午夜福利片在线观看| 土默特左旗| 免费看亚洲一区二区三区| 亚洲精品成人福利网站| 亚洲偷自拍国综合| 国产黄色一区二区三区四区| 亚洲综合在线日韩av| 久久综合狠狠综合久久激情| 内射视频福利在线观看| 国产精品成人一区二区三|