Zabbix 系统概述与部署(1)


title: Zabbix 系统概述与部署(1)
date: 2018-12-09 09:40:28
tags:php

  • Zabbix
    categories: Zabbix
    copyright: true
    ---

Zabbix是一个很是强大的监控系统,是企业级的软件,来监控IT基础设施的可用性和性能.它是一个可以快速搭建起来的开源的监控系统,Zabbix能监视各类网络参数,保证服务器系统的安全运营,并提供灵活的通知机制以让系统管理员快速定位解决存在的各类问题,Zabbix系统几乎可用于任何系统的监控过程,它能够运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X,等平台上.html



Zabbix 是什么?java

Zabbix 是一个高度集成的网络监控解决方案,能够提供企业级的开源分布式监控解决方案,由一个国外的团队持续维护更新,软件能够自由下载使用,运做团队靠提供收费的技术支持赢利.mysql

Zabbix能够对网络和服务进行监控,Zabbix利用灵活的告警机制,可实现微信、短信和邮件的自动报警.Zabbix利用存储的监控数据提供监控报告及实现图形化显示,linux

Zabbix支持polling和trapping两种方式,全部的Zabbix报告均可以经过配置参数在WEB界面进行访问,你能够经过Web界面实时查看网络和服务的监控情况,无论你是小型组织仍是大规模的公司.Zabbix均可以经过不通的配置来扮演监控你的IT基础框架的角色,Zabbix是零成本的,由于Zabbix编写和发布基于GPL V2协议,意味着源代码是免费发布的.web

经过YUM仓库安装

◆Zabbix服务端配置◆

1.在开始安装软件以前,须要配置yum源与zabbix源,这里咱们就使用163的YUM源吧.sql

[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# rpm -ivh http://repo.zabbix.com/zabbix/4.1/rhel/7/x86_64/zabbix-release-4.1-1.el7.noarch.rpm

2.因为Zabbix须要一个Web展示出页面来,因此在这里咱们须要自行安装一个LAMP或LNMP环境.数据库

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

Package 1:mariadb-5.5.60-1.el7_5.x86_64 already installed and latest version
Package 1:mariadb-server-5.5.60-1.el7_5.x86_64 already installed and latest version
Package httpd-2.4.6-88.el7.centos.x86_64 already installed and latest version
Package php-5.4.16-46.el7.x86_64 already installed and latest version
Package php-mysql-5.4.16-46.el7.x86_64 already installed and latest version
Nothing to do

3.接着安装Zabbix组件,这里因为是YUM安装因此直接执行yum install就搞定了.apache

[root@localhost ~]# yum install -y net-snmp zabbix-web zabbix-agent zabbix-server-mysql zabbix-web-mysql

Package 1:net-snmp-5.7.2-37.el7.x86_64 already installed and latest version
Package zabbix-web-4.2.0-0.1alpha1.el7.noarch already installed and latest version
Package zabbix-agent-4.2.0-0.1alpha1.el7.x86_64 already installed and latest version
Package zabbix-server-mysql-4.2.0-0.1alpha1.el7.x86_64 already installed and latest version
Package zabbix-web-mysql-4.2.0-0.1alpha1.el7.noarch already installed and latest version
Nothing to do

4.配置Zabbix表结构,建立MariaDB用户并用于Zabbix受权使用,并恢复Zabbix表结构.vim

[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl enable mariadb

[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
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;
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
MariaDB [(none)]> exit

[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pzabbix zabbix

5.将Zabbix的页面文件拷贝到指定目录(跟apache配置的相同便可).

[root@localhost ~]# cp -a /usr/share/zabbix/* /var/www/html/
[root@localhost ~]# chmod 755 -R /var/www/html/
[root@localhost ~]# chown apache.apache -R /var/www/html/*

[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl enable httpd

6.修改PHP配置文件,在PHP配置文件的末尾添加便可,主要目的是调整一下PHP参数,不然Zabbix不经过.

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

date.timezone = Asia/Shanghai
max_execution_time = 300
max_input_time = 300
post_max_size = 32M
memory_limit = 128M
mbstring.func_overload = 0

7.配置Zabbix Server端配置文件,主要目的是定义数据库的IP、用户名、密码等.

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

DBHost=localhost         #监控主机数据库IP,这里是本地
DBName=zabbix            #数据库名
DBUser=zabbix            #访问,数据库的用户名
DBPassword=zabbix        #访问,数据库访问密码

8.全部工做配置完成之后,启动一下Zabbix进程和Apache服务.

systemctl restart httpd
systemctl restart mariadb
systemctl restart zabbix-server
systemctl restart zabbix-agent

9.拓展环节:若是你的Zabbix登录密码忘记了,你可使用如下命令找回来.

MariaDB [(none)]> update zabbix.users set passwd=md5(123123) where name="Zabbix";

10.解决中文乱码问题,并登录系统看结果吧.

#在windows系统中:Win+R -> fonts -> 拷贝微软雅黑字体更名为 msyh.ttf

[root@localhost ~]# cp -a msyh.ttf /var/www/html/fonts//
[root@localhost ~]# vim /var/www/html/include/defines.inc.php

#修改 zabbix php 页面配置,将'DejaVuSans' 修改成 'msyh'

65 define('ZBX_GRAPH_FONT_NAME',           'msyh'); // font file name

[root@localhost ~]# systemctl restart httpd

用户名:Admin     密码:zabbix

◆监控一台Linux◆

1.在监控以前咱们首先要安装一个工具,就是Zabbix的客户端组件.

[RHEL6]
[root@localhost ~]# wget http://repo.zabbix.com/zabbix/4.1/rhel/6/x86_64/zabbix-agent-4.2.0-0.1alpha1.el6.x86_64.rpm
[root@localhost ~]# rpm -ivh zabbix-agent-4.2.0-0.1alpha1.el6.x86_64.rpm

[RHEL7]
[root@localhost ~]# wget http://repo.zabbix.com/zabbix/4.1/rhel/7/x86_64/zabbix-agent-4.2.0-0.1alpha1.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh zabbix-agent-4.2.0-0.1alpha1.el7.x86_64.rpm

2.编辑Zabbix客户端配置文件,指定Zabbix服务器的IP地址.

[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf     

Server=192.168.1.10                #填写Server的IP地址
ServerActive=192.168.1.10          #修改成Server的IP地址
Hostname=centos_01                 #填写本机的HostName

3.启动Zabbix客户端进程,并设置开机自启动.

[root@localhost ~]# systemctl restart zabbix-agent
[root@localhost ~]# systemctl enable zabbix-agent

[root@localhost ~]# /usr/sbin/zabbix_agentd

◆监控一台Windows◆

1.首先下载监控Windows的客户端组件,并修改一下配置文件.

https://assets.zabbix.com/downloads/3.4.6/zabbix_agents_3.4.6.win.zip
https://www.zabbix.com/downloads/4.0.0/zabbix_agents-4.0.0-win-amd64.zip

修改文件:zabbix_agentd.win.conf

Server=192.168.1.10                #填写Server的IP地址
ServerActive=192.168.1.10          #修改成Server的IP地址
Hostname=centos_01                 #填写本机的HostName

2.打开命令行,并启动相应服务便可.

zabbix_agentd.exe -c C:\zabbix\conf\zabbix_agentd.win.conf -i   #将进程添加到 windows 服务管理
zabbix_agentd.exe -c C:\zabbix\conf\zabbix_agentd.win.conf -s   #开启服务


经过源码编译安装

◆Zabbix服务端搭建◆

1.因为Zabbix是基于Web界面的,因此在编译安装Zabbix以前,咱们应该准备好一个LAMP或者LNMP的系统环境,来确保Zabbix可以经过Web展示出来.

[root@localhost ~]# yum install -y gcc httpd httpd-devel mariadb mariadb-server mariadb-devel php php-mysql php-common php-gd php-xml

Package gcc-4.8.5-36.el7.x86_64 already installed and latest version
Package httpd-2.4.6-88.el7.centos.x86_64 already installed and latest version
Package httpd-devel-2.4.6-88.el7.centos.x86_64 already installed and latest version
Package 1:mariadb-5.5.60-1.el7_5.x86_64 already installed and latest version
Package 1:mariadb-server-5.5.60-1.el7_5.x86_64 already installed and latest version
Package 1:mariadb-devel-5.5.60-1.el7_5.x86_64 already installed and latest version
Package php-5.4.16-46.el7.x86_64 already installed and latest version
Package php-mysql-5.4.16-46.el7.x86_64 already installed and latest version
Package php-common-5.4.16-46.el7.x86_64 already installed and latest version
Package php-gd-5.4.16-46.el7.x86_64 already installed and latest version
Package php-xml-5.4.16-46.el7.x86_64 already installed and latest version
Nothing to do

[root@localhost ~]# yum install -y libevent-devel php-bcmath php-common php-mbstring

Package libevent-devel-2.0.21-4.el7.x86_64 already installed and latest version
Package php-bcmath-5.4.16-46.el7.x86_64 already installed and latest version
Package php-common-5.4.16-46.el7.x86_64 already installed and latest version
Package php-mbstring-5.4.16-46.el7.x86_64 already installed and latest version
Nothing to do

2.接着咱们先来安装一下Zabbix编译所依赖的包文件,具体操做以下.

[root@localhost ~]# yum install -y net-snmp-devel curl curl-devel libxml2-devel libcurl-devel libevent libevent-devel

Package 1:net-snmp-devel-5.7.2-37.el7.x86_64 already installed and latest version
Package curl-7.29.0-51.el7.x86_64 already installed and latest version
Package libcurl-devel-7.29.0-51.el7.x86_64 already installed and latest version
Package libxml2-devel-2.9.1-6.el7_2.3.x86_64 already installed and latest version
Package libcurl-devel-7.29.0-51.el7.x86_64 already installed and latest version
Package libevent-2.0.21-4.el7.x86_64 already installed and latest version
Package libevent-devel-2.0.21-4.el7.x86_64 already installed and latest version
Nothing to do

3.继续,咱们经过wget命令下载一个Zabbix源码包,执行如下编译过程.

[root@localhost ~]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.2/zabbix-4.0.2.tar.gz

[root@localhost ~]# useradd -M -s /sbin/nologin zabbix
[root@localhost ~]# tar -xzvf zabbix-4.0.2.tar.gz
[root@localhost ~]# cd zabbix-4.0.2/

[root@localhost ~]# ./configure --prefix=/usr/local/zabbix --enable-server \
--enable-agent --with-mysql --enable-ipv6 --with-net-snmp \
--with-libcurl --with-libxml2 --enable-java

[root@localhost ~]# make && make install

4.配置Zabbix表结构,建立MariaDB用户并用于Zabbix受权使用,并恢复Zabbix表结构.

[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl enable mariadb

[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
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 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
MariaDB [(none)]> grant all on zabbix.* to zabbix@"%" identified by "zabbix";
MariaDB [(none)]> grant all on zabbix.* to zabbix@"localhost" identified by "zabbix";
MariaDB [(none)]> exit

[root@localhost ~]# cd /root/zabbix-4.0.2/database/mysql/
[root@localhost mysql]# mysql -uzabbix -pzabbix zabbix <schema.sql
[root@localhost mysql]# mysql -uzabbix -pzabbix zabbix <images.sql
[root@localhost mysql]# mysql -uzabbix -pzabbix zabbix <data.sql

5.将Zabbix的页面文件拷贝到指定目录(跟apache配置的相同便可).

[root@localhost ~]# cp -a /root/zabbix-4.0.2/frontends/php/* /var/www/html/
[root@localhost ~]# chown -R apache:apache /var/www/html/

[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl enable httpd

6.修改PHP配置文件,在PHP配置文件的末尾添加便可,主要目的是调整一下PHP参数,不然Zabbix不经过.

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

date.timezone = Asia/Shanghai
max_execution_time = 300
max_input_time = 300
post_max_size = 32M
memory_limit = 128M
mbstring.func_overload = 0

7.配置Zabbix Server端配置文件,主要目的是定义数据库的IP、用户名、密码等.

[root@localhost ~]# vim /usr/local/zabbix/etc/zabbix_server.conf

DBHost=localhost         #监控主机数据库IP,这里是本地
DBName=zabbix            #数据库名
DBUser=zabbix            #访问,数据库的用户名
DBPassword=zabbix        #访问,数据库访问密码

8.全部工做配置完成之后,启动一下Zabbix进程和Apache服务.

[root@localhost ~]# /usr/local/zabbix/sbin/zabbix_server 
[root@localhost ~]# echo "/usr/local/zabbix/sbin/zabbix_server" >> /etc/bashrc 
[root@localhost ~]# systemctl restart httpd

9.拓展环节:若是你的Zabbix登录密码忘记了,你可使用如下命令找回来.

MariaDB [(none)]> update zabbix.users set passwd=md5(123123) where name="Zabbix";

10.解决中文乱码问题,并登录系统看结果吧.

#在windows系统中:Win+R -> fonts -> 拷贝微软雅黑字体更名为 msyh.ttf

[root@localhost ~]# cp -a msyh.ttf /var/www/html/fonts//
[root@localhost ~]# vim /var/www/html/include/defines.inc.php

#修改 zabbix php 页面配置,将'DejaVuSans' 修改成 'msyh'

65 define('ZBX_GRAPH_FONT_NAME',           'msyh'); // font file name

[root@localhost ~]# systemctl restart httpd

用户名:Admin     密码:zabbix

◆Zabbix客户端配置◆

1.首先安装依赖和,编译环境.

[root@localhost ~]# yum install -y gcc pcre-devel pcre-static pcre-tools

2.编译安装Zabbix客户端监控程序,这里一样适用相同的压缩包.

[root@localhost ~]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.2/zabbix-4.0.2.tar.gz

[root@localhost ~]# useradd -M -s /sbin/nologin zabbix
[root@localhost ~]# tar -xzvf zabbix-4.0.2.tar.gz
[root@localhost ~]# cd zabbix-4.0.2/
[root@localhost ~]# ./configure --prefix=/usr/local/zabbix --sysconfdir=/etc/zabbix --enable-agent
[root@localhost ~]# make && make install

3.配置Zabbix-Agent端配置文件,修改主机列表.

[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf     

Server=192.168.22.195                   #填写Server的IP地址
ServerActive=192.168.22.195             #修改成Server的IP地址
Hostname=centos_1                       #填写本机的HostName

4.启动zabbix-agent端,并设置开机自启动.

[root@localhost ~]# /usr/local/zabbix/sbin/zabbix_agentd 
[root@localhost ~]# echo "/usr/local/zabbix/sbin/zabbix_agentd" >> /etc/bashrc
相关文章
相关标签/搜索