Linux部署zabbix

一、zabbix是一款优秀的监控软件,在部署zabbix之前,需要先查看环境,内存至少2G,确保内存足够,先将防火墙关闭(服务端配置如下)
[root@zknode1 ~]# getenforce
Disabled
[root@zknode1 ~]# systemctl  stop firewalld
 1.1获取zabbix的下载源
[root@zknode1 ~]# rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

 如上图所示成功

1.2更换zabbix.repo为在线源
[root@zknode1 ~]# cd /etc/yum.repos.d/
[root@zknode1 yum.repos.d]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' zabbix.repo
[root@zknode1 yum.repos.d]# yum clean all && yum makecache

如下图所示: 

 

 1.3下载zabbix相关组件
[root@zknode1 yum.repos.d]# yum install -y zabbix-server-mysql zabbix-agent

 

在这里可能会出现如下错误:

解决方案:

rpm -ivh mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm

 执行这条命令之后,在执行yum install -y zabbix-server-mysql zabbix-agent就可以正常安装部署了,如下图所示:

安装SCL(Software Collections),便于后续安装高版本的 php,默认 yum 安装的 php 版本为 5.4,版本过低,zabbix 5.0 版本对 php 版本最低要 7.2.0 版本。SCL 可以使得在同一台机器上使用多个版本的软件,而又不会影响整个系统的依赖环境。软件包会安装在 /opt/rh 目录下。

[root@zknode1 yum.repos.d]# yum install -y centos-release-scl

 

 1.4修改zabbix-front前端源,安装zabbix前端环境到scl环境
[root@zknode1 yum.repos.d]# vim zabbix.repo
  1. [zabbix-frontend]

  2. ##11行,开启安装源

  3. enabled=1

[root@zknode1 yum.repos.d]# yum install -y zabbix-web-mysql-scl zabbix-apache-conf-scl

这一步如果出现如图所示错误:

如果这一步报错出现Cannot find a valid baseurl for repo: centos-sclo-rh/x86_64

这是由于CentOS7的SCL源在2024年6月30日停止维护了。 当scl源里面默认使用了centos官方的地址,无法连接,需要替换为阿里云。

[root@zknode1 yum.repos.d]# cd /etc/yum.repos.d/
[root@zknode1 yum.repos.d]# mv CentOS-SCLo-scl.repo CentOS-SCLo-scl.repo.bak
[root@zknode1 yum.repos.d]# mv CentOS-SCLo-scl-rh.repo CentOS-SCLo-scl-rh.repo.bak[root@zknode1 yum.repos.d]# vim CentOS-SCLo-scl-rh.repo
添加以下内容
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/rh/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

 完成之后在执行命令;

1.5安装mariadb 
[root@zknode1 yum.repos.d]# yum install -y zabbix-web-mysql-scl zabbix-apache-conf-scl
[root@zknode1 yum.repos.d]# cd /opt/rh
[root@zknode1 rh]# ls
rh-php72
[root@zknode1 rh]# yum install -y mariadb-server mariadb

 然后启动

[root@zknode1 rh]# systemctl enable --now mariadb

 这个时候出现如果以下错误:

 此时去查看日志

[root@zknode1 ~]# tail -40f /var/log/messages

 如果日志出现以下内容就表示mariadb已经启动,继续下一步

 1.6初始化数据库并设置密码,按照机器提示操作
[root@zknode1 rh]# cd /etc/yum.repos.d/
[root@zknode1 yum.repos.d]# mysql_secure_installation
Securing the MySQL server deployment.

Enter password for user root: 

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 

Invalid option provided.

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Using existing password for root.

Estimated strength of the password: 50 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 
 1.7添加数据库用户,以及zabbix所需的数据库权限
[root@zknode1 yum.repos.d]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.25 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> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected, 2 warnings (0.00 sec)

mysql> CREATE USER 'zabbix'@'%' IDENTIFIED BY 'Zabbix123@';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'%';
Query OK, 0 rows affected (0.01 sec)

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

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| zabbix             |
+--------------------+
5 rows in set (0.01 sec)

mysql> use zabbix;
 1.8导入数据库信息
rpm -ql zabbix-server-mysql
[root@zknode1 ~]# find / | grep create.sql.gz  #这里结果就是下一条指令的/usr/share/doc/zabbix-server-mysql-5.0.43部分
[root@zknode1 yum.repos.d]# zcat /usr/share/doc/zabbix-server-mysql-5.0.43/create.sql.gz | mysql -uzabbix -pZabbix123@ zabbix

mysql> use zabbix;  //查看是否导入成功
1.9修改配置文件
[root@zknode1 yum.repos.d]# vim /etc/zabbix/zabbix_server.conf

##124行,取消注释,指定zabbix数据库的密码
DBPassword=Zabbix123@     #根据自己设置的密码填写
 1.9.1修改zabbix的php配置文件
[root@zknode1 yum.repos.d]# vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
[root@zknode1 yum.repos.d]# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm

 结果如下:

1.10启动浏览器访问

浏览器访问http://192.168.116.6/zabbix,这里的IP地址填写自己的IP地址

进入后点击下一步,如果全部OK就就继续下一步,并且设置密码:

设置密码后继续下一步,如果这里出现连接不上的情况:

这里可能是数据库导入/create.sql.gz 文件 失败,

find / | grep create.sql.gz
[root@zknode1 yum.repos.d]# zcat /usr/share/doc/zabbix-server-mysql-5.0.43/create.sql.gz | mysql -uzabbix -pZabbix123@ zabbix

 然后就可以了,继续下一步,检查相关信息有无错误,最后finish,安装完成后,默认的登录账号和密码为:Admin/zabbix,登入成功后就进入如下页面:

然后点击左边菜单栏的【User settings】,【Language】选择 Chinese(zh_CN),再点击 Update 更新,将语言修改为中文,这时候去查看图形发现会有很多乱码问题,解决方案如下:

[root@zknode1 yum.repos.d]# yum install -y wqy-microhei-fonts
[root@zknode1 yum.repos.d]# \cp -f /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf

然后刷新一下,如图所示:

 二、zabbix部署客户端

1.服务器配置

服务器IP地址主机名主要软件
zabbix-agent192.168.116.16zknode2zabbix-agent2
zabbix 5.0 版本采用 golang 语言开发的新版本客户端 agent2 
zabbix 服务端 zabbix_server 默认使用 10051 端口,客户端 zabbix_agent2 默认使用 10050 端口
1.配置服务端和客户端时间同步
[root@zknode1 ~]# yum install -y ntpdate
[root@zknode1 ~]# ntpdate -u ntp.aliyun.com
[root@zknode2 ~]# yum install -y ntpdate
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
软件包 ntpdate-4.2.6p5-29.el7.centos.2.x86_64 已安装并且是最新版本
无须任何处理
[root@zknode2 ~]# ntpdate -u ntp.aliyun.com
15 Aug 15:52:31 ntpdate[64427]: adjust time server 203.107.6.88 offset -0.002429 sec
2.配置客户端时区,要与服务器保持一致,我在这里采用的是上海时区
[root@zknode2 ~]# mv /etc/localtime{,.bak}
[root@zknode2 ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
3.设置zabbix下载源,下载zabbix-agent
[root@zknode2 ~]# rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

[root@zknode2 ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
[root@zknode2 ~]# yum install -y zabbix-agent2

如图所示:

 4.修改配置文件
[root@~]# vim /etc/zabbix/zabbix_agent2.conf
#80行,指定zabbix服务端的IP地址
Server=192.168.80.115
##120行,指定zabbix服务端的IP地址,这里的行不一定每个人都一样,根据自己的实际情况来
ServerActive=192.168.80.115
##136行,指定当前zabbix客户端的主机名
Hostname=zabbix_agent

 如下图所示:

 5.启动zabbix-agent2
[root@zknode2 ~]# systemctl enable --now zabbix-agent2.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent2.service to /usr/lib/systemd/system/zabbix-agent2.service.
[root@zknode2 ~]# netstat -natp | grep zabbix

成功就会如下图所示: 

6.在服务端验证zabbix-agent2的连通性
[root@zknode1 ~]# yum install -y zabbix-get

 如下图所示:

[root@zknode1 ~]# zabbix_get -s '192.168.116.16' -p 10050 -k 'agent.ping'
1
[root@zknode1 ~]# zabbix_get -s '192.168.116.16' -p 10050 -k 'system.hostname'
zknode2

第一条命令返回1表示成功,返回0表示失败,第二条命令会显示客户端主机名称

 7.在浏览器上添加agent主机
7.1在左侧菜单栏【配置】中的【主机】,右上角点击【创建主机】,如下图所示:

 7.2【主机名称】设置成 zknode2;【可见的名称】设置成 zknode2-192.168.116.16;

【群组】选择 Linux servers接口的【IP地址】设置成 192.168.116.16;再点击上方菜单栏【模板】,如下图所示:

 7.3在链接新模板搜索 Linux ,选择 Template OS Linux by Zabbix agent,点击添加

可以进入监测--主机查看各项监控,可以看到下方多了zknode2-192.168.116.16,可以点击查看相关监测情况

 查看情况如图所示:

  • 11
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

修乙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值