监控服务zabbix部署
zabbix介绍
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特点
zabbix的主要特点:
- 安装与配置简单,学习成本低
- 支持多语言(包括中文)
- 免费开源
- 自动发现服务器与网络设备
- 分布式监视以及WEB集中管理功能
- 可以无agent监视
- 用户安全认证和柔软的授权方式
- 通过WEB界面设置或查看监视结果
- email等通知功能
Zabbix主要功能:
- CPU负荷
- 内存使用
- 磁盘使用
- 网络状况
- 端口监视
- 日志监视
zabbix配置文件
zabbix配置文件有两种:
-
服务器端配置文件(/usr/local/etc/zabbix_server.conf)
-
客户端配置文件(/usr/local/etc/zabbix_agentd.conf)
-
zabbix代理配置文件(/usr/local/etc/zabbix_proxy.conf)
服务器端配置文件zabbix_server.conf常用配置参数:
参数 作用 LogFile 设置服务端日志文件存放路径 ListenIP 设置服务端监听IP ListenPort 设置服务端监听的端口号 PidFile 设置服务端进程号文件存放路径 DBHost 指定zabbix的数据库服务器IP DBName 指定zabbix使用的数据库库名 DBUser 指定zabbix数据库登录用户 DBPassword 指定zabbix数据库登录密码 DBPort 指定zabbix数据库端口号 User 设置zabbix以什么用户的身份运行 AlertScriptsPath 设置告警脚本存放路径 ExternalScripts 外部脚本存放路径 客户端配置文件zabbix_agentd.conf常用配置参数:
参数 作用 Server 指定zabbix服务器的IP或域名 ServerActive 指定zabbix服务器的IP或域名 Hostname 指定本机的主机名,此项必须与web界面配置项一致 UnsafeUserParameters 是否启用自定义监控项,可选值为{1 | 0} UserParameter 指定自定义监控脚本参数 LogFile 设置客户端日志文件存放路
部署zabbix
环境说明:
环境 | IP | 要安装的应用 |
---|---|---|
服务器 | 192.168.205.144 | lamp架构 zabbix server zabbix agent |
因为zabbix
是用php
语言开发的,所以必须先部署lamp
架构,使其能够支持运行php
网页
zabbix服务端安装
//安装依赖包
[root@localhost src]# yum -y install net-snmp-devel libevent-devel
//下载zbbbix
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
kernels zabbix-6.2.2.tar.gz
//解压
[root@localhost src]# tar xf zabbix-6.2.2.tar.gz
//创建zabbix用户和组
[root@localhost src]# useradd -r -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
[root@localhost src]# mkdir -p /usr/lib/zabbix
[root@localhost src]# chmod 770 /usr/lib/zabbix
[root@localhost src]# chown -R zabbix.zabbix /usr/lib/zabbix
//配置zabbix数据库
[root@localhost src]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.38 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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> create database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)
mysql> create user 'zabbix'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> SET GLOBAL log_bin_trust_function_creators = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
Bye
//数据导入数据库
[root@localhost src]# cd zabbix-6.2.2
[root@localhost zabbix-6.2.2]# ls
AUTHORS NEWS conf depcomp missing
COPYING README config.guess include sass
ChangeLog aclocal.m4 config.sub install-sh src
INSTALL bin configure m4 ui
Makefile.am build configure.ac man
Makefile.in compile database misc
[root@localhost zabbix-6.2.2]# cd database/
[root@localhost database]# ls
Makefile.am elasticsearch oracle sqlite3
Makefile.in mysql postgresql
[root@localhost database]# cd mysql/
[root@localhost mysql]# ls
Makefile.am data.sql history_pk_prepare.sql schema.sql
Makefile.in double.sql images.sql
[root@localhost mysql]# pwd
/usr/src/zabbix-6.2.2/database/mysql
[root@localhost mysql]# ll
total 35188
-rw-r--r--. 1 1000 1000 577 Aug 29 15:05 Makefile.am
-rw-r--r--. 1 1000 1000 16448 Aug 29 15:05 Makefile.in
-rw-r--r--. 1 1000 1000 33849146 Aug 29 15:05 data.sql
-rw-r--r--. 1 1000 1000 282 Jul 25 16:06 double.sql
-rw-r--r--. 1 1000 1000 1526 Aug 29 15:04 history_pk_prepare.sql
-rw-r--r--. 1 1000 1000 1978341 Jul 18 15:31 images.sql
-rw-r--r--. 1 1000 1000 170356 Aug 29 15:05 schema.sql
[root@localhost mysql]# mysql -uroot -p123456 zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uroot -p123456 zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uroot -p123456 zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.38 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| auditlog |
..................................................
| widget_field |
+----------------------------+
176 rows in set (0.00 sec)
//禁用 log_bin_trust_function_creators:
mysql> SET GLOBAL log_bin_trust_function_creators = 0;
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
Bye
//编译安装zabbix
[root@localhost mysql]# cd ..
[root@localhost database]# cd ..
[root@localhost zabbix-6.2.2]# pwd
/usr/src/zabbix-6.2.2
[root@localhost zabbix-6.2.2]# ls
AUTHORS NEWS conf depcomp missing
COPYING README config.guess include sass
ChangeLog aclocal.m4 config.sub install-sh src
INSTALL bin configure m4 ui
Makefile.am build configure.ac man
Makefile.in compile database misc
[root@localhost zabbix-6.2.2]# ./configure --enable-server --enable-agent --with-mysql --with-libcurl --with-libxml2
....................................
Configuration:
Detected OS: linux-gnu
Install path: /usr/local
Compilation arch: linux
Compiler: cc
Compiler flags: -g -O2
Library-specific flags:
database: -I/usr/local/mysql/include
libXML2: -I/usr/include/libxml2
Enable server: yes
Server details:
With database: MySQL
WEB Monitoring: cURL
SSL certificates: /usr/local/share/zabbix/ssl/certs
SSL keys: /usr/local/share/zabbix/ssl/keys
SNMP: no
IPMI: no
SSH: no
TLS: no
ODBC: no
Linker flags: -L/usr/local/mysql/lib -rdynamic
Libraries: -lmysqlclient -lpthread -lm -lrt -ldl -lxml2 -lz -lpthread -levent -lcurl -lm -ldl -lresolv -lpcre
Configuration file: /usr/local/etc/zabbix_server.conf
External scripts: /usr/local/share/zabbix/externalscripts
Alert scripts: /usr/local/share/zabbix/alertscripts
Modules: /usr/local/lib/modules
Enable proxy: no
Enable agent: yes
Agent details:
TLS: no
Modbus: no
Linker flags: -rdynamic
Libraries: -lz -lpthread -lcurl -lm -ldl -lresolv -lpcre
Configuration file: /usr/local/etc/zabbix_agentd.conf
Modules: /usr/local/lib/modules
Enable agent 2: no
Enable web service: no
Enable Java gateway: no
LDAP support: no
IPv6 support: no
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
//开始安装
[root@localhost zabbix-6.2.2]# make install
zabbix服务端配置
//配置数据库密码
[root@localhost zabbix-6.2.2]# cd /usr/local/etc/
[root@localhost etc]# ls
zabbix_agentd.conf zabbix_server.conf
zabbix_agentd.conf.d zabbix_server.conf.d
[root@localhost etc]# vim zabbix_server.conf
DBPassword=123456
//启动zabbix服务
[root@localhost etc]# zabbix_server
[root@localhost etc]# zabbix_agentd
[root@localhost etc]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
部署网站
//修改/etc/php.ini的配置并重启php-fpm
[root@localhost zabbix-6.2.2]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost zabbix-6.2.2]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost zabbix-6.2.2]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost zabbix-6.2.2]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost zabbix-6.2.2]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
//复制web页面文件
[root@localhost ~]# cd /usr/src/zabbix-6.2.2/
[root@localhost zabbix-6.2.2]# ls
AUTHORS NEWS config.guess depcomp sass
COPYING README config.log include src
ChangeLog aclocal.m4 config.status install-sh ui
INSTALL bin config.sub m4
Makefile build configure man
Makefile.am compile configure.ac misc
Makefile.in conf database missing
[root@localhost zabbix-6.2.2]# cp -a ui/* /usr/local/apache/htdocs/jiang/
cp: overwrite '/usr/local/apache/htdocs/jiang/index.php'? y
//修改属主和权限
[root@localhost zabbix-6.2.2]# ll /usr/local/apache/htdocs/
total 8
-rw-r--r--. 1 504 games 45 Jun 12 2007 index.html
drwxr-xr-x. 13 root root 4096 Sep 1 20:40 jiang
[root@localhost zabbix-6.2.2]# chown -R apache.apache /usr/local/apache/htdocs/jiang
[root@localhost zabbix-6.2.2]# chmod 777 /usr/local/apache/htdocs/jiang/conf/
[root@localhost zabbix-6.2.2]# ll /usr/local/apache/htdocs/
total 8
-rw-r--r--. 1 504 games 45 Jun 12 2007 index.html
drwxr-xr-x. 13 apache apache 4096 Sep 1 20:40 jiang
web页面安装
安装中文
[root@zabibix ~]# dnf reinstall glibc-common
[root@zabibix ~]# dnf -y install langpacks-zh_CN.noarch
检查是否出错
连接数据库
设置时区
确认信息
安装完成
恢复zabbix/conf目录的权限为755:
[root@localhost zabbix-6.2.2]# chmod 755 /usr/local/apache/htdocs/jiang/conf/
[root@localhost zabbix-6.2.2]# ll -d /usr/local/apache/htdocs/jiang/conf/
drwxr-xr-x. 3 apache apache 117 9月 1 21:19 /usr/local/apache/htdocs/jiang/conf/
登录zabbix
zabbix默认登录用户名和密码:
用户名 | 密码 |
---|---|
Admin | zabbix |
最后效果