zabbix--5.0.2部署记录本

软件说明

软件版本备注
zabbix-server-mysql5.0.2宿主机部署
zabbix-agent5.0.2宿主机部署
zabbix-web-nginx-mysql5.0.2docker方式部署
mysql8.0.21宿主机部署
grafana6.6.2宿主机部署

最终效果预览

 

安装MySQL

✏️ 下载软件包

[root@tfryb-04-30-02 ~]# mkdir /data/tools

[root@tfryb-04-30-02 ~]# cd /data/tools/

[root@tfryb-04-30-02 tools]# cat << EOF >download.sh

#!/bin/bash

wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-client-8.0.21-1.el7.x86_64.rpm

wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-devel-8.0.21-1.el7.x86_64.rpm

wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-embedded-compat-8.0.21-1.el7.x86_64.rpm

wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-libs-8.0.21-1.el7.x86_64.rpm

wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-libs-compat-8.0.21-1.el7.x86_64.rpm

wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-server-8.0.21-1.el7.x86_64.rpm

wget https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-community-common-8.0.21-1.el7.x86_64.rpm

wget https://mirrors.huaweicloud.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-server-mysql-5.0.2-1.el7.x86_64.rpm

wget https://mirrors.huaweicloud.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-get-5.0.2-1.el7.x86_64.rpm

EOF

[root@tfryb-04-30-02 tools]# bash download.sh

✏️ 安装

[root@tfryb-04-30-02 tools]# yum localinstall ./mysql-community-* -y

✏️ 修改配置文件(更改数据存放路径)

[root@tfryb-04-30-02 ~]# grep -v -E '^#|^$' /etc/my.cnf

[mysqld]

default-storage-engine=InnoDB

datadir=/data/mysql/

socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

✏️ 启动

[root@tfryb-04-30-02 tools]# systemctl start mysqld

[root@tfryb-04-30-02 tools]# systemctl enable mysqld

✏️ 修改密码

[root@tfryb-04-30-02 tools]# grep password /var/log/mysqld.log  #过滤出默认密码

2020-09-07T06:22:11.617861Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Nyf9I2Eglh/q

[root@tfryb-04-30-02 tools]# mysql -u root -p

Enter password:

......

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY "Zabbix#qaz#123";

Query OK, 0 rows affected (0.01 sec)

✏️ 创建zabbix库和用户

mysql> create database zabbix character set utf8 collate utf8_bin;

Query OK, 1 row affected (0.01 sec)

mysql> create user 'zabbix'@'%' identified by 'Zabbix@123';

Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on zabbix.* to 'zabbix'@'%' with grant option;

Query OK, 0 rows affected (0.00 sec)

mysql> alter user 'zabbix'@'%' identified with mysql_native_password by "Zabbix@123";

Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,plugin from mysql.user;

+------------------+-----------+-----------------------+

| user | host | plugin |

+------------------+-----------+-----------------------+

| zabbix | % | mysql_native_password |

| mysql.infoschema | localhost | caching_sha2_password |

| mysql.session | localhost | caching_sha2_password |

| mysql.sys | localhost | caching_sha2_password |

| root | localhost | caching_sha2_password |

+------------------+-----------+-----------------------+

5 rows in set (0.00 sec)

 

安装zabbix-server

✏️ 安装依赖fping

# 安装依赖fping

[root@tfryb-04-30-02 tools]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

[root@tfryb-04-30-02 tools]# yum install fping -y

✏️ 安装zabbix

[root@tfryb-04-30-02 tools]# yum localinstall zabbix-server-mysql-5.0.2-1.el7.x86_64.rpm -y

[root@tfryb-04-30-02 tools]# yum localinstall zabbix-get-5.0.2-1.el7.x86_64.rpm -y

✏️ 配置zabbix

[root@tfryb-04-30-02 ~]# cp /etc/zabbix/zabbix_server.conf{,.bck}

[root@tfryb-04-30-02 ~]# grep -v -E "^#|^$" /etc/zabbix/zabbix_server.conf

LogFile=/var/log/zabbix/zabbix_server.log

LogFileSize=0

PidFile=/var/run/zabbix/zabbix_server.pid

SocketDir=/var/run/zabbix

DBName=zabbix

DBUser=zabbix

DBPassword=Zabbix@123

SNMPTrapperFile=/var/log/snmptrap/snmptrap.log

Timeout=4

AlertScriptsPath=/usr/lib/zabbix/alertscripts

ExternalScripts=/usr/lib/zabbix/externalscripts

LogSlowQueries=3000

StatsAllowedIP=127.0.0.1

✏️ 导入zabbix数据库文件

[root@tfryb-04-30-02 ~]# zcat /usr/share/doc/zabbix-server-mysql-5.0.2/create.sql.gz |mysql -uroot -pYotta#qaz#123 zabbix

[root@tfryb-04-30-02 ~]# mysql -u root -pYotta#qaz#123 -e "show tables from zabbix"

mysql: [Warning] Using a password on the command line interface can be insecure.

+----------------------------+

| Tables_in_zabbix |

+----------------------------+

| acknowledges |

| actions |

| alerts |

| application_discovery |

| application_prototype |

| application_template |

| applications |

| auditlog |

| auditlog_details |

| autoreg_host |

| conditions |

| config |

| config_autoreg_tls |

| corr_condition |

| corr_condition_group |

| corr_condition_tag |

| corr_condition_tagpair |

| corr_condition_tagvalue |

| corr_operation |

| correlation |

| dashboard |

| dashboard_user |

| dashboard_usrgrp |

| dbversion |

| dchecks |

| dhosts |

| drules |

| dservices |

| escalations |

| event_recovery |

| event_suppress |

| event_tag |

| events |

| expressions |

| functions |

| globalmacro |

| globalvars |

| graph_discovery |

| graph_theme |

| graphs |

| graphs_items |

| group_discovery |

| group_prototype |

| history |

| history_log |

| history_str |

| history_text |

| history_uint |

| host_discovery |

| host_inventory |

| host_tag |

| hostmacro |

| hosts |

| hosts_groups |

| hosts_templates |

| housekeeper |

| hstgrp |

| httpstep |

| httpstep_field |

| httpstepitem |

| httptest |

| httptest_field |

| httptestitem |

| icon_map |

| icon_mapping |

| ids |

| images |

| interface |

| interface_discovery |

| interface_snmp |

| item_application_prototype |

| item_condition |

| item_discovery |

| item_preproc |

| item_rtdata |

| items |

| items_applications |

| lld_macro_path |

| lld_override |

| lld_override_condition |

| lld_override_opdiscover |

| lld_override_operation |

| lld_override_ophistory |

| lld_override_opinventory |

| lld_override_opperiod |

| lld_override_opseverity |

| lld_override_opstatus |

| lld_override_optag |

| lld_override_optemplate |

| lld_override_optrends |

| maintenance_tag |

| maintenances |

| maintenances_groups |

| maintenances_hosts |

| maintenances_windows |

| mappings |

| media |

| media_type |

| media_type_message |

| media_type_param |

| module |

| opcommand |

| opcommand_grp |

| opcommand_hst |

| opconditions |

| operations |

| opgroup |

| opinventory |

| opmessage |

| opmessage_grp |

| opmessage_usr |

| optemplate |

| problem |

| problem_tag |

| profiles |

| proxy_autoreg_host |

| proxy_dhistory |

| proxy_history |

| regexps |

| rights |

| screen_user |

| screen_usrgrp |

| screens |

| screens_items |

| scripts |

| service_alarms |

| services |

| services_links |

| services_times |

| sessions |

| slides |

| slideshow_user |

| slideshow_usrgrp |

| slideshows |

| sysmap_element_trigger |

| sysmap_element_url |

| sysmap_shape |

| sysmap_url |

| sysmap_user |

| sysmap_usrgrp |

| sysmaps |

| sysmaps_elements |

| sysmaps_link_triggers |

| sysmaps_links |

| tag_filter |

| task |

| task_acknowledge |

| task_check_now |

| task_close_problem |

| task_data |

| task_remote_command |

| task_remote_command_result |

| task_result |

| timeperiods |

| trends |

| trends_uint |

| trigger_depends |

| trigger_discovery |

| trigger_tag |

| triggers |

| users |

| users_groups |

| usrgrp |

| valuemaps |

| widget |

| widget_field |

+----------------------------+

✏️ 启动

[root@tfryb-04-30-02 ~]# systemctl start zabbix-server.service

[root@tfryb-04-30-02 ~]# systemctl enable zabbix-server.service

 

安装docker

yum install -y yum-utils device-mapper-persistent-data lvm2

yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum -y install docker-ce

sed -i 's#ExecStart=/usr/bin/dockerd.*#ExecStart=/usr/bin/dockerd#' /usr/lib/systemd/system/docker.service

mkdir /etc/docker /data/docker

cat >/etc/docker/daemon.json<<EOF

{

"registry-mirrors": ["https://15y9mzqb.mirror.aliyuncs.com"],

"exec-opts": ["native.cgroupdriver=systemd"],

"graph": "/data/docker"

}

EOF

systemctl daemon-reload

systemctl enable docker

systemctl start docker

systemctl status docker

 

安装zabbix-web

✏️ 下载镜像

[root@tfryb-04-30-02 ~]# docker pull zabbix/zabbix-web-nginx-mysql:centos-5.0.2

[root@tfryb-04-30-02 ~]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

zabbix/zabbix-web-nginx-mysql centos-5.0.2 c552ec85c6c8 7 weeks ago 439MB

✏️ 启动zabbix-web

[root@tfryb-04-30-02 ~]# docker run --name zabbix-web-nginx-mysql \

-e DB_SERVER_HOST="172.24.xxx.xxx" \

-e MYSQL_DATABASE="zabbix" \

-e MYSQL_USER="zabbix" \

-e MYSQL_PASSWORD="Zabbix@123" \

-e ZBX_SERVER_HOST="172.24.xxx.xxx" \

-e PHP_TZ="Asia/Shanghai" \

-p 80:8080 \

-d zabbix/zabbix-web-nginx-mysql:centos-5.0.2

[root@tfryb-04-30-02 ~]# docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

a3291b17f364 zabbix/zabbix-web-nginx-mysql:centos-5.0.2 "docker-entrypoint.sh" 3 seconds ago Up 10 minutes 8443/tcp, 0.0.0.0:80->8080/tcp zabbix-web-nginx-mysql

✏️ Web访问 http://172.24.xxx.xxx

 

解决乱码问题

# 1.上传字体到服务器

[root@tfryb-04-30-02 ~]# ls simkai.ttf

simkai.ttf

# 2.将字体copy到容器中

[root@tfryb-04-30-02 ~]# docker cp simkai.ttf zabbix-web-nginx-mysql:/usr/share/zabbix/assets/fonts/

# 3.进入容器中进行配置

[root@tfryb-04-30-02 ~]# docker exec -it zabbix-web-nginx-mysql /bin/bash

bash-4.4$ ls /usr/share/zabbix/assets/fonts/

DejaVuSans.ttf simkai.ttf

bash-4.4$ vi /usr/share/zabbix/include/defines.inc.php

#更改前

// define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans'); // font file name

#更改后

define('ZBX_GRAPH_FONT_NAME', 'simkai'); // font file name

✏️ 验证修改后的字体

 

安装zabbix-agent

这里采用ansible安装zabbix-agent

✏️ 下载软件包(在ansible server端下载zabbix-agent软件包)

[root@tfryb-04-30-02 ~]# cd /data/tools/

[root@tfryb-04-30-02 ~]# wget https://mirrors.huaweicloud.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-agent-5.0.2-1.el7.x86_64.rpm

✏️ 编写playbook

[root@tfryb-04-30-02 ~]# mkdir /data/tools/playbook -p

[root@tfryb-04-30-02 ~]# cd /data/tools/playbook/

[root@tfryb-04-30-02 playbook]# cat playbook_zabbix_agent.yml

---

- hosts: tdsql_test #需要安装的主机,或者主机组

remote_user: root

vars:

- src_package_path: /data/tools/zabbix-agent-5.0.2-1.el7.x86_64.rpm #ansible server上zabbix-agent包的路径

- dest_package_path: /root/zabbix-agent-5.0.2-1.el7.x86_64.rpm

tasks:

- name: Copy package zabbix-agent

copy: src={{ src_package_path }} dest={{ dest_package_path }} backup=yes

- name: Install zabbix agent

yum: name={{ dest_package_path }} state=installed

- name: Config zabbix agent

template: src=zabbix_agentd.conf.j2 dest=/etc/zabbix/zabbix_agentd.conf

notify: Restart zabbix agent

- name: Start zabbix agent

service: name=zabbix-agent.service state=started

handlers:

- name: Restart zabbix agent

service: name=zabbix-agent.service state=restarted

✏️ 准备配置文件模板

[root@tfryb-04-30-02 ~]# cd /data/tools/playbook/

[root@tfryb-04-30-02 playbook]# cat zabbix_agentd.conf.j2

PidFile=/var/run/zabbix/zabbix_agentd.pid

LogFile=/var/log/zabbix/zabbix_agentd.log

LogFileSize=0

Server=172.24.xxx.xxx

ServerActive=172.24.xxx.xxx:10051

Hostname={{ ansible_all_ipv4_addresses[0] }}

HostMetadataItem=system.uname

Include=/etc/zabbix/zabbix_agentd.d/*.conf

✏️ 安装

[root@tfryb-04-30-02 playbook]# ansible-playbook playbook_zabbix_agent.yml

PLAY [tdsql_test] *************************************************************

GATHERING FACTS ***************************************************************

ok: [172.24.xxx.xx]

ok: [172.24.xxx.xx]

ok: [172.24.xxx.xx]

ok: [172.24.xxx.xx]

ok: [172.24.xxx.xx]

......

✏️ 执行完成验证下配置文件是否正确

[root@tfryb-04-30-02 playbook]# ansible tdsql_test -m shell -a "cat /etc/zabbix/zabbix_agentd.conf"

 

微信告警

✏️ zabbix server配置文件修改

[root@tfryb-04-30-02 ~]# vim /etc/zabbix/zabbix_server.conf

AlertScriptsPath=/usr/lib/zabbix/alertscripts

✏️ 报警脚本编写

[root@tfryb-04-30-02 ~]# vim /usr/lib/zabbix/alertscripts/weixin.py

#!/usr/bin/python2.7.5

#_*_coding:utf-8 _*_

import urllib,urllib2

import json

import sys

import simplejson

reload(sys)

sys.setdefaultencoding('utf-8')

def gettoken(corpid,corpsecret):

gettoken_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + corpsecret

try:

token_file = urllib2.urlopen(gettoken_url)

except urllib2.HTTPError as e:

print e.code

print e.read().decode("utf8")

sys.exit()

token_data = token_file.read().decode('utf-8')

token_json = json.loads(token_data)

token_json.keys()

token = token_json['access_token']

return token

def senddata(access_token,user,subject,content):

send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + access_token

send_values = {

"touser":"@all", #企业号中的用户帐号,在zabbix用户Media中配置,如果配置不正常,将按部门发送。

"toparty":"2PURL", #企业号中的部门id。

"msgtype":"text", #消息类型。

"agentid":"1000038", #企业号中的应用id。

"text":{

"content":subject + '\n' + content

},

"safe":"0"

}

send_data = simplejson.dumps(send_values, ensure_ascii=False).encode('utf-8')

send_request = urllib2.Request(send_url, send_data)

response = json.loads(urllib2.urlopen(send_request).read())

print str(response)

if __name__ == '__main__':

user = str(sys.argv[1]) #zabbix传过来的第一个参数

subject = str(sys.argv[2]) #zabbix传过来的第二个参数

content = str(sys.argv[3]) #zabbix传过来的第三个参数

corpid = 'ww235ddb83xxxxxxxx' #企业号的标识(上文中提到获取位置)

corpsecret = 'NEtVoiQmgQBsBZ2IOrMdHG2CU9vxxxxxxxxxxx' #管理组凭证密钥(上文中提到获取位置)

accesstoken = gettoken(corpid,corpsecret)

senddata(accesstoken,user,subject,content)

✏️ web界面添加报警媒介

✏️ 添加完成可以进行测试

✏️ 给用户添加报警媒介

✏️ 配置一个告警动作

上面步骤配置完成后,可以测试模拟一个故障,便会通过微信接收到告警信息。

补充:告警消息模板

告警操作消息内容:

告警主机:{HOST.NAME}

主机IP: {HOST.IP}

告警时间:{EVENT.DATE} {EVENT.TIME}

告警等级:{TRIGGER.SEVERITY}

告警详情:{TRIGGER.NAME}

问题状态:{ITEM.VALUE}

当前状态:{TRIGGER.STATUS}

事件ID: {EVENT.ID}

告警恢复消息内容:

告警主机:{HOST.NAME}

主机IP: {HOST.IP}

告警时间:{EVENT.DATE} {EVENT.TIME}

告警等级:{TRIGGER.SEVERITY}

告警详情:{TRIGGER.NAME}

问题状态:{ITEM.VALUE}

当前状态:{TRIGGER.STATUS}

事件ID: {EVENT.ID}

 

安装Grafana

✏️ 安装grafana

[root@tfryb-04-30-02 ~]# yum localinstall grafana-6.6.2-1.x86_64.rpm -y

✏️ 启动

[root@tfryb-04-30-02 ~]# systemctl start grafana-server.service

[root@tfryb-04-30-02 ~]# systemctl enable grafana-server.service

✏️ Web访问http://172.24.115.129:3000/

默认账户:admin 密码:admin ,首次登陆后会要求修改密码。Admin#123zaQ

✏️ 安装zabbix插件

由于网络问题,该插件下载巨慢,故采用离线方式进行安装

[root@tfryb-04-30-02 ~]# unzip alexanderzobnin-zabbix-app-4.0.1.zip

[root@tfryb-04-30-02 ~]# mv alexanderzobnin-zabbix-app /var/lib/grafana/plugins/

[root@tfryb-04-30-02 ~]# ls /var/lib/grafana/plugins/

alexanderzobnin-zabbix-app

[root@tfryb-04-30-02 ~]# systemctl restart grafana-server.service

✏️ web界面激活zabbix插件

注:如安装最新的zabbix插件会出现问题

grafana里面plugins列表里面有zabbix,但是添加数据源的时候列表里面找不到,zabbix已经enable

解决办法

1.修改配置文件

[root@tfryb-04-30-02 ~]# vim /etc/grafana/grafana.ini

#默认情况下,未签名的插件不会加载,因此请在Grafana配置文件中允许它

allow_loading_unsigned_plugins = alexanderzobnin-zabbix-datasource

2.重启grafana

[root@tfryb-04-30-02 ~]# systemctl restart grafana-server

✏️ 添加zabbix数据源

✏️ 配置模板

该模板需要安装grafana-piechart-panel插件

[root@tfryb-04-30-02 ~]# grafana-cli plugins list-remote  |grep grafana-piechart-panel

id: grafana-piechart-panel version: 1.6.0

[root@tfryb-04-30-02 ~]# grafana-cli plugins install grafana-piechart-panel

installing grafana-piechart-panel @ 1.6.0

from: https://grafana.com/api/plugins/grafana-piechart-panel/versions/1.6.0/download

into: /var/lib/grafana/plugins

✔ Installed grafana-piechart-panel successfully

Restart grafana after installing plugins . <service grafana-server restart>

[root@tfryb-04-30-02 ~]# systemctl restart grafana-server.service

导入模板Zabbix5.0.2服务器基础监控grafana模板.json

☑️ 备注:

grafana的"Zabbix5.0.2服务器基础监控grafana模板.json"模板需要和zabbix 的监控模板"zbx_Base_Monitor_templates.xml"配合一起使用。 该模板如需要,请联系我。

以上是 zabbix--5.0.2部署记录本 的全部内容, 来源链接: utcz.com/a/46797.html

回到顶部