xlfm22 发表于 2019-1-21 12:45:46

监控服务zabbix部署

  Zabbix是什么?

'zabbix'是基于web界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
'zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制让系统管理员快速定位并解决问题'

  Zabbix组成
1.zabbix server

通过SNMP、zabbix agent 、ping,
端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能
运行在linux\Ubuntu\Solaris\HP-UX\AIX\Free BSD\Open BSD\OS X等平台。
'与zabbix agent 配合,可以轮询zabbix agent 主动接收监视数据(agent方式),
也可以被动接收zabbix agent 发送的数据(trapping方式)。
支持SNMP(v1,v2)'
  2.zabbix agent

安装在被监视的目标服务器上,主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。

  zabbix特点

安装与配置简单,学习成本低
免费开源
自动发现服务器与网络设备
支持多语言(包括中文)
分布式监视以及web集中管理功能
email等通知功能
用户安全认证和柔软的授权方式

  zabbix配置文件

服务器配置文件(/usr/local/etc/zabbix_server.conf)
客户端配置文件(/usr/local/etc/zabbix_agentd.conf)
zabbix代理配置文件(/usr/local/etc/zabbix_proxy.conf)

  zabbix服务端安装

'安装依赖包'
# yum -y install net-snmp-devel libevent-devel
'下载zabbix'
# cd /usr/src/
#wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.12/zabbix-3.4.12.tar.gz

'解压'
# tar xf zabbix-3.4.12.tar.gz

'创建zabbix用户和组'
# groupadd -r zabbix
# useradd -r -g zabbix -M -s /sbin/nologin zabbix

'配置zabbix数据库'
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.08 sec) '创建zabbix并支持中文'
mysql> show databases;(查看存在哪些数据库)
+--------------------+
| Database         |
+--------------------+
| information_schema |
| mysql            |
| performance_schema |
| sys                |
| zabbix             |
+--------------------+
5 rows in set (0.11 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123!';   '授权zabbix用户在数据库本机上登录访问所有数据库'
Query OK, 0 rows affected, 2 warnings (0.11 sec)
mysql> grant all privileges on zabbix.* to zabbix@127.0.0.1 identified by 'zabbix123!';
Query OK, 0 rows affected, 1 warning (0.04 sec)
'注意:mysql服务进程启动时会读取mysql库中的所有授权表至内存中:
1.grant 或revoke等执行权限操作会保存与表中,mysql的服务进程会自动重读授权表,并更新至内存中
2.对于不能够或不能及时重读授权表的命令,可手动让mysql的服务进程重读授权表'
mysql> flush privileges;
Query OK, 0 rows affected (0.16 sec)
mysql> exit
Bye
# cd /usr/src/zabbix-3.4.12/database/mysql/
# ls
data.sqlimages.sqlschema.sql
# mysql -uzabbix -pzabbix123! zabbix--enable-agent \
> --with-mysql \
> --with-net-snmp \
> --with-libcurl \
> --with-libxml2
# make install

  zabbix服务端配置

# ls /usr/local/etc/
zabbix_agentd.conf    zabbix_server.conf
zabbix_agentd.conf.dzabbix_server.conf.d
# vim /usr/local/etc/zabbix_server.conf
'搜索/DBPassword'
### Option: DBPassword
#       Database password. Ignored for SQLite.
#       Comment this line if no password is used.
#
# Mandatory: no
# Default:
# DBPassword=
DBPassword=zabbix123!    '设置zabbix数据库连接密码'
'启动zabbix_server和zabbix_agentd'
# zabbix_server
# zabbix_agentd
# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port            
LISTEN      0      128   *:22                  *:*                  
LISTEN      0      100    127.0.0.1:25                  *:*                  
LISTEN      0      128   *:10050               *:*                  
LISTEN      0      128   *:10051               *:*                  
LISTEN      0      128    127.0.0.1:9000                *:*                  
LISTEN      0      128    :::80               :::*                  
LISTEN      0      128    :::22               :::*                  
LISTEN      0      100       ::1:25               :::*                  
LISTEN      0      80   :::3306               :::*                  

  zabbix服务端web界面安装与配置

'修改/etc/php.ini的配置并重启php-fpm'
# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpmdone
# cd /usr/src/zabbix-3.4.12/
# ls
aclocal.m4   configure   Makefile.am
AUTHORS      configure.acMakefile.in
bin            COPYING       man
build          database      misc
ChangeLog      depcomp       missing
compile      frontends   NEWS
conf         include       README
config.guess   INSTALL       sass
config.log   install-sh    src
config.statusm4            upgrades
config.sub   Makefile
# mkdir /usr/local/apache/htdocs/zabbix
# cp -a frontends/php/* /usr/local/apache/htdocs/zabbix/
# chown -R apache.apache /usr/local/apache/htdocs/

'配置apache虚拟主机,在/etc/httpd24/httpd.conf的配置文件的末尾添加如下内容:'

DocumentRoot "/usr/local/apache/htdocs/zabbix"
ServerName www.yaoxiaorong.com
ProxyRequests off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1

Options none
AllowOverride none
Require all granted


'设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php'
# chmod 777 /usr/local/apache/htdocs/zabbix/conf
# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwxrwx. 2 apache apache 81 Jul 30 19:41 /usr/local/apache/htdocs/zabbix/conf
'重启apache'
# apachectl -t
Syntax OK
# apachectl stop
# apachectl start
# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port            
LISTEN      0      128   *:80                  *:*                  
LISTEN      0      128   *:22                  *:*                  
LISTEN      0      100    127.0.0.1:25                  *:*                  
LISTEN      0      128   *:10050               *:*                  
LISTEN      0      128   *:10051               *:*                  
LISTEN      0      128    127.0.0.1:9000                *:*                  
LISTEN      0      128    :::22               :::*                  
LISTEN      0      100       ::1:25               :::*                  
LISTEN      0      80   :::3306               :::*                  

  安装zabbix web界面

'修改/etc/hosts文件,添加域名与IP的映射(windows在
C:\Windows\System32\drivers\etc下的hosts文件)
在浏览器上访问域名,本文设置的域名为www.yaoxiaorong.com,你也可以修改成你自己想命名的域名
恢复zabbix/conf目录的权限为755'

  在浏览器上访问域名进行安装:
如图一:
http://i2.运维网.com/images/blog/201808/21/a7baeed3fcb0b4cca458ec6130310703.png
然后一直下一步下一步,直到出现如下的内容,然后输入密码
http://i2.运维网.com/images/blog/201808/21/a1eeea0d5ae4430cbdcb33bda2deb383.png
直到出现这个步骤,输入用户名和密码(用户是admin,密码是zabbix)
http://i2.运维网.com/images/blog/201808/21/10e12fc47dc32a4c34211eb34f2ed183.png
最后成功的界面
http://i2.运维网.com/images/blog/201808/21/c1445c81a67ebe99010ebb6a6c77dce5.png



页: [1]
查看完整版本: 监控服务zabbix部署