其他分享
首页 > 其他分享> > zabbix3.2监控搭建

zabbix3.2监控搭建

作者:互联网

zabbix

环境配置

配置IP主机名

c@192.168.31.144

[root@b ~]# nmtui

[root@b ~]# hostnamectl set-hostname zabbix-server
[root@b ~]# cat /etc/centos-release
CentOS Linux release 7.7.1908 (Core)
[root@b ~]# uname -r
3.10.0-1062.el7.x86_64
[root@b ~]# reboot

关闭防火墙,禁用SElinux

[root@zabbix-server ~]# systemctl stop firewalld
[root@zabbix-server ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@zabbix-server ~]# sed -i 's/=enforcing/=disabled/' /etc/sysconfig/selinux
[root@zabbix-server ~]# sed -i 's/=enforcing/=disabled/' /etc/selinux/config
[root@zabbix-server ~]# setenforce 0

安装常用软件

[root@zabbix-server ~]# yum install net-tools bash-completion wget ntpdate vim -y

时间同步

[root@zabbix-server ~]# ntpdate cn.pool.ntp.org
24 Oct 18:03:45 ntpdate[1507]: adjust time server 148.251.69.45 offset 0.003344 sec
[root@zabbix-server ~]# hwclock -w

准备LAMP环境

[root@zabbix-server ~]# yum install httpd mariadb mariadb-server php php-mysql php-gd -y

配置zabbix yum

[root@zabbix-server zabbix-server-mysql-4.0.13]# yum install https://mirrors.aliyun.com/zabbix/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm -y
Total size: 21 k
Installed size: 21 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : zabbix-release-3.2-1.el7.noarch                    1/1
  Verifying  : zabbix-release-3.2-1.el7.noarch                    1/1

Installed:
  zabbix-release.noarch 0:3.2-1.el7

Complete!
[root@zabbix-server ~]# ll /etc/yum.repos.d/zabbix.repo
-rw-r--r--. 1 root root 410 Oct  2  2018 /etc/yum.repos.d/zabbix.repo

安装zabbix server

[root@zabbix-server ~]# yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
[root@zabbix-server ~]# rpm -aq | grep zabbix
zabbix-server-mysql-3.2.11-1.el7.x86_64
zabbix-web-mysql-3.2.11-1.el7.noarch
zabbix-agent-3.2.11-1.el7.x86_64
zabbix-release-3.2-1.el7.noarch
zabbix-web-3.2.11-1.el7.noarch

修改php时区

[root@zabbix-server ~]# sed -i 's@# php_value date.timezone Europe/Riga@php_value date.timezone Asia/Shanghai@g' /etc/httpd/conf.d/zabbix.conf

要注意需要改的配置文件是/etc/httpd/conf.d/zabbix.conf而不是/etc/php.ini

启动数据库

[root@zabbix-server ~]# systemctl start mariadb
[root@zabbix-server ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

创建zabbix数据库及用户

[root@zabbix-server ~]# mysql -e "create database zabbix character set utf8;"
[root@zabbix-server ~]# mysql -e "grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';"
[root@zabbix-server ~]# mysqladmin flush-privileges

导入数据库

[root@zabbix-server ~]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/
[root@zabbix-server zabbix-server-mysql-4.0.13]# zcat create.sql.gz | mysql -uzabbix -p zabbix
Enter password:
[root@zabbix-server zabbix-server-mysql-4.0.13]# mysql -uzabbix -p -e 'use zabbix;show tables;'
Enter password:
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
| auditlog_details           |
| autoreg_host               |
| conditions                 |
| config                     |
| corr_condition             |
| corr_condition_group       |
| corr_condition_tag         |
| corr_condition_tagpair     |
| corr_condition_tagvalue    |
| corr_operation             |
| correlation                |
| dashboard                  |
| dashboard_user             |
| dashboard_usrgrp           |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_suppress             |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| history                    |
| history_log                |
| history_str                |
| history_text               |
| history_uint               |
| host_discovery             |
| host_inventory             |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| hstgrp                     |
| httpstep                   |
| httpstep_field             |
| httpstepitem               |
| httptest                   |
| httptest_field             |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
| interface                  |
| interface_discovery        |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| item_preproc               |
| items                      |
| items_applications         |
| maintenance_tag            |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| mappings                   |
| media                      |
| media_type                 |
| opcommand                  |
| opcommand_grp              |
| opcommand_hst              |
| opconditions               |
| operations                 |
| opgroup                    |
| opinventory                |
| opmessage                  |
| opmessage_grp              |
| opmessage_usr              |
| optemplate                 |
| problem                    |
| problem_tag                |
| profiles                   |
| proxy_autoreg_host         |
| proxy_dhistory             |
| proxy_history              |
| regexps                    |
| rights                     |
| screen_user                |
| screen_usrgrp              |
| screens                    |
| screens_items              |
| scripts                    |
| service_alarms             |
| services                   |
| services_links             |
| services_times             |
| sessions                   |
| slides                     |
| slideshow_user             |
| slideshow_usrgrp           |
| slideshows                 |
| sysmap_element_trigger     |
| sysmap_element_url         |
| sysmap_shape               |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| tag_filter                 |
| task                       |
| task_acknowledge           |
| task_check_now             |
| task_close_problem         |
| task_remote_command        |
| task_remote_command_result |
| timeperiods                |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
| widget                     |
| widget_field               |
+----------------------------+

修改zabbix配置文件

[root@zabbix-server zabbix-server-mysql-4.0.13]# grep ^DB /etc/zabbix/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix

启动zabbix及apache

[root@zabbix-server ~]# grep ^DB /etc/zabbix/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
[root@zabbix-server ~]# systemctl restart zabbix-server.service httpd.service
[root@zabbix-server ~]# systemctl enable zabbix-server.service httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@zabbix-server ~]# netstat -lnupt | egrep '80|10051'
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      2431/zabbix_server
tcp6       0      0 :::10051                :::*                    LISTEN      2431/zabbix_server
tcp6       0      0 :::80                   :::*                    LISTEN      2429/httpd

Web 界面安装master

浏览器输入网址:

http://192.168.31.145/zabbix/setup.php

密码为:

zabbix

此处信息:

Host:localhost
Port:10051
Name:zabbix-server

此处信息:

Username:admin
Password:zabbix

修改密码

配置zabbix-agent端

[root@zabbix-server ~]# grep ^Server /etc/zabbix/zabbix_agentd.conf
Server=127.0.0.1
ServerActive=127.0.0.1
[root@zabbix-server ~]# systemctl start zabbix-agent.service
[root@zabbix-server ~]# 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@zabbix-server ~]# netstat -lnupt | grep 1005
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      2737/zabbix_agentd
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      2431/zabbix_server
tcp6       0      0 :::10050                :::*                    LISTEN      2737/zabbix_agentd
tcp6       0      0 :::10051                :::*                    LISTEN      2431/zabbix_server

默认情况下zabbix server可以监控自己,但状态是Disabled

启用监控

修改密码并设置中文

解决中文乱码

将中文字体拷贝到以下目录:

/usr/share/zabbix/fonts
[root@zabbix-server ~]# ls /usr/share/zabbix/fonts/
graphfont.ttf  simkai.ttf

修改zabbix php配置文件

sed -i 's/graphfont/simkai/g' /usr/share/zabbix/include/defines.inc.php

修改图像字体的软链接为绝对路径:

cd /etc/alternatives
mv zabbix-web-font zabbix-web-font.bak
ln -s /usr/share/zabbix/fonts/simkai.ttf zabbix-web-font
rm -rf zabbix-web-font.bak
[root@zabbix-server alternatives]# ls -l | grep zabbix-web-font
lrwxrwxrwx. 1 root root 34 Oct 24 20:49 zabbix-web-font -> /usr/share/zabbix/fonts/simkai.ttf

修改字体配置:

chmod 777 /usr/share/zabbix/include/defines.inc.php
vim /usr/share/zabbix/include/defines.inc.php
# vim中搜索ZBX_GRAPH_FONT_NAME
/ZBX_GRAPH_FONT_NAME
# 改成这样
define('ZBX_GRAPH_FONT_NAME',           'simkai'); // font file name
# :x 保存退出
chmod 755 /usr/share/zabbix/include/defines.inc.php

安装graphtrees插件

将插件拷贝到以下目录:

/usr/share/zabbix/

来源:

https://github.com/OneOaaS/graphtrees/blob/master/graphtree3.2.x.patch
[root@zabbix-server zabbix]# ll -h graphtree3.2.x.patch
-rwxr-xr-x. 1 c c 3.1M Oct 24 20:18 graphtree3.2.x.patch

打补丁

[root@zabbix-server zabbix]# yum install -y patch
[root@zabbix-server zabbix]# patch -Np0 <graphtree3.2.x.patch

修改权限

[root@zabbix-server zabbix]# chown -R apache:apache oneoaas/

重启apache

[root@zabbix-server zabbix]# systemctl restart httpd

部署监控

更改被监控机的主机名e@192.168.31.146

[root@d ~]# hostnamectl set-hostname linux-server1
[root@d ~]# cat /etc/centos-release
CentOS Linux release 7.7.1908 (Core)
[root@d ~]# uname -r
3.10.0-1062.el7.x86_64
[root@d ~]# reboot

关闭防火墙,禁用SElinux

[root@linux-server1 ~]# systemctl stop firewalld
[root@linux-server1 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@linux-server1 ~]# sed -i 's/=enforcing/=disabled/' /etc/sysconfig/selinux
[root@linux-server1 ~]# sed -i 's/=enforcing/=disabled/' /etc/selinux/config
[root@linux-server1 ~]# setenforce 0

安装zabbix yum源

[root@linux-server1 ~]# yum install https://mirrors.aliyun.com/zabbix/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm -y
Total size: 21 k
Installed size: 21 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : zabbix-release-3.2-1.el7.noarch                          1/1
  Verifying  : zabbix-release-3.2-1.el7.noarch                          1/1

Installed:
  zabbix-release.noarch 0:3.2-1.el7

Complete!

安装agent

[root@linux-server1 ~]# yum install zabbix-agent -y
Total download size: 348 k
Installed size: 1.3 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/zabbix/packages/zabbix-agent-3.2.11-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Public key for zabbix-agent-3.2.11-1.el7.x86_64.rpm is not installed
zabbix-agent-3.2.11-1.el7.x86_64.rpm                   | 348 kB   00:03
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
Importing GPG key 0xA14FE591:
 Userid     : "Zabbix LLC <packager@zabbix.com>"
 Fingerprint: a184 8f53 52d0 22b9 471d 83d0 082a b56b a14f e591
 Package    : zabbix-release-3.2-1.el7.noarch (@/zabbix-release-3.2-1.el7.noarch)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : zabbix-agent-3.2.11-1.el7.x86_64                         1/1
  Verifying  : zabbix-agent-3.2.11-1.el7.x86_64                         1/1

Installed:
  zabbix-agent.x86_64 0:3.2.11-1.el7

Complete!

修改配置文件

# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.31.145 主动
ServerActive=192.168.31.145 被动
Hostname=linux-server1
注意:其中192.168.31.145为Zabbix server地址

开启zabix_agent

[root@linux-server1 ~]# systemctl start zabbix-agent.service
[root@linux-server1 ~]# 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@linux-server1 ~]# netstat -lnupt | grep 10050
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      1444/zabbix_agentd
tcp6       0      0 :::10050                :::*                    LISTEN      1444/zabbix_agentd

测试Zabbix客户端与Zabbix服务端通信是否正常

以下指令在Zabbix server端执行

[root@zabbix-server ~]# yum install zabbix-get.x86_64 -y
Total download size: 241 k
Installed size: 972 k
Downloading packages:
zabbix-get-3.2.11-1.el7.x86_64.rpm                         | 241 kB   00:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : zabbix-get-3.2.11-1.el7.x86_64                               1/1
  Verifying  : zabbix-get-3.2.11-1.el7.x86_64                               1/1

Installed:
  zabbix-get.x86_64 0:3.2.11-1.el7

Complete!
[root@zabbix-server ~]# zabbix_get -s 192.168.31.145 -k system.uptime
794 #有数据显示说明通信正常

以下操作通过 zabiix web管理界面完成

在网页端创建主机项

配置,主机,创建主机

嵌套模板监控

配置,主机,d,模板

添加监控项

标签:zabbix,server,etc,zabbix3.2,3.2,监控,root,el7,搭建
来源: https://www.cnblogs.com/lulujunsir/p/zabbix32.html