linux搭建zabbix

zabbix简介

Zabbix是一个监控系统,它可以帮助我们实时检查设备的状态,比如服务器、网络设备等。当设备出现问题时,它会及时通知我们,让我们可以采取措施来解决。同时,它还可以把收集到的数据转化成图表和报告,让我们更直观地了解设备的运行情况

zabbix特性

数据采集:Zabbix Agent方式会定期收集设备的各种指标数据,比如CPU使用率、内存占用、网络流量等。这些数据会被Zabbix Server主动获取。

触发检测告警:Zabbix会根据我们事先设定的阈值和触发条件,对采集到的数据进行检测。如果某个指标超过了阈值或满足了触发条件,Zabbix会触发一个告警。Zabbix会根据事先设置的通知方式,比如邮件、短信等,通知相关的人员或团队。这样我们可以及时知道设备出现了问题。

数据存储:Zabbix将采集到的数据存储在数据库中

数据展示:Zabbix提供了丰富的可视化功能,可以将采集到的数据转化成各种图表和报表。这样我们可以直观地了解设备的运行状态和趋势

 zabbix结构

1. Zabbix Server
这是Zabbix的核心组件,负责接收Agent发送的数据,处理数据,触发告警等。
Server也可以主动向Agent请求获取需要的监控数据。
一个Zabbix安装实例可以包含一个或多个Zabbix Server,以提供高可用性和可扩展性。
2. Zabbix Agent
部署在被监控目标上,它负责定期收集本地的监控数据(如CPU、内存、磁盘使用情况等)并发送给Zabbix Server。
Agent也可以执行Server发送的命令(例如重启服务或执行脚本)。
3. Zabbix Proxy
是一个可选组件,常用于分布式监控环境中。
Proxy可以代替Server收集Agent发送的数据,然后再将数据转发给Server,这样可以减轻Server的负担并提高数据收集的效率。
4. Zabbix Web
这是Zabbix的用户界面,用户可以通过Web界面配置监控项、查看监控数据和接收告警等。
Web界面非常灵活,支持自定义仪表板、报表和告警设置。
5. Zabbix Database
用于存储所有的配置信息、监控数据和历史数据。
Zabbix支持多种数据库,如MySQL、PostgreSQL、Oracle等。
 

 安装zabbix

做之前需要关闭防火墙,selinux,设置时钟同步

做之前需要安装zabbix源

[root@zabbix-server ~]# ls
anaconda-ks.cfg  zabbix-release-7.0-2.el9.noarch.rpm
[root@zabbix-server ~]# rpm -Uvh zabbix-release-7.0-2.el9.noarch.rpm
warning: zabbix-release-7.0-2.el9.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID b5333005: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-7.0-2.el9         ################################# [100%]
[root@zabbix-server ~]#  ls /etc/yum.repos.d/
backup                    rocky-addons.repo      rocky-extras.repo      zabbix.repo
epel-cisco-openh264.repo  rocky-addons.repo.bak  rocky-extras.repo.bak   // zabbix源
epel.repo                 rocky-devel.repo       rocky.repo
epel-testing.repo         rocky-devel.repo.bak   rocky.repo.bak

///将zabbix的源换成阿里源/
[root@zabbix-server ~]# cat /etc/yum.repos.d/zabbix.repo 
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/7.0/rocky/9/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-B5333005

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/9/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-08EFA7DD
gpgcheck=1

[zabbix-sources]
name=Zabbix Official Repository source code - $basearch
baseurl=https://repo.zabbix.com/zabbix/7.0/rocky/9/SRPMS
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-B5333005
gpgcheck=1

在epel源前面添加一行

[root@zabbix-server ~]# vim /etc/yum.repos.d/epel.repo
[epel]
    // 中间的省略///
excludepkgs=zabbix*

安装 zabbix server、web前端、agent

yum install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent -y

安装数据库,yum -y install mariadb-server mariadb

 启动数据库服务,并初始化数据库

[root@zabbix-server ~]# systemctl  restart  mariadb
[root@zabbix-server ~]# systemctl  enable  mariadb
[root@zabbix-server ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] y
New password: 输入密码
Re-enter new password: 再次输入密码
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

配置数据库并导入,zabbix表数据

[root@zabbix-server ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.5.22-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.000 sec)

MariaDB [(none)]> create user zabbix@localhost identified by 'linux';
Query OK, 0 rows affected (0.001 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.000 sec)

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

MariaDB [(none)]> exit
Bye

导入数据库

[root@zabbix-server ~]# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix

 导入数据库构架后禁用,将log_bin_trust_function_creators选项

[root@zabbix-server ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.5.22-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 global log_bin_trust_function_creators = 0;        //设置为0
Query OK, 0 rows affected (0.000 sec)

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

MariaDB [(none)]> exit
Bye

配置zabbix服务并启动服务

[root@zabbix-server ~]# vim /etc/zabbix/zabbix_server.conf
ListenPort=10051 
DBHost=localhost 
DBName=zabbix 
DBUser=zabbix 
DBPassword=redhat              
DBSocket=/var/lib/mysql/mysql.sock 
ListenIP=0.0.0.0 

为zabbix前端配置php

编辑配置文件 /etc/nginx/conf.d/zabbix.conf 取消注释并设置“listen”和“server_name”指令

[root@zabbix-server ~]# vim /etc/nginx/conf.d/zabbix.conf
        listen          8080;
        server_name     example.com;

启动 zabbix-server zabbix-agent nginx php-fpm服务

[root@zabbix-server ~]# systemctl restart zabbix-server zabbix-agent nginx php-fpm
[root@zabbix-server ~]# systemctl enable zabbix-server zabbix-agent nginx php-fpm

使用浏览器访问http://192.168.100.10:8080/setup.php

 

解决支持中文

[root@zabbix-server ~]# yum -y install langpacks-zh_CN.noarch
[root@zabbix-server ~]# yum -y install glibc-common
[root@zabbix-server ~]# locale -a | grep zh_CN
zh_CN
zh_CN.gb18030
zh_CN.gbk
zh_CN.utf8

再次刷新浏览器,此时就支持中文了

 点击下一步,

检查是否都ok,再进行下一步

 /

 ///

 默认账号为Admin,密码为zabbix

此时打开会乱码

解决乱码 

1、找到windows下的简体 楷体 常规字体

C:\Windows\Fonts

2、将简体 楷体 常规字体文件复制出来

3、上传到Linux系统中的/usr/share/zabbix/assets/fonts

4、替换原先的字体文件即可

mv simkai.ttf graphfont.ttf

监控远程Linux服务器

[root@zabbix-agent ~]# yum -y install zabbix-agent

[root@zabbix-agent ~]# vim /etc/zabbix/zabbix_agentd.conf

Server=192.168.100.40                 zabbix服务器的IPagent被动监控(默认模式)

ServerActive=192.168.100.40           zabbix服务器的IPagent主动监控

Hostname=zabbix-agent                 zabbix服务器的主机名

systemctl restart zabbix-agent

systemctl enable zabbix-agent

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值