Zabbix 监控系统部署

Zabbix 监控系统部署

实验环境

Zabbix server:RHEL8
ip:192.168.121.10

一、关闭防火墙和selinux

[root@Zabbix-server ~]# systemctl stop firewalld
[root@Zabbix-server ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@Zabbix-server ~]# setenforce 0

二、Zabbix安装

  1. 下载安装 Zabbix 仓库
[root@Zabbix-server ~]# wget https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/8/x86_64/zabbix-release-4.0-2.el8.noarch.rpm
[root@Zabbix-server ~]# rpm -ivh zabbix-release-4.0-2.el8.noarch.rpm 
warning: zabbix-release-4.0-2.el8.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-4.0-2.el8         ################################# [100%]
  1. 更新 yum 仓库
[root@Zabbix-server ~]# yum repolist
repo id                                                              repo name
AppStream                                                            CentOS-8 - AppStream - mirrors.aliyun.com
base                                                                 CentOS-8 - Base - mirrors.aliyun.com
epel                                                                 Extra Packages for Enterprise Linux 8 - x86_64
epel-modular                                                         Extra Packages for Enterprise Linux Modular 8 - x86_64
extras                                                               CentOS-8 - Extras - mirrors.aliyun.com
zabbix                                                               Zabbix Official Repository - x86_64
zabbix-non-supported                                                 Zabbix Official Repository non-supported - x86_64
  1. 安装 Zabbix
[root@Zabbix-server ~]# yum install -y epel-release
[root@Zabbix-server ~]# yum install -y zabbix-agent zabbix-get zabbix-sender zabbix-server-mysql zabbix-web zabbix-web-mysql

三、安装数据库

  1. 安装 mariadb
[root@Zabbix-server ~]# yum install -y mariadb mariadb-server
  1. 修改配置文件 /etc/my.cnf.d/mariadb-server.cnf
在 [mysqld] 节点添加一下配置
[root@Zabbix-server ~]# vim /etc/my.cnf.d/mariadb-server.cnf 
 [mysqld]
skip_name_resolve = ON            #跳过主机名解析
innodb_file_per_tab1e = ON        #开启独立表空间
innodb_buffer_pool_size = 256M    #缓存池大小
max_connections = 2000            #最大连接数
log-bin = master-log              #开自二进制日志
innodb_strict_mode=0              #取消行大小限制(8126)
  1. 启动数据库服务
[root@Zabbix-server ~]# systemctl start mariadb
[root@Zabbix-server ~]# systemctl enable mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
  1. 设置数据库管理员密码
[root@Zabbix-server ~]# mysql_secure_installation    #mariadb初始化
或者
[root@Zabbix-server ~]# mysqladmin -u root password "123456"
  1. 创建 zabbixdb 数据库并授权
[root@Zabbix-server ~]# mysql -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 10
Server version: 10.3.17-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 zabbixdb character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> grant all on zabbixdb.* to "zabbixuser"@"192.168.121.%" identified by '123456';       #授权网段
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> grant all on zabbixdb.* to "zabbixuser"@"localhost" identified by '123456';           #授权本地
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

四、导入 Zabbix 服务表

  1. 解压 create.sql.gz
[root@Zabbix-server ~]# cp /usr/share/doc/zabbix-server-mysql/create.sql.gz .
[root@Zabbix-server ~]# gzip -d create.sql.gz 
  1. create.sql 文件顶行写如需要使用的数据库
[root@Zabbix-server ~]# vim create.sql 
[root@Zabbix-server ~]# head create.sql 
USE zabbixdb;        #添加使用刚刚创建的zabbixdb数据库
CREATE TABLE `users` (
	`userid`                 bigint unsigned                           NOT NULL,
	`alias`                  varchar(100)    DEFAULT ''                NOT NULL,
	`name`                   varchar(100)    DEFAULT ''                NOT NULL,
	`surname`                varchar(100)    DEFAULT ''                NOT NULL,
	`passwd`                 varchar(32)     DEFAULT ''                NOT NULL,
	`url`                    varchar(255)    DEFAULT ''                NOT NULL,
	`autologin`              integer         DEFAULT '0'               NOT NULL,
	`autologout`             varchar(32)     DEFAULT '15m'             NOT NULL,
  1. 导入表信息
[root@Zabbix-server ~]# mysql -uzabbixuser -p123456 < create.sql

五、配置 Server 端

  1. 修改配置文件
[root@Zabbix-server ~]# cd /etc/zabbix/
[root@Zabbix-server zabbix]# cp zabbix_server.conf{,.bak}
[root@Zabbix-server zabbix]# ls
web  zabbix_agentd.conf  zabbix_agentd.d  zabbix_server.conf  zabbix_server.conf.bak
[root@Zabbix-server zabbix]# vim zabbix_server.conf
ListenPort=10051             #默认监听端口
SourceIP=192.168.121.10      #数据请求IP(服务端IP)
  1. Zabbix 日志.
  • 默认用文件记录,也可以发送给我们的 rsyslog 日志记录系统,如果我们选择默认,则日志存放在
    LogFile=var/og/zabbix/zabbix_ server.log中,也可以自己设置。
  • 例如:
### Option: LogFile
#       Log file name for LogType 'file' parameter.
#
# Mandatory: yes, if LogType is set to file, otherwise no
# Default:
# LogFile=

LogFile=/var/log/zabbix/zabbix_server.log
  1. 日志的滚动
  • 默认值为1,表示滚动。我们设为0则表示不滚动。当数据特别多的时候,我们也可以设置成为1,然后在
    Maximum size of log file in MB 设置当数据文件最大到多少时会自动滚动。
  • 例如:
### Option: LogFileSize
#       Maximum size of log file in MB.
#       0 - disable automatic log rotation.
#
# Mandatory: no
# Range: 0-1024
# Default:
# LogFileSize=1

LogFileSize=0
  1. 日志的级别
  • 共有6个级别。 我们可以根据自己的需要来设置级别。其中0表示输出最少的信息,5表示输出最详细的信
    息,默认值为3,设置为3的话就表示,0、1、2. 3四个级别都显示。考虑到生产系统中的压力时,这里的信
    息,如果没有必要的话,越简单越好,只要在出错的时候,我们可以依据其进行排错即可。
  • 例如:
### Option: DebugLevel
#       Specifies debug level:
#       0 - basic information about starting and stopping of Zabbix processes
#       1 - critical information
#       2 - error information
#       3 - warnings
#       4 - for debugging (produces lots of information)
#       5 - extended debugging (produces even more information)
#
# Mandatory: no
# Range: 0-5
# Default:
# DebugLevel=3
  1. 数据库相关配置
  • /etc/zabbix/zabbix_server.conf 文件中修改一下参数
DBHost=192.168.121.10            #数据库对外的主机
DBName=zabbixdb                  #数据库名称
DBUser=zabbixuser                #数据库用户名
DBPassowrd=123456                #数据库密码
DBPort=3306                      #数据库启动端口号

六、启动服务

[root@Zabbix-server ~]# systemctl start zabbix-server
[root@Zabbix-server ~]# systemctl enable zabbix-server
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-server.service → /usr/lib/systemd/system/zabbix-server.service.

七、配置 web GUI

  1. /etc/httpd/conf.d/zabbix.conf 文件中修改如下配置
[root@Zabbix-server ~]# vim /etc/httpd/conf.d/zabbix.conf
<IfModule mod_php5.c>
php_value max_execution_time 300        #最大脚本执行时长
php_value memory_limit 128M             #内存大小
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value always_populate_raw_post_data -1
# php_value date.timezone Europe/Riga
php_value date.timezone Asia/Shanghai    #设置时区
</IfModule>

  1. 注意:
  • 时区是- -定要设置的,这里被注释掉是因为,在php的配置文件中设置时区,如果在php配置文件中设置
    时区,则对所有的php服务均有效,如果在 zabbix.conf 中设置时区,则仅对 zabbix 服务有效;所以,在php配
    文件中设置时区:
[root@Zabbix-server ~]# vim /etc/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Shanghai

八、启动 httpd 服务

[root@Zabbix-server ~]# systemctl start httpd
[root@Zabbix-server ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

九、浏览器访问并初始化设置

原文地址:https://www.cnblogs.com/itwangqiang/p/14156304.html