本篇文章介绍zabbix监控,监控是对我们操作系统进行不间断的监控,这是软件生命周期非常重要的一环,可以做到事前告警,事后根据监控内容排查问题(金丝雀,监控重要指标),有问题的时候,运维需要管理运维债务(在软件开发过程中积累的一些技术债务)
目录
监控内容
监控工具
Zabbix安装
1、配置yum源
2、安装zabbix服务
3、安装scl源,更好兼容已经安装的软件包,避免把系统搞烂
4、开启前端的仓库
5、安装php和apache前端
6、安装mariadb
7、配置zabbix数据库
8、导入数据库,初始化数据
9、再次配置数据库
10、修改zabbix连接数据库的信息
11、修改时区
12、启动zabbix进程
13、浏览器访问安装
14、修改语言为中文
15、修改乱码
Zabbix添加监控服务器
1、安装zabbix-agent客户端,准备一台服务器10.0.0.7
2、配置zabbix客户端服务器信息,启动服务端
3、zabbix监控web01
拆分数据库
1、准备一台数据库服务器10.0.0.51安装mariadb
2、导出zabbix服务器zabbix数据库,导入到新的数据库
3、配置WEB连接数据库信息并重启服务
监控内容
我们需要监控硬件(磁盘df -h,内存free,磁盘IO,负载CPU,网络),软件服务(端口、进程、状态),业务层面(监控业务数据,订单量,注册用户,充值用户),只要是有值,zabbix都能监控,核心功能就是自定义监控。
监控工具
zabbix 硬件 服务状态 自定义监控
Nagions 网络产品 交换机 路由器 中型大型公司使用
Cacti 流量
Open-Falcon 小米公司自研
prometheus 监控kubernetes docker,比zabbix更好
监控宝等等
Zabbix安装
服务端:10.0.0.71(配置与监控数量有关,企业中一般是8G内存,4核或6核)
客户端:10.0.0.7,10.0.0.8
系统版本为CentOS7.9
1、配置yum源
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpmyum clean all
2、安装zabbix服务
yum -y install zabbix-server-mysql zabbix-agent
3、安装scl源,更好兼容已经安装的软件包,避免把系统搞烂
yum -y install centos-release-scl
4、开启前端的仓库
[root@Zabbix ~]# cat /etc/yum.repos.d/zabbix.repo[zabbix]name=Zabbix Official Repository - $basearchbaseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/enabled=1gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591[zabbix-frontend]name=Zabbix Official Repository frontend - $basearchbaseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontendenabled=1#开这里gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591[zabbix-debuginfo]name=Zabbix Official Repository debuginfo - $basearchbaseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/debuginfo/enabled=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591gpgcheck=1[zabbix-non-supported]name=Zabbix Official Repository non-supported - $basearchbaseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/enabled=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIXgpgcheck=1
5、安装php和apache前端
yum -y install zabbix-web-mysql-scl zabbix-apache-conf-scl
6、安装mariadb
yum -y install mariadb-serversystemctl start mariadbsystemctl enable mariadb
7、配置zabbix数据库
[root@Zabbix ~]# mysql -urootWelcome to the MariaDB monitor.Commands end with ; or \g.Your MariaDB connection id is 2Server version: 5.5.68-MariaDB MariaDB ServerCopyright (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)]> create database zabbix character set utf8 collate utf8_bin;Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> create user zabbix@localhost identified by 'zabbix';Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> set global log_bin_trust_function_creators = 1;Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> quit;Bye
8、导入数据库,初始化数据
[root@Zabbix ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbixEnter password: zabbix
可以进去检查一下
[root@Zabbix ~]# mysql -urootWelcome to the MariaDB monitor.Commands end with ; or \g.Your MariaDB connection id is 5Server version: 5.5.68-MariaDB MariaDB ServerCopyright (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)]> use zabbixReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedMariaDB [zabbix]> show tables;+----------------------------+| 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 |+----------------------------+166 rows in set (0.00 sec)
9、再次配置数据库
[root@Zabbix ~]# mysql -urootWelcome to the MariaDB monitor.Commands end with ; or \g.Your MariaDB connection id is 8Server version: 5.5.68-MariaDB MariaDB ServerCopyright (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)]> set global log_bin_trust_function_creators = 0;Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> quitBye
10、修改zabbix连接数据库的信息
[root@Zabbix ~]# egrep ^DB /etc/zabbix/zabbix_server.confDBName=zabbixDBUser=zabbixDBPassword=zabbix#取消注释
11、修改时区
[root@Zabbix ~]# tail -1 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.confphp_value[date.timezone] = Asia/Shanghai
12、启动zabbix进程
[root@Zabbix ~]# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm[root@Zabbix ~]# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
13、浏览器访问安装
14、修改语言为中文
15、修改乱码
上传windows字体到zabbix中
[root@Zabbix ~]# cd /usr/share/fonts/dejavu[root@Zabbix dejavu]# lltotal 5288-rw-r--r-- 1 root root 611212 Feb 272011 DejaVuSans-BoldOblique.ttf-rw-r--r-- 1 root root 672300 Feb 272011 DejaVuSans-Bold.ttf-rw-r--r-- 1 root root 580168 Feb 272011 DejaVuSansCondensed-BoldOblique.ttf-rw-r--r-- 1 root root 631992 Feb 272011 DejaVuSansCondensed-Bold.ttf-rw-r--r-- 1 root root 576004 Feb 272011 DejaVuSansCondensed-Oblique.ttf-rw-r--r-- 1 root root 643852 Feb 272011 DejaVuSansCondensed.ttf-rw-r--r-- 1 root root 345204 Feb 272011 DejaVuSans-ExtraLight.ttf-rw-r--r-- 1 root root 611556 Feb 272011 DejaVuSans-Oblique.ttf-rw-r--r-- 1 root root 720012 Feb 272011 DejaVuSans.ttf[root@Zabbix dejavu]# rz -Erz waiting to receive.[root@Zabbix dejavu]# mv DejaVuSans.ttf DejaVuSans.ttf.bak[root@Zabbix dejavu]# mv simhei.ttf DejaVuSans.ttf
Zabbix添加监控服务器
1、安装zabbix-agent客户端,准备一台服务器10.0.0.7
#配置yum仓库rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-agent-5.0.34-1.el7.x86_64.rpm#解决软件冲突yum -y install centos-release-scl#安装客户端agentyum -y install zabbix-agent
2、配置zabbix客户端服务器信息,启动服务端
[root@Web01 yum.repos.d]# cat /etc/zabbix/zabbix_agentd.confServer=172.16.1.71[root@Web01 yum.repos.d]# systemctl start zabbix-agent
3、zabbix监控web01
拆分数据库
1、准备一台数据库服务器10.0.0.51安装mariadb
[root@DB01 ~]# yum -y install mariadb-server[root@DB01 ~]# systemctl start mariadb[root@DB01 ~]# systemctl enable mariadb[root@DB01 ~]# mysqlWelcome to the MariaDB monitor.Commands end with ; or \g.Your MariaDB connection id is 2Server version: 5.5.68-MariaDB MariaDB ServerCopyright (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)]> create database zabbix character set utf8 collate utf8_bin;Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> create user 'zabbix'@'%' identified by 'zabbix';Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'%';Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> quitBye
2、导出zabbix服务器zabbix数据库,导入到新的数据库
[root@Zabbix ~]# mysqldump -uroot -B zabbix > zabbix.sql[root@Zabbix ~]# cat zabbix.sql |mysql -h 172.16.1.51 -uzabbix -pzabbix zabbix
3、配置WEB连接数据库信息并重启服务
[root@Zabbix ~]# cat /etc/zabbix/web/zabbix.conf.php<?php// Zabbix GUI configuration file.$DB['TYPE']= 'MYSQL';$DB['SERVER']= '172.16.1.51';$DB['PORT']= '3306';$DB['DATABASE']= 'zabbix';$DB['USER']= 'zabbix';$DB['PASSWORD']= 'zabbix';......[root@Zabbix ~]# grep ^DB /etc/zabbix/zabbix_server.conf DBHost=172.16.1.51DBName=zabbixDBUser=zabbixDBPassword=zabbix[root@Zabbix ~]# systemctl restart zabbix-server httpd
我是koten,10年运维经验,持续分享运维干货,感谢大家的阅读和关注!