美文网首页
Zabbix安装 - 新

Zabbix安装 - 新

作者: 诺之林 | 来源:发表于2020-06-19 13:47 被阅读0次

本文vagrantfile配置详细参考vagrant-zabbix

目录

安装

vagrant ssh zabbix

wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.4-1%2Bxenial_all.deb
sudo dpkg -i zabbix-release_3.4-1+xenial_all.deb
sudo apt update

sudo apt install -y zabbix-server-mysql zabbix-frontend-php zabbix-agent
# sudo mysql_secure_installation
# sudo mysql -uroot -p
# CREATE DATABASE zabbix character set utf8 collate utf8_bin;
# GRANT ALL PRIVILEGES on zabbix.* to zabbix@localhost IDENTIFIED BY '123456';
# FLUSH PRIVILEGES;

zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p zabbix

sudo vim /etc/zabbix/apache.conf
# php_value date.timezone Asia/Shanghai

sudo vim /etc/zabbix/zabbix_server.conf
# DBHost=localhost
# DBName=zabbix
# DBUser=zabbix
# DBPassword=123456

sudo service apache2 restart
sudo service apache2 status # active (running)

sudo service zabbix-server restart
sudo service zabbix-server status # active (running)
账号: Admin

密码: zabbix

报警

  • 企业微信 => 创建应用 => 保存参数
agentid 1000002

secret xxxx

corpid ww14ea6cc9f25696d5
sudo vim /usr/lib/zabbix/alertscripts/wechat.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-


import json
import requests
import sys

sendto = str(sys.argv[1])
subject = str(sys.argv[2])
content = str(sys.argv[3])

# 获取access_token
# https://work.weixin.qq.com/api/doc/90000/90135/91039
corpid = 'ww14ea6cc9f25696d5'
corpsecret = 'xxxx'
res = requests.get(
    "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={}&corpsecret={}".format(corpid, corpsecret))
token = res.json()['access_token']
print(token)

# 发送应用消息
# https://work.weixin.qq.com/api/doc/90000/90135/90236
data = json.dumps({'agentid': 1000002,
                   'toparty': sendto,
                   'msgtype': 'text',
                   "text": {
                       "content": subject + '\n' + content
                   }})
res = requests.post(
    "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={}".format(token), data=data)
print(res.json())
sudo chmod 777 /usr/lib/zabbix/alertscripts/wechat.py

/usr/lib/zabbix/alertscripts/wechat.py 1 hello world
  • Administration => Media types => Create media type
Name: 企业微信通知

Type: Script

Script name: wechat.py

Script parameters: {ALERT.SENDTO} {ALERT.SUBJECT} {ALERT.MESSAGE}
  • Administration => Users => admin => Media
Type: 企业微信通知

Send to: 1
  • Configuration => Actions => Create action
Name: 企业微信报警

Conditions: Maintenance status not in maintenance

Default operation step duration: 60

Operations:

    Send to User Groups: Zabbix administrators

    Send only to: 企业微信通知

Recovery operations:

    Send to User Groups: Zabbix administrators

    Send only to: 企业微信通知
  • Configuration => Hosts => Zabbix server => Enabled
sudo service zabbix-agent start

sudo service zabbix-agent status # active (running)
sudo dd if=/dev/zero of=/swapfile bs=1G count=2

sudo mkswap /swapfile

sudo swapon /swapfile

sudo vim /etc/fstab
# /swapfile  none  swap  sw  0  0

网页

  • Configuration => Hosts => Zabbix server => Web => Create web scenario
Name: 网站监测

Agent: Chrome 38.0 (Mac)

Steps:

    URL: http://file.nuozhilin.site

    Required status codes: 200
  • Configuration => Templates => Template App HTTP Service => Triggers => Create trigger
Name: HTTP response is not 200 on {HOST.NAME}

Severity: High

Expression:

    Item: Zabbix server: Zabbix server: Response code for step "http://file.nuozhilin.site" of scenario "网站监测".

    Function: last()

    Last Of (T): 2

    Time Shift: 5m

    Result: <> 200

{Zabbix server:web.test.rspcode[网站监测,http://file.nuozhilin.site].last(#2,5m)}<>200

监控

vagrant ssh web

wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.4-1%2Bxenial_all.deb
sudo dpkg -i zabbix-release_3.4-1+xenial_all.deb
sudo apt update

sudo apt install -y zabbix-agent

sudo vim /etc/zabbix/zabbix_agentd.conf
# Server=192.168.56.101

sudo service zabbix-agent restart
sudo service zabbix-agent status # active (running)
Host
Host name: web
Visible name: web
Groups: Linux servers
New group: Web
Agent interfaces: 192.168.56.102 10050

Templates
Linked templates: Template OS Linux
  • Monitoring => Graphs => Group (Web) => Host (web1) => Graph (CPU utilization)

模式

  • 主动模式(Push) 客户端向服务端主动发动数据

  • 被动模式(Pull) 客户端等待服务端来获取数据 <= Zabbix默认模式

sudo dd if=/dev/zero of=/swapfile bs=1G count=2

sudo mkswap /swapfile

sudo swapon /swapfile

sudo vim /etc/fstab
# /swapfile  none  swap  sw  0  0

参考

相关文章

  • zabbix简易教程

    1、Zabbix介绍 Zabbix功能 Zabbix应用 2、zabbix安装教程 安装包安装Zabbix doc...

  • zabbix3.4使用说明

    zabbix架构图 zabbix安装 ​ zabbix需要安装依赖的数据库,需要安装zabbix server...

  • Zabbix安装 - 新

    本文vagrantfile配置详细参考vagrant-zabbix 目录 安装 报警 网页 监控 模式 安装 浏览...

  • zabbix安装

    安装zabbix 4.0 LTS 1:配置zabbix yum仓库 2:安装zabbix服务端和zabbix-...

  • zabbix

    zabbix-server安装 1、安装zabbix源rpm -Uvh https://repo.zabbix.c...

  • Zabbix安装

    1、创建zabbix运行的用户 2、zabbix安装 2.1 安装阿里云yum配置文件 2.2 安装zabbix-...

  • zabbix docker 安装

    第一步 安装zabbix一、docker 安装 zabbix

  • Zabbix监控nginx性能(记录)

    zabbix配置监控nginx,nginx安装的时候必须编译安装zabbix模块 需要使用zabbix监控ngin...

  • zabbix部署

    1:配置zabbix yum仓库 2:安装zabbix服务端和zabbix-web前端 3:安装mariadb,创...

  • Ansible Role 监控 之【zabbix-server】

    Ansible Role: zabbix-server 安装zabbix server 介绍 zabbix(音同 ...

网友评论

      本文标题:Zabbix安装 - 新

      本文链接:https://www.haomeiwen.com/subject/appvxktx.html