简介
- zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案
- zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题
zabbix由2部分构成,zabbix server与可选组件zabbix agent
zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Ubuntu,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上
zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集
zabbix server可以单独监视远程服务器的服务状态;同时也可以与zabbix agent配合,可以轮询zabbix agent主动接收监视数据(agent方式),同时还可被动接收zabbix agent发送的数据(trapping方式)
另外zabbix server还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用
zabbix的主要特点
安装与配置简单,学习成本低
支持多语言(包括中文)
免费开源
自动发现服务器与网络设备
分布式监视以及WEB集中管理功能
可以无agent监视
用户安全认证和柔软的授权方式
通过WEB界面设置或查看监视结果
email等通知功能
Zabbix主要功能:
CPU负荷
内存使用
磁盘使用
网络状况
端口监视
日志监视
实验前提
需要配置lamp
这里使用的centos8,mysql5.7源码,apache源码,php yum装
zabbix服务端安装
下载安装包
[root@host src]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.2/zabbix-5.2.6.tar.gz
下载依赖包
[root@host ~]# yum install curl-devel
[root@host ~]# yum install libxml2 libxml2-devel -y
[root@host ~]# yum -y install net-snmp-devel libevent-devel
解压
[root@host src]# tar xf zabbix-5.2.6.tar.gz
- 创建用户和组
[root@host src]# groupadd -r zabbix
[root@host src]# useradd -r -g zabbix -M -s /sbin/nologin zabbix
- 配置zabbix数据库
[root@host src]# mysql -uroot -pxialuo123!
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> create user 'zabbix'@'localhost' identified by 'zabbix123!';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all on *.* to 'zabbix'@'192.168.192.133' identified by'zabbix123!';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all privileges on zabbix .* to zabbix@192.168.149.133 identified by 'zabbix123!';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@host src]# cd zabbix-5.2.6/database/mysql/
[root@host mysql]# ls
data.sql double.sql images.sql Makefile.am Makefile.in schema.sql
[root@host mysql]# mysql -uzabbix -pzabbix123! zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@host mysql]# mysql -uzabbix -pzabbix123! zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@host mysql]# mysql -uzabbix -pzabbix123! zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
- 编译安装
[root@host ~]# cd /usr/src/zabbix-5.2.6
[root@host zabbix-5.2.6]# ./configure --enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2
[root@host zabbix-5.2.6]# make install
zabbix服务端配置
[root@host ~]# ls /usr/local/etc/
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d
修改服务端配置文件
修改数据库信息
[root@host ~]# vim /usr/local/etc/zabbix_server.conf
......
# Default:
DBPassword=zabbix123! 设置zabbix数据库连接密码
......
启动zabbix_server和zabbix_agentd
[root@host ~]# zabbix_server
[root@host ~]# zabbix_agentd
[root@host ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
zabbix web界面安装前配置
[root@host ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@host ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@host ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@host ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@host ~]# service php-fpm restart
Redirecting to /bin/systemctl restart php-fpm.service
[root@host ~]# cd /usr/src/zabbix-5.2.6/
[root@host zabbix-5.2.6]# ls
aclocal.m4 ChangeLog config.log configure.ac include Makefile misc sass
AUTHORS compile config.status COPYING INSTALL Makefile.am missing src
bin conf config.sub database install-sh Makefile.in NEWS ui
build config.guess configure depcomp m4 man README
[root@host ~]# cd /usr/src/zabbix-5.2.6/
[root@host zabbix-5.2.6]# ls
aclocal.m4 ChangeLog config.log configure.ac include Makefile misc sass
AUTHORS compile config.status COPYING INSTALL Makefile.am missing src
bin conf config.sub database install-sh Makefile.in NEWS ui
build config.guess configure depcomp m4 man README
[root@host ~]# cd /usr/src/zabbix-5.2.6/
[root@host zabbix-5.2.6]# cd /usr/local/apache/htdocs/
[root@host htdocs]# ls
index.html xialuo
[root@host htdocs]# mv xialuo/ zabbix
[root@host htdocs]# cd zabbix/
[root@host zabbix]# rm -rf *
[root@host zabbix]#cd /usr/src/zabbix-5.2.6/
[root@host zabbix-5.2.6]# cp -a ui/* /usr/local/apache/htdocs/zabbix/
[root@host zabbix-5.2.6]# chown -R apache.apache /usr/local/apache/htdocs
- 配置虚拟主机
[root@host htdocs]# vim /etc/httpd24/extra/vhosts.conf
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/zabbix"
ServerName www.xialuo.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
<Directory "/usr/local/apache/htdocs/zabbix">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
关闭防火墙
[root@host ~]# systemctl stop firewalld.service
[root@host ~]# setenforce 0
重启服务
[root@host htdocs]# apachectl restart
[root@host htdocs]# service php-fpm restart
Redirecting to /bin/systemctl restart php-fpm.service
[root@host htdocs]# service mysqld restart
Shutting down MySQL.... SUCCESS!
Starting MySQL. SUCCESS!
- 修改/usr/local/apache/htdocs/zabbix/conf的权限,这样才能自动生成数据库连接文件
[root@host ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
安装zabbix web界面
下一步
把/usr/local/apache/htdocs/zabbix/conf目录的权限修改回755
[root@host ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf