监控服务zabbix部署
一、介绍
zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位及解决存在的各种问题。
zabbix由两部分组成:
- zabbix server
- zabbix agent
二、特点
zabbix主要特点:
- 安装配置简单
- 支持多语言并且开源
- 自动发现服务器与网络设备
- 分布式监视以及web集中管理功能
- 可无agent监视
- 可通过web界面设置或者查看监视结果
zabbix监控指标:
- 系统监控
- 内存使用率
- 硬盘使用率
- CPU使用率
- 网络监控
- 流量
- 网卡
- 硬件监控 IPMI
- 电源
- CPU温度
- 业务监控
- 进程
- 日志
三、部署zabbix
环境说明:
因为zabbix使用php语言开发的,所以要求环境必须有lamp架构,使其能够支持运行php网页。
版本:6.2
1. 部署lamp
1.1 配置yum源
//进入目录添加yum源仓库
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- 0 0 0 0 0 0 0 0 --:--:-- --:--:-- 100 2495 100 2495 0 0 5788 0 --:--:-- --:--:-- --:--:-- 5775
[root@localhost yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
//清除建立缓存
[root@localhost yum.repos.d]# dnf clean all
Failed to set locale, defaulting to C.UTF-8
Repository AppStream is listed more than once in the configuration
13 files removed
[root@localhost yum.repos.d]# dnf makecache
Failed to set locale, defaulting to C.UTF-8
Repository AppStream is listed more than once in the configuration
CentOS-8.5.2111 - Base - mirror 513 kB/s | 4.6 MB 00:09
CentOS-8.5.2111 - Extras - mirr 34 kB/s | 10 kB 00:00
CentOS-8.5.2111 - AppStream - m 415 kB/s | 8.4 MB 00:20
baseos 41 MB/s | 2.5 MB 00:00
Metadata cache created.
1.2 安装服务
//安装httpd
[root@localhost ~]# dnf install -y httpd
//安装mysql
[root@localhost ~]# dnf -y module install mariadb:10.5
//安装php
[root@localhost ~]# dnf -y module install php:7.4
1.3 配置apache
//配置虚拟主机文件
[root@localhost ~]# cp /usr/share/doc/httpd/httpd-vhosts.conf /etc/httpd/conf.d/
[root@localhost ~]# vim /etc/httpd/conf.d/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/var/www/html/zabbix.example.com"
ServerName zabbix.example.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/zabbix.example.com/$1
<Directory "/var/www/html/zabbix.example.com">
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog "/var/log/httpd/zabbix.example.com-error_log"
CustomLog "/var/log/httpd/zabbix.example.com-access_log" common
</VirtualHost>
//修改httpd主配置文件
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
167 DirectoryIndex index.php index.html //在中间添加index.php
288 AddType application/x-httpd-php .php
289 AddType application/x-httpd-php-source .phps //添加此两行配置
//配置html网页文件
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# mkdir zabbix.example.com
[root@localhost html]# ls
zabbix.example.com
[root@localhost html]# cd zabbix.example.com/
[root@localhost zabbix.example.com]# vim index.php
<?php
phpinfo();
?>
[root@localhost zabbix.example.com]# cd
[root@localhost ~]#
//设置开机自启动
[root@localhost ~]# systemctl enable --now httpd
[root@localhost ~]# systemctl enable --now mariadb
[root@localhost ~]# systemctl enable --now php-fpm
//修改数据库密码
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.9-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> set password = password ('123com');
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> quit
Bye
//修改php-fpm.d配置文件
[root@localhost ~]# vim /etc/php-fpm.d/www.conf
38 listen = 0.0.0.0:9000 //修改此行
//重启php
[root@localhost ~]# systemctl restart php-fpm
//查看端口是否监听
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
[root@localhost ~]#
1.4 关闭防火墙
[root@localhost ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
1.5 访问网页
2. 部署zabbix
2.1 安装依赖包
[root@localhost ~]# dnf install -y net-snmp-devel libevent-devel gcc gcc-c++ make libxml2-devel libcurl-devel pcre-devel openssl openssl-devel mysql-devel php-bcmath php-gd php-mysqlnd wget
2.2 下载zabbix 6.2包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.2/zabbix-6.2.2.tar.gz
2.3 解压
[root@localhost src]# tar xf zabbix-6.2.2.tar.gz
2.4 创建用户
[root@localhost src]# useradd -r -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
2.5 创建目录并改权限
[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
2.6 配置数据库
[root@localhost src]# mysql -uroot -p123com
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.5.9-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.002 sec)
MariaDB [(none)]> create user 'zabbix'@'localhost' identified by 'zabbix123!';
Query OK, 0 rows affected (0.002 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> SET GLOBAL log_bin_trust_function_creators = 1;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> quit
Bye
[root@localhost src]#
//导入表文件
[root@localhost src]# cd zabbix-6.2.2/database/mysql/
[root@localhost mysql]# mysql -uroot -p123com zabbix < schema.sql
[root@localhost mysql]# mysql -uroot -p123com zabbix < images.sql
[root@localhost mysql]# mysql -uroot -p123com zabbix < data.sql
//测试看是否可以登录到zabbix
[root@localhost mysql]# mysql -uroot -p123com
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.5.9-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
2.7 编译安装
[root@localhost mysql]# cd
[root@localhost ~]# cd /usr/src/zabbix-6.2.2
[root@localhost zabbix-6.2.2]# ./configure --enable-server --enable-agent --with-mysql --with-libcurl --with-libxml2
······
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
[root@localhost zabbix-6.2.2]# make install
2.8 添加配置文件
[root@localhost zabbix-6.2.2]# cd /usr/local/etc/
[root@localhost etc]# vim zabbix_server.conf
124 DBPassword=zabbix123!
2.9 启动
[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:Port Process
LISTEN 0 128 0.0.0.0:22 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 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
2.10 部署web界面
[root@localhost etc]# cd
[root@localhost ~]# cd /usr/src/zabbix-6.2.2
[root@localhost zabbix-6.2.2]# cp -a ui/* /var/www/html/zabbix.example.com/
cp: overwrite '/var/www/html/zabbix.example.com/index.php'? y
[root@localhost zabbix-6.2.2]# chown -R apache.apache /var/www/html
2.11 设置参数
[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]# systemctl restart php-fpm
2.12 访问测试
输入IP进行访问
输入zabbix密码
登录zabbix
zabbix默认登录用户名和密码:
用户名 | 密码 |
---|---|
Admin | zabbix |
登录成功