Linux监控平台搭建(一)--介绍

一 Linux监控平台介绍

常见开源监控软件

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

二 zabbix监控软件介绍

  1. C/S架构,基于C++开发,监控中心支持web界面配置和管理
    需要agent,意思是在客户端必需要有一个服务启动,这个服务是负责采集数据的,这个数据会主动地上报服务端,也可以让服务端去连接客户端抓取这个数据,因此这里就需要分两种模式:主动模式和被动模式
  2. 单server节点可以支持上万台客户端
    瓶颈在于采集数据的量,当服务器规模大到一定程度时就需要做一些优化了,比如说可以增加一些代理点proxy来充当server的角色,替代server去采集数据,然后他得到分析结果再汇报给server
  3. 最新版本3.4,官方文档https://www.zabbix.com/manuals
  4. 5个组件
  5. zabbix-server 监控中心,接收客户端上报信息,负责配置、统计、操作数据
  6. 数据存储 存放数据,比如mysql
  7. web界面 也叫web UI,在web界面下操作配置是zabbix简单易用的主要原因
  8. zabbix-proxy 可选组件,它可以代替zabbix-server的功能,减轻server的压力
  9. zabbix-agent 客户端软件,负责采集各个监控服务或项目的数据,并上报

zabbix监控流程图

输入图片说明

三 安装zabbix

  1. 官网下载地址 www.zabbix.com/download
  2. wget repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  3. rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm 实际上我们可以看到,安装这个包就是安装了一个yum源
[root@lijie-01 src]# ls !$ 
ls /etc/yum.repos.d/
CentOS7-Base-163.repo  CentOS-fasttrack.repo  CentOS-Vault.repo  zabbix.repo
CentOS-CR.repo         CentOS-Media.repo      epel.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo    epel-testing.repo
[root@lijie-01 src]# cat /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://repo.zabbix.com/zabbix/3.2/rhel/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch 
baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
[root@lijie-01 src]# 
  1. 安装zabbix服务器,前端,代理
# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql

其中zabbix-agent是客户端软件,zabbix-get是服务端上用的一个工具,这个工具是可以通过命令行的形式获得客户端上某些监控项目的数据,zabbix-server-mysql是安装一些跟mysql相关的文件,zabbix-web是web UI,zabbix-web-mysql是安装web和mysql相关的一些文件

  1. 会连带安装httpd和php
作为依赖被安装:
  OpenIPMI-libs.x86_64 0:2.0.19-15.el7          OpenIPMI-modalias.x86_64 0:2.0.19-15.el7    
  apr.x86_64 0:1.4.8-3.el7_4.1                  apr-util.x86_64 0:1.5.2-6.el7               
  dejavu-fonts-common.noarch 0:2.33-6.el7       dejavu-sans-fonts.noarch 0:2.33-6.el7       
  fontpackages-filesystem.noarch 0:1.44-8.el7   fping.x86_64 0:3.10-4.el7                   
  httpd.x86_64 0:2.4.6-67.el7.centos.6          httpd-tools.x86_64 0:2.4.6-67.el7.centos.6  
  iksemel.x86_64 0:1.4-6.el7                    libX11.x86_64 0:1.6.5-1.el7                 
  libX11-common.noarch 0:1.6.5-1.el7            libXau.x86_64 0:1.0.8-2.1.el7               
  libXpm.x86_64 0:3.5.12-1.el7                  libxcb.x86_64 0:1.12-1.el7                  
  libzip.x86_64 0:0.10.1-8.el7                  mailcap.noarch 0:2.1.41-2.el7               
  php.x86_64 0:5.4.16-43.el7_4.1                php-bcmath.x86_64 0:5.4.16-43.el7_4.1       
  php-cli.x86_64 0:5.4.16-43.el7_4.1            php-common.x86_64 0:5.4.16-43.el7_4.1       
  php-gd.x86_64 0:5.4.16-43.el7_4.1             php-ldap.x86_64 0:5.4.16-43.el7_4.1         
  php-mbstring.x86_64 0:5.4.16-43.el7_4.1       php-mysql.x86_64 0:5.4.16-43.el7_4.1        
  php-pdo.x86_64 0:5.4.16-43.el7_4.1            php-xml.x86_64 0:5.4.16-43.el7_4.1          
  t1lib.x86_64 0:5.1.2-14.el7                   unixODBC.x86_64 0:2.3.1-11.el7              
完毕!
  1. 如果mysql之前没有安装的话,需要根据lamp那一章的mysql安装方法安装mysql,然后启动mysql
# systemctl start mysql
  1. 编辑mysql配置文件vim /etc/my.cnf设置字符集为utf8 输入图片说明
  2. 重启mysqld服务后,登陆进入mysql命令行,创建zabbix库,同时指定字符集
[root@lijie-01 src]# mysql -uroot -p112233
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.36-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database zabbix character set utf8;
Query OK, 1 row affected (0.01 sec)
mysql> 
  1. 再创建用户,这个用户是让web代码连接mysql数据库的,zabbix服务启动的前提也是需要能够连接数据库的
mysql> grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by '112233';
Query OK, 0 rows affected (0.11 sec)
mysql> 
  1. 导入zabbix自带的数据
[root@lijie-01 src]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/       切换到自带数据所在目录
[root@lijie-01 zabbix-server-mysql-3.2.11]# ls    可以看到数据压缩包
AUTHORS  ChangeLog  COPYING  create.sql.gz  NEWS  README
[root@lijie-01 zabbix-server-mysql-3.2.11]# gzip -d create.sql.gz    解压
[root@lijie-01 zabbix-server-mysql-3.2.11]# ls
AUTHORS  ChangeLog  COPYING  create.sql  NEWS  README
[root@lijie-01 zabbix-server-mysql-3.2.11]# mysql -uroot -p112233 zabbix < create.sql  恢复数据到zabbix库
Warning: Using a password on the command line interface can be insecure.
[root@lijie-01 zabbix-server-mysql-3.2.11]# systemctl start zabbix-server  启动zabbix服务
[root@lijie-01 zabbix-server-mysql-3.2.11]# systemctl start httpd^C
  1. 启动httpd服务
[root@lijie-01 zabbix-server-mysql-3.2.11]# ps aux |grep nginx   查看nginx是否占用80端口
root      6716  0.0  0.0 112676   984 pts/0    S+   17:15   0:00 grep --color=auto nginx
[root@lijie-01 zabbix-server-mysql-3.2.11]# systemctl start httpd  启动httpd服务      
[root@lijie-01 zabbix-server-mysql-3.2.11]# systemctl enable httpd     
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@lijie-01 zabbix-server-mysql-3.2.11]# 
  1. 修改配置文件vim /etc/zabbix/zabbix_server.conf 配置连接数据库主机的账号密码
    DBHost=127.0.0.1 //在DBName=zabbix上面增加
    DBName=zabbix
    DBUser=zabbix
    DBPassword=112233 //在DBuser下面增加
  2. netstat -lntp |grep zabbix //查看监听端口
[root@lijie-01 ~]# systemctl start zabbix-server
[root@lijie-01 ~]# systemctl enable zabbix-server
[root@lijie-01 zabbix-server-mysql-3.2.11]# systemctl disable nginx   禁止nginx启动
nginx.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig nginx off
[root@lijie-01 zabbix-server-mysql-3.2.11]# chkconfig nginx off
[root@lijie-01 ~]# ps aux |grep zabbix   
zabbix    7388  2.0  0.2 254760  4168 ?        S    00:16   0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
zabbix    7391  0.0  0.1 254760  2520 ?        S    00:16   0:00 /usr/sbin/zabbix_server: configuration syncer [waiting 60 sec for processes]
zabbix    7392  0.0  0.1 254760  2732 ?        S    00:16   0:00 /usr/sbin/zabbix_server: db watchdog [synced alerts config in 0.004178 sec, idle 60 sec]
zabbix    7393  0.8  0.2 361704  5244 ?        S    00:16   0:00 /usr/sbin/zabbix_server: poller #1 [got 0 values in 0.000009 sec, idle 5 sec]
zabbix    7394  1.1  0.2 361704  5244 ?        S    00:16   0:00 /usr/sbin/zabbix_server: poller #2 [got 0 values in 0.000010 sec, idle 5 sec]
zabbix    7395  1.1  0.2 361704  5244 ?        S    00:16   0:00 /usr/sbin/zabbix_server: poller #3 [got 0 values in 0.000008 sec, idle 5 sec]
zabbix    7396  1.1  0.2 361704  5244 ?        S    00:16   0:00 /usr/sbin/zabbix_server: poller #4 [got 0 values in 0.000247 sec, idle 5 sec]
zabbix    7397  1.0  0.2 361704  5244 ?        S    00:16   0:00 /usr/sbin/zabbix_server: poller #5 [got 0 values in 0.000008 sec, idle 5 sec]
zabbix    7398  1.4  0.2 361704  5244 ?        S    00:16   0:00 /usr/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000008 sec, idle 5 sec]
zabbix    7399  0.3  0.1 254760  3628 ?        S    00:16   0:00 /usr/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting for connection]
zabbix    7400  0.1  0.1 254760  3624 ?        S    00:16   0:00 /usr/sbin/zabbix_server: trapper #2 [processed data in 0.000000 sec, waiting for connection]
zabbix    7401  0.0  0.1 254760  3628 ?        S    00:16   0:00 /usr/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting for connection]
zabbix    7402  0.0  0.1 254760  3628 ?        S    00:16   0:00 /usr/sbin/zabbix_server: trapper #4 [processed data in 0.000000 sec, waiting for connection]
zabbix    7403  0.0  0.1 254760  3628 ?        S    00:16   0:00 /usr/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting for connection]
zabbix    7407  0.0  0.1 257336  2660 ?        S    00:16   0:00 /usr/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000004 sec, idle 5 sec]
zabbix    7408  0.0  0.1 254760  2736 ?        S    00:16   0:00 /usr/sbin/zabbix_server: alerter [sent alerts: 0 success, 0 fail in 0.004105 sec, idle 30 sec]
zabbix    7410  0.0  0.1 254760  2516 ?        S    00:16   0:00 /usr/sbin/zabbix_server: housekeeper [startup idle for 30 minutes]
zabbix    7411  0.0  0.1 254760  2736 ?        S    00:16   0:00 /usr/sbin/zabbix_server: timer #1 [processed 0 triggers, 0 events in 0.000000 sec, 0 maintenances in 0.000000 sec, idle 21 sec]
zabbix    7413  0.1  0.1 254760  2876 ?        S    00:16   0:00 /usr/sbin/zabbix_server: http poller #1 [got 0 values in 0.001905 sec, idle 5 sec]
zabbix    7414  1.4  0.2 359120  5032 ?        S    00:16   0:00 /usr/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.009963 sec, idle 60 sec]
zabbix    7416  0.0  0.1 254760  2864 ?        S    00:16   0:00 /usr/sbin/zabbix_server: history syncer #1 [synced 0 items in 0.000001 sec, idle 1 sec]
zabbix    7418  0.0  0.1 254760  2864 ?        S    00:16   0:00 /usr/sbin/zabbix_server: history syncer #2 [synced 0 items in 0.000003 sec, idle 1 sec]
zabbix    7420  0.0  0.1 254760  2864 ?        S    00:16   0:00 /usr/sbin/zabbix_server: history syncer #3 [synced 0 items in 0.000002 sec, idle 1 sec]
zabbix    7422  0.0  0.1 254760  2864 ?        S    00:16   0:00 /usr/sbin/zabbix_server: history syncer #4 [synced 0 items in 0.000002 sec, idle 1 sec]
zabbix    7424  0.2  0.2 254760  3808 ?        S    00:16   0:00 /usr/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.004486 sec, idle 3 sec]
zabbix    7425  0.1  0.2 254760  3808 ?        S    00:16   0:00 /usr/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000006 sec, idle 5 sec]
zabbix    7426  0.0  0.1 254760  2628 ?        S    00:16   0:00 /usr/sbin/zabbix_server: self-monitoring [processed data in 0.000009 sec, idle 1 sec]
zabbix    7428  0.0  0.1 254760  2852 ?        S    00:16   0:00 /usr/sbin/zabbix_server: task manager [processed 0 task(s) in 0.003621 sec, idle 5 sec]
root      7439  0.0  0.0 112680   984 pts/1    S+   00:16   0:00 grep --color=auto zabbix
[root@lijie-01 ~]# netstat -lntp |grep zabbix
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      7388/zabbix_server  
tcp6       0      0 :::10051                :::*                    LISTEN      7388/zabbix_server  
[root@lijie-01 ~]# 
  1. 配置web界面 打开浏览器访问http://192.168.75.136/zabbix/ web界面下面配置zabbix 输入图片说明
    点击下一步,进入以下页面,OK的选项我们不用管,可以看到有一个fail项,timezone时区fail, 输入图片说明 这时我们需要去php的配置文件/etc/php.ini中找到timezone,设置date.timezone=Asia/shanghai 或者 chongqin,配置完成后需要重启apache服务,重启后再来刷新刚才的页面,可以看到时区已经OK 输入图片说明 然后点击下一步,这里我们就需要填写mysql相关的信息 输入图片说明 点击下一步 输入图片说明 再下一步 输入图片说明 下一步 输入图片说明
  2. 登录 点击完成,进入登录界面,填写登录信息 输入图片说明
    使用默认用户名Admin 密码zabbix登录后,进入首页如下 输入图片说明
  3. 进入后台第一件事情就是修改密码 按照下图顺序进入admin用户个人信息中心 输入图片说明 进入后,点击修改密码,填写两次新密码,同时可以将语言修改为中文 输入图片说明 修改完成后点击下方的update更新设置,然后刷新一下,界面就变成中文了 输入图片说明

四 忘记Admin密码怎么办

忘记密码我们可以直接进入mysql的zabbix库users表中修改数据库数据就可以了

  1. 进入mysql命令行,选择zabbix库
[root@lijie-01 ~]# mysql -uroot -p112233
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 464
Server version: 5.6.36-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> 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
mysql> 
  1. 更改密码
mysql> update users set passwd=md5('112233') where alias='Admin';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

这样就更改了Admin用户的密码

五 zabbix客户端安装

  1. 在客户端上也需要下载zabbix的yum源
# wget repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  1. 安装yum源
# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm 
  1. 安装客户端
# yum install -y zabbix-agent   
  1. vim /etc/zabbix/zabbix_agentd.conf //修改如下配置
    Server=127.0.0.1修改为Server=192.168.75.136 //定义服务端的ip(被动模式) ServerActive=127.0.0.1修改为ServerActive=192.168.75.136 //定义服务端的ip(主动模式)
    Hostname=Zabbix server修改为Hostname=lijie-01 //这是自定义的主机名,一会还需要在web界面下设置同样的主机名
  2. systemctl start zabbix-agent
[root@lijie-02 src]# systemctl start zabbix-agent
[root@lijie-02 src]# ps aux |grep zabbix
zabbix   50606  0.0  0.0  82964  1272 ?        S    01:46   0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
zabbix   50607  0.0  0.0  82964  1432 ?        S    01:46   0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix   50608  0.0  0.0  82964  1852 ?        S    01:46   0:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix   50609  0.0  0.0  82964  1852 ?        S    01:46   0:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix   50610  0.0  0.0  82964  1852 ?        S    01:46   0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix   50611  0.0  0.1  83096  2208 ?        S    01:46   0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root     50621  0.0  0.0 112680   980 pts/1    S+   01:46   0:00 grep --color=auto zabbi
[root@lijie-02 src]# netstat -lntp |grep zabbix    可以看到监控的端口为10050
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      50606/zabbix_agentd 
tcp6       0      0 :::10050                :::*                    LISTEN      50606/zabbix_agentd 
  1. systemctl enable zabbix-agent
[root@lijie-02 src]# systemctl enable zabbix-agent
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
[root@lijie-02 src]# 

猜你喜欢

转载自my.oschina.net/u/3746774/blog/1794711
今日推荐