监控的软件
一、开源的软件
1. Nagios
Nagios于1999年首次推出,现已发展到包括由全球Nagios社区开发的数千个项目。Nagios由Nagios Enterprises正式赞助,Nagios Enterprises通过销售其商业产品和服务以多种不同方式支持社区。
Nagios监控您的整个IT基础架构,以确保系统、应用程序、服务和业务流程正常运行。如果发生故障,Nagios可以提醒技术人员注意问题,允许他们在中断影响业务流程、最终用户或客户之前开始补救过程。有了Nagios,你永远不必解释为什么看不见的基础设施中断会损害你组织的底线。
2. cacti
3. zabbix
4.open-falcon
5.prometheus
6.netdata
优点: 费用低廉
缺点: 不能做到完全的定制,和你公司的业务完全的吻合
二、自研
缺点: 需要专门的人员去开发,成本比较高,今后的维护也比较多
优点:完全符合公司的业务特点
为什么需要监控?
1.需要保障业务时时刻刻正常的运转,一旦出现问题,需要马上知道,赶紧修复
2.解放人力,提升效率
zabbix是什么?
zabbix是一个监控软件,可以监控以下方面
zabbix的组件
1.Zabbix Web GUI: 提供Web界面
2.Zabbix Database:提供数据存储功能,专用于存储配置信息,以及采集到的数据
3.Zabbix Server: 接收Agent采集数据的核心组件。
4.Zabbix Agent: 部署在被监控主机上,用于采集本地数据。
5.Zabbix Proxy: 当被监控节点较多时,用于减轻Server压力的组件,也用于分布式监控系统。由Proxy接收数据后统一发送至Server。
环境准备
1.centos7的系统
[root@zabbix ~]# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)
2.安装zabbix
部署zabbix
1.安装zabbix服务器的源
源:repository 软件仓库,用来找到zabbix官方网站提供的软件,可以下载软件的地方
[root@zabbix ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
获取https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
警告:/var/tmp/rpm-tmp.AWU1lB: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:zabbix-release-5.0-1.el7 ################################# [100%]
[root@zabbix ~]# cd /etc/yum.repos.d/
[root@zabbix yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo zabbix.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo CentOS-x86_64-kernel.repo
CentOS-Base.repo 仓库文件: 用来找到centos官方提供的下载软件的地方的文件
Base 存放centos官方基本软件的仓库
zabbix.repo 帮助我们找到zabbix官方提供的软件下载地方的文件
[root@zabbix yum.repos.d]# cat zabbix.repo
[zabbix] # 的名字
name=Zabbix Official Repository - $basearch # 对这个源的介绍
baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/ # 具体源的位置
enabled=1 # 表示这个源可以使用
gpgcheck=1 # 操作系统会对下载的软件进行gpg检验码的检查,防止软件不是正版的
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 # --》防伪码
2.安装zabbix相关的软件
[root@zabbix yum.repos.d]# yum install zabbix-server-mysql zabbix-agent -y
zabbix-server-mysql 安装zabbix server和连接mysql功能的软件
zabbix-agent zabbix的代理软件
3.安装Zabbix前端
[root@zabbix yum.repos.d]# yum install centos-release-scl -y
修改仓库文件,启用前端的源
[root@zabbix yum.repos.d]# vim zabbix.repo
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1 # 修改为1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
安装web相关的软件
[root@zabbix yum.repos.d]# yum install zabbix-web-mysql-scl zabbix-nginx-conf-scl -y
4.安装mariadb数据库
[root@zabbix yum.repos.d]# yum install mariadb mariadb-server -y
mariadb-server 服务器端的软件包
mariadb 提供客户端命令的软件包
注意:如果已经安装过mysql的centos系统,不需要安装mariadb
[root@zabbix yum.repos.d]# service mariadb start # 启动mariadb
Redirecting to /bin/systemctl start mariadb.service
[root@zabbix yum.repos.d]# systemctl enable mariadb # 设置开机启动mariadb数据库
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
查看mysqld进程运行
[root@zabbix yum.repos.d]# ps aux|grep mysqld
mysql 7626 0.1 0.0 113408 1632 ? Ss 23:00 0:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql 7791 1.7 4.3 968920 80816 ? Sl 23:00 0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root 7845 0.0 0.0 112824 984 pts/0 S+ 23:00 0:00 grep --color=auto mysqld
[root@zabbix yum.repos.d]# netstat -anplut | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 7791/mysqld
5.在数据库主机上运行以下命令
[root@zabbix yum.repos.d]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (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; # 创建zabbix数据库
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases; #查看当前MySQL里有哪些库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> create user zabbix@localhost identified by 'sc123456'; # 创建用户zabbix@localhost 密码是sc123456
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost; #授权zabbix@localhost用户对zabbix.*库里的表有所有的权限(insert,delete,update,select等)
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)]> exit
Bye
导入初始化数据,会在zabbix库里新建很多的表
cd /usr/share/doc/zabbix-server-mysql-5.0.33/
[root@zabbix zabbix-server-mysql-5.0.33]# ls
AUTHORS ChangeLog COPYING create.sql.gz double.sql NEWS README
[root@zabbix zabbix-server-mysql-5.0.33]# zcat create.sql.gz |mysql -uzabbix -p'sc123456' zabbix
[root@zabbix zabbix-server-mysql-5.0.33]# mysql -uzabbix -psc123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
| zabbix |
+--------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> use zabbix
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
导入数据库架构后禁用log_bin_trust_function_creators选项
[root@zabbix zabbix-server-mysql-5.0.33]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (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)]> exit
Bye
6.为 Zabbix 服务器配置数据库
编辑文件 /etc/zabbix/zabbix_server.conf
[root@zabbix zabbix-server-mysql-5.0.33]# cd /etc/zabbix/
[root@zabbix zabbix]# vim zabbix_server.conf
# DBPassword=
DBPassword=sc123456
7.为 Zabbix 前端配置 PHP
编辑文件 /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf 取消注释
[root@zabbix conf.d]# cd /etc/opt/rh/rh-nginx116/nginx/conf.d/
[root@zabbix conf.d]# ls
zabbix.conf
[root@zabbix conf.d]# vim zabbix.conf
server {
listen 80;
server_name example.com;
编辑/etc/opt/rh/rh-nginx116/nginx/nginx.conf
[root@zabbix php-fpm.d]# cd /etc/opt/rh/rh-nginx116/nginx/
[root@zabbix nginx]# vim nginx.conf
server {
listen 8080 default_server; #修改80为8080
listen [::]:8080 default_server;
避免zabbix和nginx监听同一个端口,导致zabbix启动不起来。
编辑文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
[root@zabbix zabbix]# cd /etc/opt/rh/rh-php72/php-fpm.d
[root@zabbix php-fpm.d]# ls
www.conf zabbix.conf
[root@zabbix php-fpm.d]# vim zabbix.conf
listen.acl_users = apache,nginx
php_value[date.timezone] = Asia/Shanghai
8.关闭firewalld防火墙并且设置开机不启动
[root@zabbix php-fpm.d]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
[root@zabbix php-fpm.d]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
关闭selinux安全机制,临时和永久都关闭
[root@zabbix php-fpm.d]# getenforce
Enforcing
[root@zabbix php-fpm.d]# setenforce 0 # 临时关闭selinux
[root@zabbix php-fpm.d]# vim /etc/sysconfig/selinux
SELINUX=disabled
# 或者
[root@zabbix php-fpm.d]# vim /etc/selinux/config
SELINUX=disabled
建议一定要关闭selinux,不然会导致zabbix_server启动不了
9.启动Zabbix服务器和代理进程并且设置开机启动
[root@zabbix php-fpm.d]# systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
[root@zabbix php-fpm.d]# systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/rh-nginx116-nginx.service to /usr/lib/systemd/system/rh-nginx116-nginx.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/rh-php72-php-fpm.service to /usr/lib/systemd/system/rh-php72-php-fpm.service.
10.浏览器里访问
默认登录的账号和密码
username: Admin
password: zabbix