zabbix介绍

zabbix是一个基于WEB界面的分布式监控系统,zabbix能监控各种网络参数,保证服务器系统的安全运营,并提供灵活的通知机制,让系统管理员快手定位解决存在的各种问题,主要有监控CPU负载,内存使用、磁盘使用、网络状态、端口监视,日志监视、插件开发自定义等功能。

zabbix Server 通过SNMP、zabbix agent,ping、端口监视等方法提供对远程服务器/网络状态的监视,数据收集功能。可以在运行Linux 、Solaris、HP-UX、AIX、FreeBSD、OpenBSD、Windows等多平台运行。

常见商业功能:

  • 主机性能监控
  • 网络设备性能监控
  • 数据库性能监控
  • ftp等通用协议的监控
  • 能够利用灵活的可定制警告机制
  • 允许用户对事件发送基于 E-mail的警告,可以保证相关维护人员对问题做出快速响应
  • 可以利用存储数据提供杰出的报表及实时的图形化数据处理,实现对 Linux、 Windows主机的7×24小时集中监控
  • 监控的项目可包括CPU、内存、磁盘、网卡流量、服务可用性等各种资源。

其中组件:

zabbix_agent 安装在需要被监控的目标服务器上,主要完成对硬件信息与操作系统有关的内存,CPU、硬盘等信息的收集,功能十分强大。

zabbix_server 可以单独监视远程服务器的服务状态,同时也可以与zabbix_agent 结合,可以轮询zabbix Agent 主动接收监控数据,还可以被动接收zabbix_agent 发送的数据。

如图:

微信截图_20181028154920

 

环境介绍:

通过C/S模式采集数据

通过B/S模式在WEB端展示和配置

Agent 监控端口10050

服务端端口10051

以LNMP为监测环境  LNMP=Linux+Nginx+Mysql+PHP

 

环境表:

主机操作系统IP地址主要软件
Zabbix服务器Centos 7192.168.10.11Zabbix
客户机Centos 7192.168.10.12Zabbix

 

操作步骤:

LAMP环境部署

#Zabbix服务器 和客户机 关闭防火墙
systemctl stop firewalld.service
setenforce 0  #不关,Zabbix无法启动

 

安装nginx

获取安装源

wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enable=1

yum list
yum install nginx –y

http防火墙设置,关闭防火墙则无需此步骤。


firewall-cmd --permanent --add-service=http --zone=public
firewall-cmd –reload

开启nginx

systemctl start nginx
netstat -ntap | grep nginx       #查看端口

安装mariadb

yum install mariadb-server mariadb -y
systemctl start mariadb.service
systemctl enable mariadb.service
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      #创建新密码
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   #不删除匿名用户
... 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      #远程ROOT登陆
... 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    #删除测试数据库
... 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!

安装PHP

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql

编辑PHP配置文件

vim /etc/php-fpm.d/www.conf
8 user = nginx
10 group = nginx

vim /etc/php.ini
359 expose_php = Off      //隐藏php版本
202 short_open_tag = On   //支持php短标签
//以下为zabbix配置要求
368 max_execution_time = 300   //执行时间
378 max_input_time = 300   //接受数据等待时间
389 memory_limit = 128M    //每个脚本占用的内存设置
656 post_max_size = 16M    //post数据大小
799 upload_max_filesize = 2M  //下载文件大小
800 always_populate_raw_post_data = -1  //可用 $HTTP_RAW_POST_DATA 接受post raw data
878 date.timezone = Asia/shanghai  //时区设置上海

vim /etc/nginx/conf.d/default.conf
10         index  index.php index.html index.htm;  //添加PHP支持
  30     location ~ \.php$ {
31         root           /usr/share/nginx/html;
32         fastcgi_pass   127.0.0.1:9000;
33         fastcgi_index  index.php;
34         fastcgi_param  SCRIPT_FILENAME  $document_r    oot$fastcgi_script_name;
35         include        fastcgi_params;
36     }

开启php服务

systemctl start php-fpm.service
systemctl enable php-fpm.service
netstat -ntap | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      76012/php-fpm: mast
systemctl restart nginx

进入数据库给Zabbix创建提供数据库

mysql -uroot -p1
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on *.* to 'zabbix'@'%' identified by 'admin123';
flush privileges;

写入一个页面测试PHP是否能连接数据库

vim info.php
<?php
$link=mysqli_connect('127.0.0.1','root','1');
if($link) echo "true!";
else echo "Fail!!";
?>

成功:

 

微信截图_20181026150159

 

-----------如果出现无法登陆问题------------

select user,host from mysql.user;
看见有空用户,删除即解决
drop user ''@localhost;
drop user ''@cent;
再次检测

 

安装zabbix

rpm -i http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent –y

编辑配置文件

vim /etc/zabbix/zabbix_server.conf
91 DBHost=localhost
125 DBPassword=admin123

-----------防止出现zabbix页面乱码问题------------


vim /usr/share/zabbix/include/defines.inc.php
%s /graphfont/kaiti/g        //全局替换

https://pan.baidu.com/s/1f5XCKPMusD1weN6AfB2UYQ
把上面这个文件放到/usr/share/zabbix/fonts/下

给zabbix相关加权,不然后面开启zabbix会出现很多问题。

cp -r /usr/share/zabbix/ /usr/share/nginx/html/
chown -R zabbix:zabbix /etc/zabbix/
chown -R zabbix:zabbix /usr/share/nginx/
chown -R zabbix:zabbix /usr/lib/zabbix/
chmod -R 755 /etc/zabbix/web/
chmod -R 777 /var/lib/php/session/
zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -p zabbix

重启改动服务以及启动zabbix

systemctl stop php-fpm.service
systemctl stop nginx.service
systemctl start php-fpm.service
systemctl start nginx.service
systemctl start zabbix-server.service
systemctl start zabbix-agent.service
netstat -ntap | grep 10051

 

登陆 Zabbix 并配置
默认用户名和密码分别为  admin,zabbix
http://192.168.10.11/zabbix/

微信截图_20181025151215

 

--------------------安装过程中如果出现---------------------

 

微信截图_20181026154159

 

解决方法如下


cp /bao/zabbix.conf.php /etc/zabbix/web/
chown zabbix.zabbix /etc/zabbix/web/zabbix.conf.php

中文可以在网站设置里面调。

 微信截图_20181028171925

进去之后测试一下,我们添加一个SSH监控模块

微信截图_20181026155150

 

干掉这个SSH

systemctl stop sshd

等个十几秒,刷新一下这个页面

微信截图_20181026155228

 

至此就完成了zabbix的监控流程。