当前位置:   article > 正文

Linux监控平台介绍及Zabbix安装配置

alerter [connecting to the database]

常见的开源监控软件

  • cacti、nagios、zabbix、smokeping、open-falcon
  • cacti、smokeping偏向于基础监控,成图非常漂亮
  • cacti、nagios、zabbix服务端监控中心,需要php环境支持,其中zabbix和cacti都需要mysql作为数据存储,nagios不用存储历史数据,注重服务或者监控项的状态,zabbix会获取服务或者监控项目的数据,会把数据记录到数据库里,从而可以成图
  • open-falcon为小米公司开发,开源后受到诸多大公司和运维工程师的追捧,适合大企业,滴滴、360、新浪微博、京东等大公司在使用这款监控软件,值得研究

zabbix 监控介绍

  • C/S架构,基于C++开发,监控中心支持web界面配置和管理

  • 单个server节点可以支持上万台客户端

  • 官方文档https://www.zabbix.com/manuals

  • 5个组件

    • zabbix-server 监控中心,接收客户端上报信息,负责配置、统计、操作数据
    • 数据存储 存放数据,比如mysql
    • web界面 也叫web UI,在web界面下操作配置是zabbix简单易用的主要原因
    • zabbix-proxy 可选组件,它可以代替zabbix-server的功能,减轻server的压力
    • zabbix-agent 客户端软件,负责采集各个监控服务或项目的数据,并上报

监控流程图

安装zabbix

在两台机器上安装,一台是服务端(test-a:192.168.77.134),一台是客户端(centos0:192.168.77.129)。

第一步,服务端安装zabbix,导入数据,启动服务

  1. [root@test-a ~]# wget https://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm # 下载不下来,就通过浏览器下载后上传
  2. [root@test-a ~]# rpm -ivh zabbix-release-3.4-2.el7.noarch.rpm # 安装rpm
  3. warning: zabbix-release-3.4-2.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
  4. Preparing... ################################# [100%]
  5. Updating / installing...
  6. 1:zabbix-release-3.4-2.el7 ################################# [100%]
  7. [root@test-a ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql # 安装相关的工具包
  8. # zabbix-agent 客户端工具
  9. # zabbix-get 服务端工具,获取客户端收集的相关监控数据
  10. # zabbix-server-mysql 服务端工具,和mysql相关的工具
  11. # zabbix-web 服务端工具,监控展示网页工具
  12. # zabbix-web-mysql 服务端工具,网页与mysql相关的工具
  13. # 创建zabbix的mysql库及用户,并导入初始数据
  14. [root@test-a ~]# ps aux|grep mysql
  15. root 2234 0.0 0.1 115436 1728 ? S 08:46 0:00 /bin/sh /usr/local/mysql/bin/mysqd_safe --datadir=/data/mysql --pid-file=/usr/local/mysql/mysqld.pid
  16. mysql 2463 0.1 18.4 1117940 186076 ? Sl 08:46 0:02 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/db.err --pid-file=/usr/local/mysql/mysqld.pid --socket=/usr/local/mysqlmysql.sock --port=3306
  17. root 2777 0.0 0.0 112704 972 pts/0 S+ 09:12 0:00 grep --color=auto mysql
  18. # mysql 的配置需要添加character-set-server = utf8,使支持中文
  19. [root@test-a ~]# mysql -uroot -p
  20. Enter password:
  21. Welcome to the MySQL monitor. Commands end with ; or \g.
  22. Your MySQL connection id is 3
  23. Server version: 5.7.23-log MySQL Community Server (GPL)
  24. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  25. Oracle is a registered trademark of Oracle Corporation and/or its
  26. affiliates. Other names may be trademarks of their respective
  27. owners.
  28. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  29. mysql> create database zabbix character set utf8; -- 创建库
  30. Query OK, 1 row affected (0.04 sec)
  31. mysql> grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'test111'; -- 添加用户及授权
  32. Query OK, 0 rows affected, 1 warning (0.30 sec)
  33. mysql> quit
  34. Bye
  35. [root@test-a ~]# cd /usr/share/doc/zabbix-server-mysql-3.4.15/
  36. [root@test-a zabbix-server-mysql-3.4.15]# ls
  37. AUTHORS ChangeLog COPYING create.sql.gz NEWS README
  38. [root@test-a zabbix-server-mysql-3.4.15]# cp create.sql.gz create.sql.gz.default # 备份一下
  39. [root@test-a zabbix-server-mysql-3.4.15]# gzip -d create.sql.gz # 解压
  40. [root@test-a zabbix-server-mysql-3.4.15]# ls
  41. AUTHORS ChangeLog COPYING create.sql create.sql.gz.default NEWS README
  42. [root@test-a zabbix-server-mysql-3.4.15]# mysql -uroot -ptest111 zabbix < create.sql # 导入数据,需要几秒导入
  43. mysql: [Warning] Using a password on the command line interface can be insecure.
  44. [root@test-a ~]# vim /etc/zabbix/zabbix_server.conf # 配置DBHost=127.0.0.1 和 DBPassword=test111,就是刚授权的ip及密码
  45. [root@test-a ~]# systemctl start zabbix-server
  46. [root@test-a ~]# ps -aux|grep zabbix
  47. zabbix 3164 45.5 0.3 254608 4036 ? R 09:35 0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
  48. zabbix 3167 0.0 0.2 254608 2316 ? S 09:35 0:00 /usr/sbin/zabbix_server: configuration syncer [waiting 60 sec for processes]
  49. zabbix 3168 0.0 0.2 254608 2320 ? S 09:35 0:00 /usr/sbin/zabbix_server: alerter [connecting to the database]
  50. zabbix 3169 0.0 0.2 254608 2320 ? S 09:35 0:00 /usr/sbin/zabbix_server: alerter [connecting to the database]
  51. zabbix 3170 0.0 0.2 254608 2320 ? S 09:35 0:00 /usr/sbin/zabbix_server: alerter [connecting to the database]
  52. zabbix 3171 0.0 0.2 254608 2316 ? S 09:35 0:00 /usr/sbin/zabbix_server: housekeeper [startup idle for 30 minutes]
  53. zabbix 3172 0.5 0.2 254608 2548 ? S 09:35 0:00 /usr/sbin/zabbix_server: timer #1 [processed 0 triggers, 0 events in 0.000000 sec, 0 maintenances in 0.000000 sec, idle 8 sec]
  54. zabbix 3173 0.0 0.2 254604 2644 ? S 09:35 0:00 /usr/sbin/zabbix_server: http poller #1 [got 0 values in 0.104076 sec, idle 5 sec]
  55. zabbix 3174 6.0 0.3 358328 3916 ? D 09:35 0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
  56. zabbix 3175 2.0 0.2 254604 2644 ? S 09:35 0:00 /usr/sbin/zabbix_server: history syncer #1 [synced 0 items in 0.000042 sec, idle 1 sec]
  57. zabbix 3177 0.0 0.2 254604 2644 ? S 09:35 0:00 /usr/sbin/zabbix_server: history syncer #2 [synced 0 items in 0.000040 sec, idle 1 sec]
  58. zabbix 3179 0.0 0.2 254604 2644 ? S 09:35 0:00 /usr/sbin/zabbix_server: history syncer #3 [synced 0 items in 0.000029 sec, idle 1 sec]
  59. zabbix 3181 2.0 0.2 254604 2644 ? S 09:35 0:00 /usr/sbin/zabbix_server: history syncer #4 [synced 0 items in 0.000024 sec, idle 1 sec]
  60. zabbix 3183 2.0 0.3 254608 3576 ? S 09:35 0:00 /usr/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.051954 sec, idle 3 sec]
  61. zabbix 3185 3.0 0.3 254608 3580 ? S 09:35 0:00 /usr/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000584 sec, idle 5 sec]
  62. zabbix 3187 0.0 0.2 254608 2408 ? S 09:35 0:00 /usr/sbin/zabbix_server: self-monitoring [processed data in 0.000440 sec, idle 1 sec]
  63. zabbix 3188 0.0 0.2 254608 2552 ? S 09:35 0:00 /usr/sbin/zabbix_server: task manager [started, idle 1 sec]
  64. zabbix 3189 0.0 0.3 358328 3916 ? R 09:35 0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
  65. zabbix 3191 0.0 0.3 358328 3916 ? D 09:35 0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
  66. root 3193 0.0 0.0 112704 972 pts/0 S+ 09:35 0:00 grep --color=auto zabbix
  67. [root@test-a ~]# netstat -ntlp # 查看zabbix的监听端口: 10051 说明启动成功,如果启动报错了,根据日志(/var/log/zabbix/zabbix_server.log)解决问题
  68. Active Internet connections (only servers)
  69. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  70. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2465/master
  71. tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
  72. tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 3164/zabbix_server
  73. tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
  74. tcp 0 0 0.0.0.0:44016 0.0.0.0:* LISTEN -
  75. tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 1313/rpc.mountd
  76. tcp 0 0 0.0.0.0:56497 0.0.0.0:* LISTEN 1231/rpc.statd
  77. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1214/sshd
  78. tcp6 0 0 ::1:25 :::* LISTEN 2465/master
  79. tcp6 0 0 :::51514 :::* LISTEN 1231/rpc.statd
  80. tcp6 0 0 :::2049 :::* LISTEN -
  81. tcp6 0 0 :::10051 :::* LISTEN 3164/zabbix_server
  82. tcp6 0 0 :::55049 :::* LISTEN -
  83. tcp6 0 0 :::3306 :::* LISTEN 2463/mysqld
  84. tcp6 0 0 :::111 :::* LISTEN 1/systemd
  85. tcp6 0 0 :::80 :::* LISTEN 2999/httpd
  86. tcp6 0 0 :::20048 :::* LISTEN 1313/rpc.mountd
  87. tcp6 0 0 :::22 :::* LISTEN 1214/sshd

第二步,网页配置(server-ip/zabbix)
访问 http://192.168.77.134/zabbix,会出来安装界面

点击 next step,会发现有红色提示,那是因为php没有配置时区,早/etc/php.ini中配置date.timezone = Asia/Shanghai后,重启apache,重新刷新网页就没有提示了

然后输入mysql相关配置,点击next step安装完成啦

到登录页面输入默认账户admin,密码zabbix,登录

登录成功后,首先更改密码和系统语言

点Change password进行密码替换,下面的Language选择Chinese

刷新主页

zabbix服务名

第三步,客户端安装及配置启动

  1. [root@centos0 ~]# rpm -ivh zabbix-release-3.4-2.el7.noarch.rpm
  2. 警告:zabbix-release-3.4-2.el7.noarch.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
  3. 准备中... ################################# [100%]
  4. 正在升级/安装...
  5. 1:zabbix-release-3.4-2.el7 ################################# [100%]
  6. [root@centos0 ~]# yum install -y zabbix-agent
  7. [root@centos0 ~]# vim /etc/zabbix/zabbix_agentd.conf # 更改Server, ServerActive为对应的zabbix服务器IP, Hostname为对应的zabbix服务名称(不是主机名,web工具安装时配置的,不记得了可以在web里去找)
  8. [root@centos0 ~]# systemctl start zabbix-agent
  9. [root@centos0 ~]# netstat -ntlp # 监听的端口是10050
  10. Active Internet connections (only servers)
  11. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  12. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3550/master
  13. tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 3989/zabbix_agentd
  14. tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
  15. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2599/sshd
  16. tcp6 0 0 ::1:25 :::* LISTEN 3550/master
  17. tcp6 0 0 :::10050 :::* LISTEN 3989/zabbix_agentd
  18. tcp6 0 0 :::111 :::* LISTEN 1/systemd
  19. tcp6 0 0 :::22 :::* LISTEN 2599/sshd

忘记了Zabbix web工具admin密码如何处理

进入mysql,选择zabbix库及users表,更改对应用户的密码即可,

  1. [root@test-a logs]# mysql -uroot -p
  2. Enter password:
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 331
  5. Server version: 5.7.23-log MySQL Community Server (GPL)
  6. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql> use zabbix;
  12. Reading table information for completion of table and column names
  13. You can turn off this feature to get a quicker startup with -A
  14. Database changed
  15. mysql> desc users;
  16. +----------------+---------------------+------+-----+---------+-------+
  17. | Field | Type | Null | Key | Default | Extra |
  18. +----------------+---------------------+------+-----+---------+-------+
  19. | userid | bigint(20) unsigned | NO | PRI | NULL | |
  20. | alias | varchar(100) | NO | UNI | | |
  21. | name | varchar(100) | NO | | | |
  22. | surname | varchar(100) | NO | | | |
  23. | passwd | char(32) | NO | | | |
  24. | url | varchar(255) | NO | | | |
  25. | autologin | int(11) | NO | | 0 | |
  26. | autologout | varchar(32) | NO | | 15m | |
  27. | lang | varchar(5) | NO | | en_GB | |
  28. | refresh | varchar(32) | NO | | 30s | |
  29. | type | int(11) | NO | | 1 | |
  30. | theme | varchar(128) | NO | | default | |
  31. | attempt_failed | int(11) | NO | | 0 | |
  32. | attempt_ip | varchar(39) | NO | | | |
  33. | attempt_clock | int(11) | NO | | 0 | |
  34. | rows_per_page | int(11) | NO | | 50 | |
  35. +----------------+---------------------+------+-----+---------+-------+
  36. 16 rows in set (0.31 sec)
  37. mysql> update users set passwd=md5('test111') where alias='Admin'; # 设置新密码为test111
  38. Query OK, 0 rows affected (0.10 sec)
  39. Rows matched: 1 Changed: 0 Warnings: 0

转载于:https://my.oschina.net/u/996931/blog/2992780

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/49159
推荐阅读
相关标签
  

闽ICP备14008679号