【精选】运维自动化(二)

您所在的位置:网站首页 zabbix和pro 【精选】运维自动化(二)

【精选】运维自动化(二)

#【精选】运维自动化(二)| 来源: 网络整理| 查看: 265

Zabbix 介绍

Zabbix是由Alexei Vladishev 开发的一种网络监视、管理系统,基于Server-Client架构。可用于监视各种网络服务、服务器和网络机器等状态。

​使用各种Database-end 如 MySQL,PostgreSQL,SQlite,Oracle 或IBMDB2储存资料。Server端基于C语言、Web管理端frontend则是基于PHP所制作的。

Zabbix可以使用多种方式监视。可以只使用Simple Check不需要安装 Client端,亦可基于SMTP或HTTP… 各种协议定制监视。

在客户端如UNIX,Windows 中安装Zabbix Agent之后,可监视CPULoad、网络使用状况、硬盘容量等各种状态。而就算没有安装Agent 在监视对象中,Zabbix 也可以经由SNMP、TCP、ICMP、利用IPMI、SSH、telnet 对目标进行监视。

Zabbbix自带的Item足够满足普通小公司的监控需求,对于大公司也可以设定自定义的Item,自动生成报表,也有API可以和其他系统集成。

为何是Zaabix不是其他监控

Zabbix就是可以满足理想化的监控系统需求

支持自定义监控脚本,提供需要输出的值即可Zabbix存储的数据库表结构稍有复杂但是逻辑清晰Zabbix存在模板的概念,可以方便的将一组监控项进行部署Zabbix每一个item也就是监控项,都可以看到历史记录,且web界面友好Zabbix有强大的Trigger(触发器)定义规则,可以定义复杂的报警逻辑Zabbix提供了ack报警确认机制Zabbix支持邮件,短信,微信等告警Zabbix在触发告警后,可以远程执行系统命令Zabbix有原生的PHP绘图模块 Zabbix专有词汇

对于英文的掌握,是IT人员必须学习的技能,以下是使用zabbix必须掌握的一些关键词

zabbix server,服务端,收集数据,写入数据zabbix agent,部署在被监控的机器上,是一个进程和zabbix server进行交互,以及负责执行命令Host,服务器的概念,指zabbix监控的实体,服务器,交换机等Hosts,主机组Applications,应用Events,事件Media,发送通知的通道Remote command,远程命令Template,模板Item,对于某一个指标的监控,称之为Items,如某台服务器的内存使用状况,就是一个item监控项Trigger, 触发器,定义报警的逻辑,有正常,异常,未知三个状态Action, 当Trigger符合设定值后,zabbix指定的动作, 如发个邮件给运维,说服务器有问题了。 Zabbix程序组件 zabbix_server,服务端守护进程zabbix_agentd,agent守护进程zabbix_proxy,代理服务器zabbix_database,存储系统,mysql,pgsqlzabbix_web,web GUI图形化界面zabbix_ get,命令行工具,测试向agent发起数据采集请求zabbix_sender,命令行工具,测试向server发送数据zabbix_ java_ gateway,java网关 安装zabbix6.2

官网文档介绍了所需环境 https://www.zabbix.com/documentation/current/manual/installation/requirements

# 环境准备 # 关闭防火墙 [root@Zabbix ~]# systemctl disable --now firewalld # 关闭selinux [root@Zabbix ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config 安装步骤 # 1.获取zabbix官方源 [root@Zabbix ~]# rpm -Uvh https://repo.zabbix.com/zabbix/6.2/rhel/8/x86_64/zabbix-release-6.2-1.el8.noarch.rpm Retrieving https://repo.zabbix.com/zabbix/6.2/rhel/8/x86_64/zabbix-release-6.2-1.el8.noarch.rpm Verifying... ################################# [100%] Preparing... ################################# [100%] package zabbix-release-6.2-1.el8.noarch is already installed [root@Zabbix ~]# yum clean all # 2.安装php7.4,6.2版本需要php7.4 [root@Zabbix ~]# yum module switch-to php:7.4 # 3.安装zabbix server web前端和agent [root@Zabbix ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent -y # 4.安装zabbix所需的数据库,zabbix6.2所需mariadb版本至少为10.5,系统自带10.3版本,需要先卸载旧版本再安装新版本 # 备份数据库 [root@Zabbix ~]# mysqldump -u root -p --all-databases > /home/alldb.sql Enter password: # 备份配置 [root@Zabbix ~]# mv /etc/my.cnf /etc/my.cnf.bak # 停止并卸载旧版本数据库 [root@Zabbix ~]# systemctl stop mariadb [root@Zabbix ~]# yum remove mariadb mariadb-server # 添加yum源,这里作者添加的是10.5版本 [root@Zabbix ~]# cat /etc/yum.repos.d/MariaDB.repo # MariaDB 10.5 CentOS repository list - created 2021-06-23 09:53 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.5/centos8-amd64 module_hotfixes=1 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 # 清除yum源缓存并建立数据源 [root@Zabbix ~]# yum clean all && yum makecache # 安装新版本mariadb并设置开机自启 [root@Zabbix ~]# yum install mariadb mariadb-server -y [root@Zabbix ~]# systemctl start mariadb [root@Zabbix ~]# systemctl enable mariadb # 查看版本是否正确 [root@Zabbix ~]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 10.5.16-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)]> # 检查并更新数据库表 [root@Zabbix ~]# mysql_upgrade -uroot -p --force Enter password: Phase 1/7: Checking and upgrading mysql database Processing databases # 数据恢复 [root@Zabbix ~]# mysql -u root -p create database zabbix character set utf8 collate utf8_bin; # 创建zabbix数据库 Query OK, 1 row affected (0.000 sec) MariaDB [(none)]> create user zabbix@localhost identified by 'zabbix'; # 创建zabbix用户和密码 Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost; # 赋予zabbix用户可以使用zabbix数据库的权限 Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> quit Bye # 6.导入zabbix数据,系统将提示您输入新创建的密码(这里的密码是zabbix用户的密码,上面设置的) [root@Zabbix ~]# zcat /usr/share/doc/zabbix-sql-scripts/mysql/server.sql.gz | mysql -uzabbix -p zabbix Enter password: # 7.为Zabbix server配置数据库 [root@Zabbix ~]# vim /etc/zabbix/zabbix_server.conf # 将第129行(vim查看行数命令:set nu)改为 DBPassword=zabbix #我的账号密码都是zabbix # 8.启动Zabbix server和agent进程,设置开机自启 [root@Zabbix ~]# systemctl restart zabbix-server zabbix-agent httpd php-fpm [root@Zabbix ~]# systemctl enable zabbix-server zabbix-agent httpd php-fpm # 9.查看前端 http://ip/zabbix 安装前端web界面

1.选择语言,只有两项,后续可以自己安装需要的语言 在这里插入图片描述 2.检查requisites,确保全OK再进行下一步在这里插入图片描述 3.配置数据库连接,输入密码即可在这里插入图片描述 4.填写Zabbix server name,也可以不填,填了之后可以显示在菜单栏和页面标题中在这里插入图片描述 5.登录,默认账号Admin,密码zabbix 在这里插入图片描述

修改语言

为了在Zabbix界面使用其他语言,需要进行扩展。

# 1.展示已安装语言 [root@Zabbix ~]# locale -a C C.utf8 en_AG en_AU ...... en_ZM en_ZW en_ZW.utf8 POSIX # 2.安装中文 [root@Zabbix ~]# yum install glibc-langpack-zh.x86_64 -y [root@Zabbix ~]# echo LANG=zh_CN.UTF-8 > /etc/locale.conf [root@Zabbix ~]# source /etc/locale.conf

在这里插入图片描述

部署Zabbix客户端

准备一台新的机器,部署Zabbix客户端。

# 关闭防火墙 [root@Zabbix-agent ~]# systemctl disable --now firewalld # 配置时区 [root@Zabbix-agent ~]# mv /etc/localtime{,.bak} [root@Zabbix-agent ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime # 配置源文件 [root@Zabbix-agent ~]# rpm -Uvh https://repo.zabbix.com/zabbix/6.2/rhel/8/x86_64/zabbix-release-6.2-1.el8.noarch.rpm Retrieving https://repo.zabbix.com/zabbix/6.2/rhel/8/x86_64/zabbix-release-6.2-1.el8.noarch.rpm warning: /var/tmp/rpm-tmp.EW7vEG: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY Verifying... ################################# [100%] Preparing... ################################# [100%] Updating / installing... 1:zabbix-release-6.2-1.el8 ################################# [100%] [root@Zabbix-agent ~]# yum clean all && yum makecache # 安装客户端 [root@Zabbix-agent ~]# yum install zabbix-agent2 -y 默认配置文件为 /etc/zabbix/zabbix_agent2.conf 默认二进制文件为 /usr/sbin/zabbix_agent2 # 启动设置开机自启 [root@Zabbix-agent ~]# systemctl enable --now zabbix-agent2 Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-agent2.service → /usr/lib/systemd/system/zabbix-agent2.service. # 检查端口 [root@Zabbix-agent ~]# netstat -tunlp|grep zabbix tcp6 0 0 :::10050 :::* LISTEN 58168/zabbix_agent2 # 查看systemctl管理的单元文件,修改填写服务端ip和主机名 [root@Zabbix-agent ~]# vi /lib/systemd/system/zabbix-agent2.service [root@Zabbix-agent ~]# grep -Ev '^#|^$' /etc/zabbix/zabbix_agent2.conf PidFile=/var/run/zabbix/zabbix_agent2.pid LogFile=/var/log/zabbix/zabbix_agent2.log LogFileSize=0 Server=******* #填写服务端IP(作者用的是云服务器,不方便写在这) ServerActive=******* #填写服务端IP Hostname=Zabbix-agent #填写主机名 Include=/etc/zabbix/zabbix_agent2.d/*.conf ControlSocket=/tmp/agent.sock Include=./zabbix_agent2.d/plugins.d/*.conf # 重启agent2 [root@Zabbix-agent ~]# systemctl restart zabbix-agent2 检测server-client连通性

在服务端操作

[root@Zabbix ~]# yum install zabbix-get -y [root@Zabbix ~]# zabbix_get -s '客户端IP' -p 10050 -k "system.hostname" Zabbix-agent zabbix-server监控主机

默认监控自己(服务端) 在这里插入图片描述

服务器可视化指标

点击主机的【图形】,可见如下界面 在这里插入图片描述

解决Zabbix乱码问题

上图括号里是乱码,因为语言为中文,没有安装字体(这里很尴尬,作者这里发现zabbix没有数据,一番查找发现是conf文件里忘记写DBpassword了!!!)

[root@Zabbix zabbix]# yum -y install wqy-microhei-fonts [root@Zabbix zabbix]# \cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf

修改完成后正确显示中文 在这里插入图片描述

----根据于超老师视频讲解进行笔记,做了相对更改,如有侵权请联系作者删除。


【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3