监控服务zabbix部署

监控服务zabbix部署

zabbix介绍

常用的监控软件:

cacti							擅长画图,流量图

nagios 							擅长警告,配置较为麻烦

zabbix							结合cacti与nagios优点,有web界面,结合grafna

promethues  普罗米修斯            擅长监控容器

监控指标: 
   系统监控
      内存使用率
      硬盘使用率
      cpu使用率
   网络监控
      流量
      网卡
   硬件监控
      电源
      cpu温度
      硬盘温度
   业务监控
      进程
      日志

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)

部署lamp

环境说明:

因为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

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 wge
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]# 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

访问测试

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值