本篇文章介绍zabbix监控,监控是对我们操作系统进行不间断的监控,这是软件生命周期非常重要的一环,可以做到事前告警,事后根据监控内容排查问题(金丝雀,监控重要指标),有问题的时候,运维需要管理运维债务(在软件开发过程中积累的一些技术债务)
监控内容
我们需要监控硬件(磁盘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源
1. rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm 2. yum clean all
2、安装zabbix服务
yum -y install zabbix-server-mysql zabbix-agent
3、安装scl源,更好兼容已经安装的软件包,避免把系统搞烂
yum -y install centos-release-scl
4、开启前端的仓库
1. [root@Zabbix ~]# cat /etc/yum.repos.d/zabbix.repo 2. [zabbix] 3. name=Zabbix Official Repository - $basearch 4. baseurl=http://repo.zabbix.com/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. 9. [zabbix-frontend] 10. name=Zabbix Official Repository frontend - $basearch 11. baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontend 12. enabled=1 #开这里 13. gpgcheck=1 14. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 15. 16. [zabbix-debuginfo] 17. name=Zabbix Official Repository debuginfo - $basearch 18. baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/debuginfo/ 19. enabled=0 20. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 21. gpgcheck=1 22. 23. [zabbix-non-supported] 24. name=Zabbix Official Repository non-supported - $basearch 25. baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/ 26. enabled=1 27. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX 28. gpgcheck=1
5、安装php和apache前端
yum -y install zabbix-web-mysql-scl zabbix-apache-conf-scl
6、安装mariadb
1. yum -y install mariadb-server 2. systemctl start mariadb 3. systemctl enable mariadb
7、配置zabbix数据库
1. [root@Zabbix ~]# mysql -uroot 2. Welcome to the MariaDB monitor. Commands end with ; or \g. 3. Your MariaDB connection id is 2 4. Server version: 5.5.68-MariaDB MariaDB Server 5. 6. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. 7. 8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 9. 10. MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; 11. Query OK, 1 row affected (0.00 sec) 12. 13. MariaDB [(none)]> create user zabbix@localhost identified by 'zabbix'; 14. Query OK, 0 rows affected (0.00 sec) 15. 16. MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost; 17. Query OK, 0 rows affected (0.00 sec) 18. 19. MariaDB [(none)]> set global log_bin_trust_function_creators = 1; 20. Query OK, 0 rows affected (0.00 sec) 21. 22. MariaDB [(none)]> quit; 23. Bye
8、导入数据库,初始化数据
1. [root@Zabbix ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix 2. Enter password: zabbix
可以进去检查一下
1. [root@Zabbix ~]# mysql -uroot 2. Welcome to the MariaDB monitor. Commands end with ; or \g. 3. Your MariaDB connection id is 5 4. Server version: 5.5.68-MariaDB MariaDB Server 5. 6. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. 7. 8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 9. 10. MariaDB [(none)]> use zabbix 11. Reading table information for completion of table and column names 12. You can turn off this feature to get a quicker startup with -A 13. 14. Database changed 15. MariaDB [zabbix]> show tables; 16. +----------------------------+ 17. | Tables_in_zabbix | 18. +----------------------------+ 19. | acknowledges | 20. | actions | 21. | alerts | 22. | application_discovery | 23. | application_prototype | 24. | application_template | 25. | applications | 26. | auditlog | 27. | auditlog_details | 28. | autoreg_host | 29. | conditions | 30. | config | 31. | config_autoreg_tls | 32. | corr_condition | 33. | corr_condition_group | 34. | corr_condition_tag | 35. | corr_condition_tagpair | 36. | corr_condition_tagvalue | 37. | corr_operation | 38. | correlation | 39. | dashboard | 40. | dashboard_user | 41. | dashboard_usrgrp | 42. | dbversion | 43. | dchecks | 44. | dhosts | 45. | drules | 46. | dservices | 47. | escalations | 48. | event_recovery | 49. | event_suppress | 50. | event_tag | 51. | events | 52. | expressions | 53. | functions | 54. | globalmacro | 55. | globalvars | 56. | graph_discovery | 57. | graph_theme | 58. | graphs | 59. | graphs_items | 60. | group_discovery | 61. | group_prototype | 62. | history | 63. | history_log | 64. | history_str | 65. | history_text | 66. | history_uint | 67. | host_discovery | 68. | host_inventory | 69. | host_tag | 70. | hostmacro | 71. | hosts | 72. | hosts_groups | 73. | hosts_templates | 74. | housekeeper | 75. | hstgrp | 76. | httpstep | 77. | httpstep_field | 78. | httpstepitem | 79. | httptest | 80. | httptest_field | 81. | httptestitem | 82. | icon_map | 83. | icon_mapping | 84. | ids | 85. | images | 86. | interface | 87. | interface_discovery | 88. | interface_snmp | 89. | item_application_prototype | 90. | item_condition | 91. | item_discovery | 92. | item_preproc | 93. | item_rtdata | 94. | items | 95. | items_applications | 96. | lld_macro_path | 97. | lld_override | 98. | lld_override_condition | 99. | lld_override_opdiscover | 100. | lld_override_operation | 101. | lld_override_ophistory | 102. | lld_override_opinventory | 103. | lld_override_opperiod | 104. | lld_override_opseverity | 105. | lld_override_opstatus | 106. | lld_override_optag | 107. | lld_override_optemplate | 108. | lld_override_optrends | 109. | maintenance_tag | 110. | maintenances | 111. | maintenances_groups | 112. | maintenances_hosts | 113. | maintenances_windows | 114. | mappings | 115. | media | 116. | media_type | 117. | media_type_message | 118. | media_type_param | 119. | module | 120. | opcommand | 121. | opcommand_grp | 122. | opcommand_hst | 123. | opconditions | 124. | operations | 125. | opgroup | 126. | opinventory | 127. | opmessage | 128. | opmessage_grp | 129. | opmessage_usr | 130. | optemplate | 131. | problem | 132. | problem_tag | 133. | profiles | 134. | proxy_autoreg_host | 135. | proxy_dhistory | 136. | proxy_history | 137. | regexps | 138. | rights | 139. | screen_user | 140. | screen_usrgrp | 141. | screens | 142. | screens_items | 143. | scripts | 144. | service_alarms | 145. | services | 146. | services_links | 147. | services_times | 148. | sessions | 149. | slides | 150. | slideshow_user | 151. | slideshow_usrgrp | 152. | slideshows | 153. | sysmap_element_trigger | 154. | sysmap_element_url | 155. | sysmap_shape | 156. | sysmap_url | 157. | sysmap_user | 158. | sysmap_usrgrp | 159. | sysmaps | 160. | sysmaps_elements | 161. | sysmaps_link_triggers | 162. | sysmaps_links | 163. | tag_filter | 164. | task | 165. | task_acknowledge | 166. | task_check_now | 167. | task_close_problem | 168. | task_data | 169. | task_remote_command | 170. | task_remote_command_result | 171. | task_result | 172. | timeperiods | 173. | trends | 174. | trends_uint | 175. | trigger_depends | 176. | trigger_discovery | 177. | trigger_tag | 178. | triggers | 179. | users | 180. | users_groups | 181. | usrgrp | 182. | valuemaps | 183. | widget | 184. | widget_field | 185. +----------------------------+ 186. 166 rows in set (0.00 sec)
9、再次配置数据库
1. [root@Zabbix ~]# mysql -uroot 2. Welcome to the MariaDB monitor. Commands end with ; or \g. 3. Your MariaDB connection id is 8 4. Server version: 5.5.68-MariaDB MariaDB Server 5. 6. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. 7. 8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 9. 10. MariaDB [(none)]> set global log_bin_trust_function_creators = 0; 11. Query OK, 0 rows affected (0.00 sec) 12. 13. MariaDB [(none)]> quit 14. Bye
10、修改zabbix连接数据库的信息
1. [root@Zabbix ~]# egrep ^DB /etc/zabbix/zabbix_server.conf 2. DBName=zabbix 3. DBUser=zabbix 4. DBPassword=zabbix #取消注释
11、修改时区
1. [root@Zabbix ~]# tail -1 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf 2. php_value[date.timezone] = Asia/Shanghai
12、启动zabbix进程
1. [root@Zabbix ~]# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm 2. [root@Zabbix ~]# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
13、浏览器访问安装