Linux云计算架构-部署Zabbix企业级监控系统5.0

偏执的太偏执、 2022-12-30 08:23 322阅读 0赞

文章目录

  • Linux云计算架构-部署Zabbix企业级监控系统5.0
      1. Zabbix5.0简介
      1. 环境配置
      1. 安装zabbix server
      1. 配置zabbix web界面
      1. 设置中文界面和修复乱码
      1. 监控远程主机
      1. 安装grafana可视化界面
      1. 添加zabbix数据源
      1. Dashboard设计(待设计)
    • 附件1:zabbix.repo

Linux云计算架构-部署Zabbix企业级监控系统5.0

1. Zabbix5.0简介

Zabbix是一款开源免费的服务器监控管理软件,其功能强大、配置简单、可外接Grafana图形可视化,是企业运维监控软件的首选。

zabbix 5.0 版本于 5 月 11 日正式发布,是最新的 LTS(长期支持)版本,5.0 带来很多功能和特性,详细见官方文档。

2. 环境配置

  1. # 系统版本
  2. [root@server ~]# cat /etc/redhat-release
  3. CentOS Linux release 7.6.1810 (Core)
  4. # 关闭并禁用防火墙,禁用selinux
  5. [root@server ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
  6. [root@server ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
  7. [root@server ~]# systemctl stop firewalld.service && systemctl disable firewalld.service
  8. [root@server ~]# setenforce 0
  9. [root@server ~]# getenforce
  10. Permissive
  11. # 配置zabbix的yum源
  12. [root@server ~]# wget https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
  13. [root@server ~]# rpm -ivh zabbix-release-5.0-1.el7.noarch.rpm
  14. [root@server ~]# cd /etc/yum.repos.d/
  15. [root@server yum.repos.d]# ll
  16. 总用量 12
  17. -rw-r--r--. 1 root root 2523 6 16 2018 Centos-7.repo
  18. -rw-r--r--. 1 root root 664 5 11 2018 epel-7.repo
  19. -rw-r--r--. 1 root root 853 5 11 2020 zabbix.repo
  20. [root@server ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
  21. [root@server ~]# yum clean all
  22. [root@server ~]# yum makecache

3. 安装zabbix server

  1. [root@server ~]# yum install zabbix-server-mysql zabbix-agent -y
  2. [root@server ~]# yum install centos-release-scl -y
  3. [root@server ~]# yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y 【要启用zabbix.repo的某个源才可以安装】
  4. [root@server ~]# yum install mariadb-server -y
  5. # zabbix-server-mysql zabbix-agent zabbix服务端和客户端
  6. # centos-release-scl 用于安装高版本的php
  7. # zabbix-web-mysql-scl zabbix-apache-conf-scl zabbix的前端web界面
  8. # mariadb-server mariadb数据库
  9. # 配置mariadb数据库
  10. [root@server ~]# systemctl start mariadb
  11. [root@server ~]# systemctl enable mariadb
  12. [root@server ~]# mysql_secure_installation
  13. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
  14. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  15. 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
  16. you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set 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] y ... Success! 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
  17. installation should now be secure.
  18. Thanks for using MariaDB!
  19. # 创建zabbix数据库和zabbix用户
  20. [root@server ~]# mysql -uroot -p123456
  21. Welcome to the MariaDB monitor. Commands end with ; or \g.
  22. Your MariaDB connection id is 10
  23. Server version: 5.5.68-MariaDB MariaDB Server
  24. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  25. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  26. MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
  27. Query OK, 1 row affected (0.00 sec)
  28. MariaDB [(none)]> create user zabbix@localhost identified by '123456';
  29. MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
  30. Query OK, 0 rows affected (0.00 sec)
  31. MariaDB [(none)]> flush privileges;
  32. Query OK, 0 rows affected (0.00 sec)
  33. MariaDB [(none)]> exit
  34. Bye
  35. # 导入zabbix的数据
  36. [root@server ~]# ll /usr/share/doc/zabbix-server-mysql-5.0.7/create.sql.gz
  37. -rw-r--r--. 1 root root 1644549 12 21 18:24 /usr/share/doc/zabbix-server-mysql-5.0.7/create.sql.gz
  38. [root@server ~]# zcat /usr/share/doc/zabbix-server-mysql-5.0.7/create.sql.gz | mysql -uzabbix -p zabbix
  39. Enter password: 123456

修改配置文件:

  1. [root@server ~]# vim /etc/zabbix/zabbix_server.conf
  2. 124 DBPassword=123456
  3. [root@server ~]# vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
  4. 24 php_value[date.timezone] = Asia/Shanghai
  5. # 启动并加入到开机自启
  6. [root@server ~]# systemctl start zabbix-server zabbix-agent httpd rh-php72-php-fpm
  7. [root@server ~]# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm

4. 配置zabbix web界面

输入网址http://192.168.80.165/zabbix/setup.php

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

初始账号密码Admin/zabbix

5. 设置中文界面和修复乱码

①设置中文界面

在这里插入图片描述

在这里插入图片描述

②修复中文字体乱码

在这里插入图片描述

  1. # 上传字体文件,然后替换配置文件中字体配置
  2. [root@server ~]# cd /usr/share/zabbix/assets/fonts/
  3. [root@server fonts]# ll
  4. 总用量 0
  5. lrwxrwxrwx. 1 root root 33 12 23 10:11 graphfont.ttf -> /etc/alternatives/zabbix-web-font
  6. [root@server fonts]# rz
  7. [root@server fonts]# ll
  8. 总用量 11512
  9. lrwxrwxrwx. 1 root root 33 12 23 10:11 graphfont.ttf -> /etc/alternatives/zabbix-web-font
  10. -rw-r--r--. 1 root root 11787328 3 2 2019 simkai.ttf
  11. [root@server fonts]# vim /usr/share/zabbix/include/defines.inc.php
  12. 81 define('ZBX_GRAPH_FONT_NAME', 'simkai'); // font file name
  13. 122 define('ZBX_FONT_NAME', 'simkai');
  14. [root@server fonts]# systemctl restart httpd

在这里插入图片描述

6. 监控远程主机

  1. # 配置zabbix的yum源并安装zabbix-agent
  2. [root@slave1 ~]# wget https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
  3. [root@slave1 ~]# rpm -ivh zabbix-release-5.0-1.el7.noarch.rpm
  4. [root@slave1 ~]# cd /etc/yum.repos.d/
  5. [root@slave1 yum.repos.d]# ll
  6. 总用量 12
  7. -rw-r--r--. 1 root root 2523 6 16 2018 Centos-7.repo
  8. -rw-r--r--. 1 root root 664 5 11 2018 epel-7.repo
  9. -rw-r--r--. 1 root root 853 5 11 2020 zabbix.repo
  10. [root@slave1 ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
  11. [root@slave1 ~]# yum clean all
  12. [root@slave1 ~]# yum makecache
  13. [root@slave1 ~]# yum install zabbix-agent -y
  14. # 修改zabbix-agent的配置文件
  15. sed -i 's/Server=127.0.0.1/Server=192.168.80.165/g' /etc/zabbix/zabbix_agentd.conf
  16. sed -i 's/ServerActive=127.0.0.1/ServerActive=192.168.80.165/g' /etc/zabbix/zabbix_agentd.conf
  17. sed -i 's/Hostname=Zabbix server/Hostname=192.168.80.166/g' /etc/zabbix/zabbix_agentd.conf
  18. sed -i 's/# UnsafeUserParameters=0/UnsafeUserParameters=1 /g' /etc/zabbix/zabbix_agentd.conf
  19. # 启动zabbix-agent服务
  20. [root@slave1 ~]# systemctl restart zabbix-agent.service
  21. [root@slave1 ~]# systemctl enable zabbix-agent.service
  22. # 可以看到zabbix-agent服务的默认端口号10050已经被监听
  23. [root@slave1 ~]# netstat -antup |grep 10050
  24. tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 20694/zabbix_agentd
  25. tcp6 0 0 :::10050 :::* LISTEN 20694/zabbix_agentd
  26. # 关闭防火墙或开放10050端口号
  27. [root@slave1 ~]# firewall-cmd --permanent --zone=public --add-port=10050/tcp
  28. success
  29. [root@slave1 ~]# firewall-cmd --reload
  30. success

web界面创建主机,并添加相应的监控模板:

在这里插入图片描述

写入主机信息:

在这里插入图片描述

选择监控模板:

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

查看监控结果,可用性显示绿色才算监控成功:

在这里插入图片描述

7. 安装grafana可视化界面

grafana版本grafana-6.7.4-1

  1. [root@server ~]# cd /usr/local/src/
  2. [root@server src]# rz
  3. [root@server src]# ll
  4. 总用量 62280
  5. -rw-r--r--. 1 root root 63773044 9 28 21:27 grafana-6.7.4-1.x86_64.rpm
  6. [root@server src]# yum install grafana-6.7.4-1.x86_64.rpm -y
  7. [root@server src]# systemctl start grafana-server.service && systemctl enable grafana-server.service
  8. # 默认占用3000号端口
  9. [root@server src]# netstat -antup |grep 3000
  10. tcp6 0 0 :::3000 :::* LISTEN 87602/grafana-serve

首次登录默认账号密码:admin/admin
会要求修改登录密码,这里建议修改成和zabbix系统一致,方便记忆。

在这里插入图片描述

8. 添加zabbix数据源

这里有很多数据源可以选择,但就是没有zabbix的。

在这里插入图片描述

手动下载zabbix的plugin,导入进去:

  1. [root@server ~]# ll grafana-zabbix-plugins-v3.12.4-1.zip
  2. -rw-r--r--. 1 root root 2747693 9 30 15:49 grafana-zabbix-plugins-v3.12.4-1.zip
  3. [root@server ~]# unzip grafana-zabbix-plugins-v3.12.4-1.zip -d /var/lib/grafana/plugins/
  4. [root@server ~]# systemctl restart grafana-server.service

启用zabbix数据源的plugins:

在这里插入图片描述

在这里插入图片描述

重新添加zabbix数据源,可以看到有zabbix了。

在这里插入图片描述

设置zabbix的api接口信息:

  1. [root@server ~]# ll /usr/share/zabbix/api_jsonrpc.php
  2. -rw-r--r--. 1 root root 2326 12 21 17:38 /usr/share/zabbix/api_jsonrpc.php

接口地址http://192.168.80.165/zabbix/api_jsonrpc.php

在这里插入图片描述

在这里插入图片描述

保存并测试显示没问题,就说明已经将zabbix数据源正确添加了。

zabbix默认带有三个面板,可以导入看看效果,不满意可以自定义dashboard。

在这里插入图片描述

9. Dashboard设计(待设计)

预期效果:

  • 总览面板:可以看到所有服务器的监控情况。
  • 分览面板:可以看到某台服务器的监控情况。
  • 监控指标:硬件、cpu、内存、磁盘、网络、应用(nginx、tomcat)、数据库
  • 阈值预警:超出阈值会有颜色变化
  • 使用模板和变量设计Dashboard,可以直接导入Dashboard进行复用。

附件1:zabbix.repo

  1. [root@server yum.repos.d]# cat zabbix.repo
  2. [zabbix]
  3. name=Zabbix Official Repository - $basearch
  4. baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/
  5. enabled=1
  6. gpgcheck=1
  7. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
  8. [zabbix-frontend]
  9. name=Zabbix Official Repository frontend - $basearch
  10. baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
  11. enabled=1
  12. gpgcheck=1
  13. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
  14. [zabbix-debuginfo]
  15. name=Zabbix Official Repository debuginfo - $basearch
  16. baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/debuginfo/
  17. enabled=1
  18. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
  19. gpgcheck=1
  20. [zabbix-non-supported]
  21. name=Zabbix Official Repository non-supported - $basearch
  22. baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/
  23. enabled=1
  24. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
  25. gpgcheck=1

发表评论

表情:
评论列表 (有 0 条评论,322人围观)

还没有评论,来说两句吧...

相关阅读