系统监控平台部署第一节----zabbix安装

Posted 有机天使

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了系统监控平台部署第一节----zabbix安装相关的知识,希望对你有一定的参考价值。

将Selinux关闭,确保是Disabled状态或警告模式

[root@localhost /]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

关闭操作系统防火墙

[root@localhost /]# systemctl stop firewalld
[root@localhost /]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

2.安装zabbix软件

下载镜像源

[root@localhost ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.2/rhel/8/x86_64/zabbix-release-5.2-1.el8.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/5.2/rhel/8/x86_64/zabbix-release-5.2-1.el8.noarch.rpm
warning: /var/tmp/rpm-tmp.pLxlpN: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-5.2-1.el8         ################################# [100%]
[root@localhost ~]# dnf clean all
21 files removed
[root@localhost ~]# dnf install zabbix-server-pgsql zabbix-web-pgsql zabbix-nginx-conf zabbix-agent

3.数据库postgresql安装

[root@localhost ~]# dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Last metadata expiration check: 0:02:31 ago on Wed 30 Dec 2020 04:30:58 PM CST.
pgdg-redhat-repo-latest.noarch.rpm                                                                                                                          10 kB/s |  11 kB     00:01    
Package pgdg-redhat-repo-42.0-14.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!  

PostgreSQL官方的yum源配置文件提供了PostgreSQL12/11/10/9.6/9.5共5个版本的配置信息,一般情况下我们只使用计划安装版本的配置信息,禁用不需要的配置信息可以提高下载速度。要安装12版,可以禁用11/10/9.6/9.5版的配置信息,以及禁用系统内置yum源的PostgreSQL安装模块
CentOS8的内置yum源中已经提供PostgreSQL安装模块(但比官方提供的版本要旧),而在执行安装命令时,内置yum源的优先级高于其他yum源,因此要禁用内置yum源的PostgreSQL安装模块。

root@localhost yum.repos.d]# dnf module list postgresql
Last metadata expiration check: 0:05:23 ago on Wed 30 Dec 2020 04:30:58 PM CST.
CentOS Linux 8 - AppStream
Name     Stream          Profiles                          Summary                                                        
postgresql    9.6        client, server [d]        PostgreSQL server and client module                            
postgresql   10 [d]      client, server [d]        PostgreSQL server and client module                            
postgresql    12        client, server [d]       ostgreSQL server and client module     

关闭内置的PostgreSQl

[root@localhost yum.repos.d]# dnf module disable postgresql
PostgreSQL common RPMs for RHEL/CentOS 8 - x86_64                                                                                                          2.6 kB/s | 3.0 kB     00:01  
PostgreSQL 13 for RHEL/CentOS 8 - x86_64                                                                                                                   3.4 kB/s | 3.8 kB     00:01    
PostgreSQL 12 for RHEL/CentOS 8 - x86_64                                                                                                                   3.4 kB/s | 3.8 kB     00:01    
PostgreSQL 11 for RHEL/CentOS 8 - x86_64                                                                                                                   3.5 kB/s | 3.8 kB     00:01    
PostgreSQL 9.6 for RHEL/CentOS 8 - x86_64                                                                                                                  3.4 kB/s | 3.8 kB     00:01    
PostgreSQL 9.5 for RHEL/CentOS 8 - x86_64                                                                                                                  3.4 kB/s | 3.8 kB     00:01    
Dependencies resolved.
==============================================================
 Package      Architecture            Version           Repository           Size
==============================================================
Disabling modules:
 postgresql                                                                                                                                              
Transaction Summary
==============================================================
Is this ok [y/N]: y
Complete!

root@localhost yum.repos.d]# dnf module list postgresql
Last metadata expiration check: 0:05:23 ago on Wed 30 Dec 2020 04:30:58 PM CST.
CentOS Linux 8 - AppStream
Name     Stream          Profiles                          Summary                                                        
postgresql    9.6        client, server [x]       PostgreSQL server and client module                            
postgresql   10 [d]      client, server [d] [x]       PostgreSQL server and client module                            
postgresql    12        client, server [x]       ostgreSQL server and client module  

[root@localhost yum.repos.d]# dnf install postgresql12-server

4.创建初始数据库

【注】由于红帽系列分发的策略,PostgreSQL 安装不会启用自动启动或自动
初始化数据库。所以必须先初始化数据库后再启动,否则会报错

[root@localhost yum.repos.d]# /usr/pgsql-12/bin/postgresql-12-setup initdb
Initializing database ... OK

启动数据库,并设置开机自启

[root@localhost yum.repos.d]# systemctl start postgresql-12.service
[root@localhost yum.repos.d]# systemctl enable postgresql-12
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-12.service → /usr/lib/systemd/system/postgresql-12.service.
[root@localhost yum.repos.d]# systemctl status  postgresql-12.service
● postgresql-12.service - PostgreSQL 12 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-12.service; disabled; vendor preset:>
   Active: active (running) since Wed 2020-12-30 17:32:45 CST; 16s ago
     Docs: https://www.postgresql.org/docs/12/static/
  Process: 4698 ExecStartPre=/usr/pgsql-12/bin/postgresql-12-check-db-dir ${PGDATA} (code=>
 Main PID: 4704 (postmaster)
    Tasks: 8 (limit: 49458)
   Memory: 18.5M
   CGroup: /system.slice/postgresql-12.service
           ├─4704 /usr/pgsql-12/bin/postmaster -D /var/lib/pgsql/12/data/
           ├─4705 postgres: logger   
           ├─4707 postgres: checkpointer   
           ├─4708 postgres: background writer   
           ├─4709 postgres: walwriter   
           ├─4710 postgres: autovacuum launcher   
           ├─4711 postgres: stats collector   
           └─4712 postgres: logical replication launcher   

createuser 创建一个新的 PostgreSQL 用户,并输入口令12345678

[root@localhost /]# sudo -u postgres createuser --pwprompt zabbix
Enter password for new role: 
Enter it again:

创建zabbix数据库(后),并指定所有者为zabbix(前)

[root@localhost /]# sudo -u postgres createdb -O zabbix zabbix

导入初始架构和数据,系统将提示您输入新创建的密码。

[root@localhost /]# zcat /usr/share/doc/zabbix-server-pgsql*/create.sql.gz | sudo -u zabbix psql zabbix

本地访问是md5验证方式,远程主机,任意ip访问,md5验证方式

[root@localhost /]# vim /var/lib/pgsql/12/data/pg_hba.conf
# IPv4 local connections:
host    all             all             0.0.0.0:0               md5
host    all             all             127.0.0.1/32            md5

重启数据库

[root@localhost /]# systemctl restart postgresql-12.service

验证数据库,检查是否可以联通

[postgres@localhost ~]$ psql -h 127.0.0.1 -U zabbix -p 5432 zabbix -W
Password: 
psql (12.5)
Type "help" for help.

zabbix=>

5.为Zabbix server配置数据库

编辑配置文件 /etc/zabbix/zabbix_server.conf

[root@localhost /]# vim /etc/zabbix/zabbix_server.conf
### Option: DBPassword/D
#       Database password.
#       Comment this line if no password is used.
#
# Mandatory: no
# Default:
# DBPassword=
DBPassword=123456
DBPort=5432  #默认也可以

6.为Zabbix前端配置php

编辑配置文件 /etc/nginx/conf.d/zabbix.conf,改端口和域名

[root@localhost /]# vim /etc/nginx/conf.d/zabbix.conf
server {
        listen         80;
        server_name     192.168.0.136;

7.启动Zabbix server和agent进程

启动Zabbix server和agent进程,并为它们设置开机自启:

[root@localhost ~]# systemctl restart zabbix-server zabbix-agent nginx php-fpm
[root@localhost ~]# systemctl enable zabbix-server zabbix-agent nginx php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-server.service → /usr/lib/systemd/system/zabbix-server.service.
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-agent.service → /usr/lib/systemd/system/zabbix-agent.service.
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.

四、配置zabbix前端

连接到新安装的Zabbix前端: http://server_ip_or_name



这里如果是localhost,会报错,改成127.0.0.1即可,详细解释参考文尾



这里可以选择界面颜色




五、服务端安装故障

1.无法连接数据库

1)故障现象

在配置过程中,出现如下两个错误

错误一:配置页面提示在“localhost:下无法连接数据库

错误二:Web端提示“zabbix server is not running


检查系统日志报错如下:

 [root@localhost ~]# cat /var/log/zabbix/zabbix_server.log
  1095:20210101:092732.077 [Z3001] connection to database \'zabbix\' failed: [0] FATAL:  Ident authentication failed for user "zabbix"3

通过localhost连接数据库,报错依旧

[root@localhost ~]# su - postgres 
[postgres@localhost ~]$ psql -h localhost -U zabbix -p 5432 zabbix -W
Password: 
psql: error: FATAL:  Ident authentication failed for user "zabbix"

2)解决方法

造成此类问题是由于Postgres在指定-h localhost时会使用IPv6的规则,
当指定-h 127.0.0.1时,它会强制Postgres使用IPv4规则,由于之前已经配置了在pg_hba.conf文件中配置了IPV4规则,所以用127.0.0.1是可以正常访问,如果要以localhost进行数据库连接,需要修改配置文件中的IPV6规则:

[root@localhost ~]# vim /var/lib/pgsql/12/data/pg_hba.conf
# IPv6 local connections:
host    all             all             ::1/128                 md5

注意:pg_hba.conf中的规则默认第一天记录优先,如果第一条记录验证失败,则不会考虑后续规则。

  • 在pg_hba.conf中添加了IPV6规则,即可解决上述故障
  • 或者不考虑localhost访问的,只用127.0.0.1的IP访问,则可以编辑zabbix配置文件,修改DBHost为数据库ip地址即可

    [root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
    DBHost=127.0.0.1

    2.Web页面乱码

    1)故障现象


    Web页面出现乱码

    2)解决方法

    在windows主机上,找到自己喜欢的中文字体:
    比如选择“新宋体”,将其拷贝至zabbix服务器“/usr/share/zabbix/assets/fonts”目录下

    [root@localhost fonts]# ls
    graphfont.ttf  simsun.ttc

    将字体名称修改为msyh.ttf

    [root@localhost fonts]# mv simsun.ttc msyh.ttf
    [root@localhost fonts]# ls
    graphfont.ttf  msyh.ttf

    修改zabbix配置文件,识别新字体

    [root@localhost fonts]# vim /usr/share/zabbix/include/defines.inc.php
    define(\'ZBX_GRAPH_FONT_NAME\',           \'msyh\'); // font file name
    define(\'ZBX_FONT_NAME\', \'msyh\');

    刷新页面,乱码显示正常:

    服务端安装过程完成,zabbix服务端配置完成

以上是关于系统监控平台部署第一节----zabbix安装的主要内容,如果未能解决你的问题,请参考以下文章

Security基础:部署Zabbix监控平台配置及使用Zabbix监控系统自定义Zabbix监控项目实现Zabbix报警功能

系统监控平台部署第二节--zabbix安装时序数据库和数据迁移

Zabbix实战之部署篇使用Docker部署Zabbix 6.2.7监控平台

Zabbix实战之部署篇Zabbix监控windows系统配置方法

Zabbix实战之部署篇Zabbix使用SNMP监控Linux系统

ubuntu16.04安装部署监控系统zabbix2.4