Linux下常用的系统监控软件有NagiosCactiZabbixMonit等,这些开源的软件,可以帮助我们更好的管理机器,在第一时间内发现,并警告系统维护人员。


    今天开始研究下Zabbix,使用Zabbix的目的,是为了能够更好的监控mysql数据库服务器,并且能够生成图形报表,虽然Nagios也能够生成图形报表,但没有Zabbix这么强大。

    首先,我们先来介绍下Zabblx


.Zabbix简介   


       zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
       zabbixzabbix server与可选组件zabbix agent两部门组成。
       zabbix server可以通过SNMPzabbix agentping,端口监视等方法提供对远程服务器/网络状态的监视。
       zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。


zabbix的主要特点:
          - 安装与配置简单,学习成本低 
          - 支持多语言(包括中文)
          - 免费开源
          - 自动发现服务器与网络设备
          - 分布式监视以及WEB集中管理功能
          - 可以无agent监视
          - 用户安全认证和柔软的授权方式
          - 通过WEB界面设置或查看监视结果
          - email等通知功能
         等等


Zabbix主要功能:
         - CPU负荷
         - 内存使用
         - 磁盘使用
         - 网络状况
         - 端口监视
         - 日志监视 

官方也提供了安装资料:http://www.zabbix.com/wiki/howto/monito


安装zabbix


yum install -y http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
yum install -y zabbix zabbix-server zabbix-server-mysql zabbix-agent zabbix-send zabbix-web zabbix-get zabbix-web-mysql trousers iksemel libssh2  mysql  net-snmp-devel net-snmp-libs net-snmp-perl net-snmp-utils net-snmp
hostnamectl set-hostname zabbix


添加zabbix用户和组

groupadd zabbix

useradd -g zabbix -s /sbin/nologin  -M zabbix


关闭防火墙
vim /etc/selinux/config 


SELINUX=disabled


setenforce 0
systemctl stop firewalld
systemctl disable firewalld


安装开发环境
yum groupinstall "Development Tools" -y


LAMP的安装
yum install -y mariadb-server mariadb mariadb-test mariadb-devel mysql-dev httpd php php-mysql gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xml  libxml2-devel mariadb-devel bzip2-devel
如果不使用本地的MySQL服务器 这里mariadb-server安装包可以不装


vim /etc/php.ini
;date.timezone = 
改成: 
date.timezone = Asia/Shanghai 


在远端Mysql服务器里添加zabbix数据库
mysql -uroot -pMyPassword -h 10.1.41.45

mysql>create database zabbix character set utf8 collate utf8_bin;

Query OK, 1 row affected (0.00 sec)


mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| wiki               |
| wordpress          |
| zabbix             |
+--------------------+
6 rows in set (0.00 sec)


mysql> grant all on zabbix.* to zabbix@'10.1.41.%' identified by 'MyPassword';
Query OK, 0 rows affected (0.00 sec)


mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


mysql> select user,host,password from mysql.user;
+-----------+-----------+-------------------------------------------+
| user      | host      | password                                  |
+-----------+-----------+-------------------------------------------+
| root      | localhost | *A21C3DFA28D74F74F7430D6B502AD58954959F0A |
| wiki      | 10.1.41.% | *A5DB2D927D6DF94DA5E1CE4B293AEAAB4D8304EA |
| root      | 127.0.0.1 |                                           |
| wordpress | 10.1.41.% | *C260A4F79FA905AF65142FFE0B9A14FE0E1519CC |
| zabbix    | 10.1.41.% | *A21C3DFA28D74F74F7430D6B502AD58954959F0A |
+-----------+-----------+-------------------------------------------+
5 rows in set (0.00 sec)


mysql> quit




导入zabbix数据库
gunzip /usr/share/doc/zabbix-server-mysql-3.2.3/create.sql.gz
mysql -uzabbix -pMyPassword -h10.1.41.45 zabbix < /usr/share/doc/zabbix-server-mysql-3.2.3/create.sql


启动httpd服务器
systemctl start httpd 
systemctl enable httpd


登陆到http://10.1.41.81/zabbix





更改初始密码


mysql -uzabbix -pMyPassword -h10.1.41.45
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| zabbix             |
+--------------------+
2 rows in set (0.00 sec)
mysql> use zabbix
Database changed
mysql> show tables;
+----------------------------+
| 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                |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| groups                     |
| history                    |
| history_log                |
| history_str                |
| history_text               |
| history_uint               |
| host_discovery             |
| host_inventory             |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| httpstep                   |
| httpstepitem               |
| httptest                   |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
| interface                  |
| interface_discovery        |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| items                      |
| items_applications         |
| 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_url         |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| task                       |
| task_close_problem         |
| timeperiods                |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
+----------------------------+
127 rows in set (0.00 sec)


mysql> desc users;
+----------------+---------------------+------+-----+---------+-------+
| Field          | Type                | Null | Key | Default | Extra |
+----------------+---------------------+------+-----+---------+-------+
| userid         | bigint(20) unsigned | NO   | PRI | NULL    |       |
| alias          | varchar(100)        | NO   | UNI |         |       |
| name           | varchar(100)        | NO   |     |         |       |
| surname        | varchar(100)        | NO   |     |         |       |
| passwd         | char(32)            | NO   |     |         |       |
| url            | varchar(255)        | NO   |     |         |       |
| autologin      | int(11)             | NO   |     | 0       |       |
| autologout     | int(11)             | NO   |     | 900     |       |
| lang           | varchar(5)          | NO   |     | en_GB   |       |
| refresh        | int(11)             | NO   |     | 30      |       |
| type           | int(11)             | NO   |     | 1       |       |
| theme          | varchar(128)        | NO   |     | default |       |
| attempt_failed | int(11)             | NO   |     | 0       |       |
| attempt_ip     | varchar(39)         | NO   |     |         |       |
| attempt_clock  | int(11)             | NO   |     | 0       |       |
| rows_per_page  | int(11)             | NO   |     | 50      |       |
+----------------+---------------------+------+-----+---------+-------+
16 rows in set (0.00 sec)


mysql> select userid,alias,name,passwd from zabbix.users;
+--------+-------+--------+----------------------------------+
| userid | alias | name   | passwd                           |
+--------+-------+--------+----------------------------------+
|      1 | Admin | Zabbix | 5fce1b3e34b520afeffb37ce08c7cd66 |
|      2 | guest |        | d41d8cd98f00b204e9800998ecf8427e |
+--------+-------+--------+----------------------------------+
2 rows in set (0.00 sec)



vim /etc/zabbix/zabbix_server.conf 


ListenPort=10051

DBHost=10.1.41.45   ###如果你的数据库是安装在本地的 可以保持为默认的localhost
DBName=zabbix

DBUser=zabbix

DBPassword=MyPassword


vim /etc/zabbix/zabbix_agentd.conf


Server=10.1.41.81

ListenIP=0.0.0.0

ServerActive=10.1.41.81

Hostname=zabbix


启动服务并让他们开机启动

systemctl start snmpd
systemctl enable snmpd
systemctl enable snmptrapd
systemctl start snmptrapd
systemctl enable zabbix-server
systemctl start zabbix-server
systemctl start zabbix-agent

systemctl enable zabbix-agent

这样zabbix server 就算完成了安装

改变web主页显示的zabbix server的地址(默认为localhost)

vim /etc/zabbix/web/zabbix.conf.php 






正常安装完zabbix后,登录后zabbix监控报错zabbix server is not running: the information displayed may not be current,


根据日志报错排查
cat /var/log/zabbix/zabbix_server.log 

zabbix进程查看
ps aux |grep zabbix 

查看监听zabbix server---------zabbix agent    10050---10051端口 
netstat -nplut |grep zabbix

登陆报错解决    zabbix server is running | No.

解决方法1

setsebool -P httpd_can_network_connect on   selinux 允许它通过httpd服务

关闭selinux

永久关闭vi /etc/selinux/config

#SELINUX=disabled

#SELINUXTYPE=targeted

临时关闭 setenforce 0  

关闭防火墙

永久关闭 chkconfig iptables off

临时生效 iptables -F

解决方法2

cd /etc/zabbix/web/

修改配置文件

vi zabbix.conf.php

修改lochlhost为 自己服务器的IP地址

修改$DB['SERVER']   = '192.168.30.6';

修改$ZBX_SERVER     = '192.168.30.6';

重启服务

service httpd restart

service zabbix-agent restart

service zabbix-server restart


Logo

更多推荐