zabbix监控管理工具
在介绍zabbix之前,先需要知道为什么需要监控,监控内容是什么。监控就是通过一系列的数据采集和分析,将处理的信息反馈给管理者,以便于管理者即时做出的管理操作,规避风险。监控内容主要分类有:
- 硬件----温度、电压、损坏等
- 系统----CPU、内存、硬盘、网卡流量、TCP连接数、进程数
- 应用----mysql、php、redis、ngnix等
- 日志----系统日志、服务日志、访问日志、错误日志等
- 安全----敏感文件
- API----可用性、接口请求、响应时间
- 业务----例如电商交易订单、注册用户数、活跃时间等
- 流量----客户访问的地理位置、页面访问量、页面访问时长等
一、zabbix概述
zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
二、zabbix的主要特点
安装与配置简单,学习成本低、支持多语言(包括中文)、免费开源、自动发现服务器与网络设备、分布式监视以及WEB集中管理功能、可以无agent监视、用户安全认证和柔软的授权方式、通过WEB界面设置或查看监视结果、email等通知功能
三、zabbix组件
- Zabbix server 是 Zabbix软件的核心组件,agent 向其报告可用性、系统完整性信息和统计信息。server也是存储所有配置信息、统计信息和操作信息的核心存储库。
- 数据库,所有配置信息以及 Zabbix 采集到的数据都被存储在数据库中。
- Zabbix proxy 可以代替 Zabbix server采集性能和可用性数据。Zabbix proxy在Zabbix的部署是可选部分;但是proxy的部署可以很好的分担单个Zabbix server的负载。
- Web 界面,为了从任何地方和任何平台轻松访问 Zabbix ,我们提供了基于 web 的界面。该界面是 Zabbix server 的一部分,通常(但不一定)和 Zabbix server 运行在同一台物理机器上。
- Zabbix agents 部署在被监控目标上,用于主动监控本地资源和应用程序,并将收集的数据发送给 Zabbix server。
四、环境准备及安装zabbix
- 硬件配置参考
- 测试虚拟机安装环境准备
#mysql安装
[root@localhost ~]# yum -y install yum-utils
[root@localhost ~]# rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
[root@localhost ~]# yum-config-manager --disable mysql80-community #取消安装新版
[root@localhost ~]# yum-config-manager --enable mysql57-community #设置安装以前版
[root@localhost ~]# yum install mysql-community-server #安装mysql
[root@localhost ~]# systemctl start mysqld #启动mysql
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log #获取密码
[root@localhost ~]# mysql -uroot -p
mysql> alter user 'root'@'localhost' identified by 'Zabbix2020!'; #登录mysql并重新设定密码
[root@localhost ~]# vi /etc/my.cnf #编辑mysql配置
[mysql]
socket = /tmp/mysql.sock
[mysqld]
user = mysql
port = 3306
datadir = /var/lib/mysql
socket = /tmp/mysql.sock
bind-address = 0.0.0.0
pid-file = /var/run/mysqld/mysqld.pid
character-set-server = utf8
collation-server = utf8_general_ci
log-error = /var/log/mysqld.log
max_connections = 1024
open_files_limit = 65535
innodb_buffer_pool_size = 512M
innodb_flush_log_at_trx_commit = 2
innodb_log_file_size = 256M
#安装zabbix
[root@localhost ~]# rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
[root@localhost ~]# yum install zabbix-server-mysql zabbix-web-mysql
#添加创建数据库
mysql> create database zabbix;
#数据库创建用户
mysql> CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'mypass';
mysql> GRANT ALL ON zabbix.* TO 'zabbix'@'localhost';
#导入表数据
[root@localhost ~]# cd /usr/share/doc/zabbix-server-mysql-4.0.16/
[root@localhost zabbix-server-mysql-4.0.16]# zcat create.sql.gz|mysql -uzabbix -p zabbix
#配置zabbix文件
[root@localhost ~]# vi /etc/zabbix/zabbix_server.conf
#添加设置好的数据库密码DBPassword=密码
#修改httpd的zabbix配置文件
[root@localhost ~]# vi /etc/httpd/conf.d/zabbix.conf
#修改时区php_value date.timezone Asua/Shanghai
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl start zabbix-server
[root-@localhost ~]# ps -ef |grep zabbix #启动后,查看zabbix有多个进程
[root@localhost ~]# tail /var/log/zabbix/zabbix_server.log #查看日志看启动是不是有问题
3.启动后,打开页面 ,按照提示进行配置
4.完成后,进行登录测试,默认用户admin,密码zabbix(可以在个人中心修改密码,语言设置)
五、源码安装
- 安装内容----Nginx;PHP;初始化数据库;Zabbix Server;Zabbix Web
#安装nginx
[root@localhost ~]# wget https://nginx.org/download/nginx-1.16.1.tar.gz
[root@localhost ~]# yum install gcc pcre-devel openssl-devel -y
[root@localhost ~]# groupadd nginx && useradd -g nginx nginx -s /bin/false
[root@localhost src]# tar -zxvf nginx-1.16.1.tar.gz
[root@localhost src]# cd nginx-1.16.1
[root@localhost src]# ./configure --prefix=/usr/local/nginx/ --user=nginx --group=nginx --with-http_sub_module --with-http_ssl_module
#./cnfigure --help 查看模块,根据需要配置添加需要模块
make && make install
#修改配置文件
[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf
user nginx; #修改用户
pid /var/run/nginx.pid; #修改PID
#添加systemctl管理
[root@localhost nginx-1.16.1]# vi /usr/lib/systemd/system/nginx.service
#编辑内容如下
[Unit]
Description=The nginx http and reerse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=ture
[Install]
WantedBy=multi-user.target
#安装PHP
[root@localhost src]# wget https://www.php.net/distributions/php-7.2.26.tar.gz
[root@localhost src]# tar -zxvf php-7.2.26.tar.gz
[root@localhost php-7.2.26]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --enable-opcache --with-mysql --with-mysqli --enable-session --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --enable-xmlwriter --enable-xmlreader --enable-xml --enable-sockets --enable-bcmath --with-gettext
[root@localhost php-7.2.26]# make
[root@localhost php-7.2.26]# make install
[root@localhost php-7.2.26]# cp php.ini-production /usr/local/php/etc/php.ini
[root@localhost php-7.2.26]# cp sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf
[root@localhost php-7.2.26]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
[root@localhost ~]# cd /usr/local/php/etc/
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# systemctl start php-fpm
#mysql安装
[root@localhost ~]# yum -y install yum-utils
[root@localhost ~]# rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
[root@localhost ~]# yum-config-manager --disable mysql80-community #取消安装新版
[root@localhost ~]# yum-config-manager --enable mysql57-community #设置安装以前版
[root@localhost ~]# yum install mysql-community-server #安装mysql
[root@localhost ~]# systemctl start mysqld #启动mysql
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log #获取密码
[root@localhost ~]# mysql -uroot -p
mysql> alter user 'root'@'localhost' identified by 'Zabbix2020!'; #登录mysql并重新设定密码
[root@localhost ~]# vi /etc/my.cnf #编辑mysql配置
[mysql]
socket = /tmp/mysql.sock
[mysqld]
user = mysql
port = 3306
datadir = /var/lib/mysql
socket = /tmp/mysql.sock
bind-address = 0.0.0.0
pid-file = /var/run/mysqld/mysqld.pid
character-set-server = utf8
collation-server = utf8_general_ci
log-error = /var/log/mysqld.log
max_connections = 1024
open_files_limit = 65535
innodb_buffer_pool_size = 512M
innodb_flush_log_at_trx_commit = 2
innodb_log_file_size = 256M
#添加创建数据库
mysql> create database zabbix;
#数据库创建用户
mysql> CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'mypass';
mysql> GRANT ALL ON zabbix.* TO 'zabbix'@'localhost';
[root@localhost src]# wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.17/zabbix-4.0.17.tar.gz
[root@localhost src]# tar -zxvf zabbix-4.0.17.tar.gz
#安装zabbix
[root@localhost ~]# yum install libxml2-devel libcurl-devel libevent-devel net-snmp-devel mysql-community-devel -y
[root@localhost ~]# groupadd zabbix
[root@localhost ~]# useradd -g zabbix zabbix -s /sbin/nologin
[root@localhost ~]# yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel -y
[root@localhost zabbix-4.0.17]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
[root@localhost zabbix-4.0.17]# make && make install
[root@localhost zabbix-4.0.17]# vi /usr/lib/systemd/system/zabbix-server.service
#编辑配置文件如下,zabbix_server进行systemctl管理
[Unit]
Description=Zabbix server
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0
[Install]
WantedBy=multi-user.target
#编辑配置文件如下,zabbix-agent进行systemctl管理
[Unit]
Description=Zabbix agentd
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-agentd
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0
[Install]
WantedBy=multi-use.target
#配置zabbix文件
[root@localhost ~]# vi /usr/local/zabbix/etc/zabbix_server.conf
#添加设置好的数据库密码DBPassword=密码
#导入数据
[root@localhost ~]# cd src/zabbix-4.0.17/database/mysql/
[root@localhost mysql]# mysql -uzabbix -p'Minioe@1' zabbix < schema.sql
[root@localhost mysql]# mysql -uzabbix -p'Minioe@1' zabbix < images.sql
[root@localhost mysql]# mysql -uzabbix -p'Minioe@1' zabbix < data.sql
#复制页面文件
[root@localhost src]# cp zabbix-4.0.17/frontends/php/* /usr/local/nginx/html/ -rf
#修改PHP配置
[root@localhost ~]# vi /usr/local/php/etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
mysqli.default_socket = /var/lib/mysql/mysql.sock
#修改nginx配置
[root@localhost ~]# /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.php index.html index.htm; #添加index.php
}
#取消注释并更改如下
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#开机自启动
[root@localhost ~]# systemctl enable zabbix_server
[root@localhost ~]# systemctl enable php-fpm
[root@localhost ~]# systemctl enable nginx