Zabbix基础1--Rocky9安装Zabbix-Grafana

安装Zabbix

安装MariaDB

这里用MariaDB演示
https://mariadb.org/download/?t=repo-config&d=Red+Hat+Enterprise+Linux+9&v=10.11&r_m=neusoft
通过这个网址获得连接

选择对应的repo

根据系统版本和要安装的版本选择对应的repo

安装

新建一个repo文件,例如/etc/yum.repos.d/MariaDB.repo, 然后把网站上提供的内容复制进去,例如

1
2
3
4
5
6
7
8
9
10
# MariaDB 10.11 RedHatEnterpriseLinux repository list - created 2024-02-29 09:14 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
# rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
# baseurl = https://rpm.mariadb.org/10.11/rhel/$releasever/$basearch
baseurl = https://mirrors.aliyun.com/mariadb/yum/10.11/rhel/$releasever/$basearch
# gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
gpgkey = https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1

然后就是安装步骤

1
2
3
4
5
6
7
8
sudo dnf install MariaDB-server

## 可选步骤,现在mariadb的命令不会自动绑定mysql命令了,所以你现在用mysql -uxxx -p之类的会跟你说命令不存在
sudo ln -s /usr/bin/mariadb /usr/bin/mysql

## 启动并设置自动启动
sudo systemctl start mysql
sudo systemctl enable mysql

至此,MariaD的安装就结束了

安装Zabbix Server

跟着这个网页的命令走,基本不会出什么问题
由于今天我们主要讲Rocky的安装,所以我们这么选
图片示例

接下来的步骤由于官网写的很详细,我就直接抄下来了,各位可以看一下

Install Zabbix repository

Disable Zabbix packages provided by EPEL, if you have it installed. Edit file /etc/yum.repos.d/epel.repo and add the following statement.

1
2
3
[epel]
...
excludepkgs=zabbix*

Proceed with installing zabbix repository.

1
2
# rpm -Uvh https://repo.zabbix.com/zabbix/7.0/rocky/9/x86_64/zabbix-release-latest-7.0.el9.noarch.rpm
# dnf clean all

Install Zabbix server, frontend, agent2

1
# dnf install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent2

Install Zabbix agent 2 plugins

You may want to install Zabbix agent 2 plugins.

1
# dnf install zabbix-agent2-plugin-mongodb zabbix-agent2-plugin-mssql zabbix-agent2-plugin-postgresql

Create initial database

Make sure you have database server up and running.

Run the following on your database host.

1
2
3
4
5
6
7
# mysql -uroot -p
password
mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> set global log_bin_trust_function_creators = 1;
mysql> quit;

On Zabbix server host import initial schema and data. You will be prompted to enter your newly created password.

1
# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix

Disable log_bin_trust_function_creators option after importing database schema.

1
2
3
4
# mysql -uroot -p
password
mysql> set global log_bin_trust_function_creators = 0;
mysql> quit;

Configure the database for Zabbix server

Edit file /etc/zabbix/zabbix_server.conf

1
DBPassword=password

Start Zabbix server and agent processes

Start Zabbix server and agent processes and make it start at system boot.

1
2
# systemctl restart zabbix-server zabbix-agent2 nginx php-fpm
# systemctl enable zabbix-server zabbix-agent2 nginx php-fpm

Open Zabbix UI web page

在Nginx的配置中,zabbix默认使用80端口,但是由于政策限制,其实我们不能使用,所以这边改成8090

1
2
3
4
5
6
7
8
9
vi /etc/nginx/conf.d/zabbix.conf

server {
## 把下面这两句的注释去掉,再修改一下端口
listen 8090;
server_name example.com;

## 重载一下nginx
systemctl reload nginx

然后就可以通过IP:8090 的形式访问到zabbix console了

安装Grafana

安装

直接进下面这个页面,可以看到这边可以选择版本以及操作系统
图片示例
并且如果是Linux平台的,下面会给出不同平台的命令,直接复制粘贴执行一下就可以了
图片示例

验证

运行命令

1
2
3
4
5
## 运行service
systemctl start grafana-server

## 自启动
systemctl enable grafana-server

之后浏览器访问IP:3000,就可以看到Grafana界面啦
默认账号密码为admin/admin,第一次登录会强制修改密码

其他

修改默认端口

1
2
3
4
vi /etc/grafana/grafana.ini

## 把这个3000修改成别的即可
;http_port = 3000

配置邮件服务

用于忘记密码等情况,可以不通知管理员自行修改密码