zabbix部署安装5.2

Posted #44

tags:

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

1.zabbix介绍

zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。

zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。

zabbix由2部分构成,zabbix server与可选组件zabbix agent

zabbix server可以通过SNMPzabbix agentping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在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)等配合使用。

2. zabbix特点

zabbix的主要特点:

安装与配置简单,学习成本低

支持多语言(包括中文)

免费开源

自动发现服务器与网络设备

分布式监视以及WEB集中管理功能

可以无agent监视

用户安全认证和柔软的授权方式

通过WEB界面设置或查看监视结果

email等通知功能

Zabbix主要功能:

CPU负荷

内存使用

磁盘使用

网络状况

端口监视

日志监视

3.部署zabbix

因为zabbix是用php语言开发的,所以必须先部署lamp架构,使其能够支持运行php网页

zabbix服务端安装

#安装依赖包
[root@localhost ~]# dnf -y install net-snmp-devel libevent-devel
#下载zabbix
[root@localhost ~]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.2/zabbix-5.2.6.tar.gz
#解压
[root@localhost ~]# tar xf zabbix-5.2.6.tar.gz 


#创建用户
[root@localhost zabbix-5.2.6]# useradd -r  -M -s /sbin/nologin zabbix

#配置数据库
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.04 sec)

mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.02 sec)
#创建用户
mysql> create user \'zabbix\'@\'localhost\' identified by \'<4564949a>\';
Query OK, 0 rows affected (0.02 sec)
#授权
mysql> grant all privileges on zabbix.* to \'zabbix\'@\'localhost\';
Query OK, 0 rows affected, 1 warning (0.01 sec)

[root@localhost ~]# cd zabbix-5.2.6/database/mysql/
[root@localhost mysql]# mysql -uzabbix -p\'<4564949a>\' zabbix < schema.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -p\'<4564949a>\' zabbix < images.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -p\'<4564949a>\' zabbix < data.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# 

安装编译zabbix

[root@localhost zabbix-5.2.6]# ./configure --enable-server \\
> --enable-agent \\
> --with-mysql \\
> --with-net-snmp \\
> --with-libcurl \\
> --with-libxml2

[root@localhost zabbix-5.2.6]# make install

 

服务端配置

#设置密码
[root@localhost zabbix-5.2.6]# vim /usr/local/etc/zabbix_server.conf
DBPassword=<4564949a>

启动

#启动
[root@localhost zabbix-5.2.6]# zabbix_server 
zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
#出现以上错误 配置软链接
[root@localhost zabbix-5.2.6]# ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64
然后[root@localhost zabbix-5.2.6]# zabbix_server 
[root@localhost zabbix-5.2.6]# zabbix_server 
[root@localhost zabbix-5.2.6]# ss -antl
State           Recv-Q          Send-Q                    Local Address:Port                      Peer Address:Port          
LISTEN          0               128                             0.0.0.0:22                             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               80                                    *:3306                                 *:*             
LISTEN          0               128                                   *:80                                   *:*             
LISTEN          0               128                                [::]:22                                [::]:*     

[root@localhost zabbix-5.2.6]# zabbix_agentd
[root@localhost zabbix-5.2.6]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
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 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*

web 界面配置

[root@localhost zabbix-4.0.3]# mkdir /usr/local/apache/htdocs/zabbix
[root@localhost zabbix-5.2.6]# cp -r ui/* /usr/local/apache/htdocs/zabbix/
[root@localhost zabbix-5.2.6]# chown -R apache.apache /usr/local/apache/htdocs/

#配置虚拟主机
[root@localhost zabbix-5.2.6]# vim /etc/httpd24/extra/vhosts.conf 
[root@localhost zabbix-5.2.6]# cat /etc/httpd24/extra/vhosts.conf 

<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/zabbix"
    ServerName www.Mariko.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
    <Directory "/usr/local/apache/htdocs/zabbix">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>  
 
#重启服务
[root@localhost zabbix-5.2.6]# apachectl restart
AH00558: httpd: Could not reliably determine the server\'s fully qualified domain name, using localhost.localdomain. Set the \'ServerName\' directive globally to suppress this message
[root@localhost zabbix-5.2.6]# ss -antl
State           Recv-Q          Send-Q                    Local Address:Port                      Peer Address:Port          
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               80                                    *:3306                                 *:*             
LISTEN          0               128                                   *:80                                   *:*             
LISTEN          0               128                                [::]:22                                [::]:*          

 

修改/etc/php.ini的配置并重启php-fpm

[root@localhost zabbix-5.2.6]# sed -ri \'s/(post_max_size =).*/\\1 16M/g\' /etc/php.ini
[root@localhost zabbix-5.2.6]# sed -ri \'s/(max_execution_time =).*/\\1 300/g\' /etc/php.ini
[root@localhost zabbix-5.2.6]# sed -ri \'s/(max_input_time =).*/\\1 300/g\' /etc/php.ini
[root@localhost zabbix-5.2.6]# sed -i \'/;date.timezone/a date.timezone = Asia/Shanghai\' /etc/php.ini
[root@localhost zabbix-5.2.6]# service php-fpm restart
Redirecting to /bin/systemctl restart php-fpm.service

 

 

 

 

 

 

设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php

[root@localhost ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf

[root@localhost zabbix]# setfacl -m u:zabbix:rwx conf
[root@localhost zabbix]# id daemon
uid=2(daemon) gid=2(daemon) groups=2(daemon)

[root@localhost zabbix]# ps -ef|grep httpd
root       49232       1  0 01:02 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon     59508   49232  0 06:24 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon     59509   49232  0 06:24 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon     59510   49232  0 06:24 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon     59511   49232  0 06:24 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon     59512   49232  0 06:24 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon     59513   49232  0 06:24 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon     59514   49232  0 06:24 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon     59515   49232  0 06:24 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon     59516   49232  0 06:24 ?        00:00:00 /usr/local/apache/bin/httpd -k start
root       59654   59457  0 06:49 pts/0    00:00:00 grep --color=auto httpd
[root@localhost zabbix]# chown -R daemon.daemon /usr/local/apache/htdocs/

授权ip

[root@localhost htdocs]# mysql -uroot -p<4564949a>
-bash: syntax error near unexpected token `newline\'
[root@localhost htdocs]# mysql -uroot -p4564949a
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 111
Server version: 5.7.33 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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> grant all on *.* to zabbix@\'192.168.59.131\' identified by \'<4564949a>\';  #本机ip
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


[root@localhost zabbix]# setfacl -b /usr/local/apache/htdocs/zabbix/conf
[root@localhost zabbix]# getfacl /usr/local/apache/htdocs/zabbix/conf
getfacl: Removing leading \'/\' from absolute path names
# file: usr/local/apache/htdocs/zabbix/conf
# owner: daemon
# group: daemon
user::rwx
group::r-x
other::rwx


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

最后吧权限改为
[root@localhost zabbix]# chmod 755 /usr/local/apache/htdocs/zabbix/conf

登录zabbix

zabbix默认登录用户名和密码:

用户:admin

密码:zabbix

 

 

 


 

以上是关于zabbix部署安装5.2的主要内容,如果未能解决你的问题,请参考以下文章

Zabbix实战之部署篇Zabbix客户端的安装部署方法

最全的zabbix部署(Serveragentproxy)

NH.A.0002__zabbix_lamp+zabbix_server源码编译安装_V2020.10.22

Zabbix监控平台安装部署

监控服务zabbix部署

zabbix监控之zabbix源码部署 (安装篇)