Linux基础(day66)

19.1 Linux监控平台介绍

Linux监控平台介绍

  • 监控存在的缘由
    • 站点出了问题,没有人知道,等用户发现了,才提醒供应商;对公司影响很大
  • 常见开源监控软件
    • cacti、nagios、zabbix、smokeping、open-falcon等等,其中nagios、zabbix流行度很是高
    • cacti、smokeping偏向于基础监控,成图很是漂亮,适合监控网络设备
      • cacti监控网络的设备
    • cacti、nagios、zabbix服务端监控中心,须要php环境支持(用Apache的php,用nginx的php均可以),其中zabbix和cacti都须要mysql做为数据存储,nagios不用存储历史数据,注重服务或者监控项的状态,zabbix会获取服务或者监控项目的数据,会把数据记录到数据库里,从而能够成图
      • 由于zabbix配置简单,优点明显,早起使用nagios的企业,慢慢的转向使用zabbix
      • nagios,须要更改配置文件,并不支持web界面一键执行,nagios和zabbix相比,
        • nagios 更注重的是某一个监控的状态,不关注历史;
        • zabbix,则是把每一次监控的数值反馈出来,数值存到数据库里面,方便后期数据图去分析监控整个状态;
        • nagios不须要mysql的支持,不能成图,若须要画图,得安装插件之后才支持web界面;
        • ccti 也须要mysql的支持,也能够成图,能够记录历史数据
      • zabbix 在web界面下管理得很是完全,能够增长监控节点,报警预知等等
    • open-falcon为小米公司开发,开源后受到诸多大公司和运维工程师的追捧,适合大企业,滴滴、360、新浪微博、京东等大公司在使用这款监控软件,值得研究
      • open-falcon软件适合大企业使用,小企业能够去研究它的思想
  • 后续以介绍zabbix为主

19.2 zabbix监控介绍

zabbix监控介绍

  • C/S架构,基于C++开发,监控中心支持web界面配置和管理
    • zabbix软件,是C/S架构:有一个服务端,去客户端抓数据。在客户端必需要有一个服务启动运行才能够抓取数据;数据能够主动的上报服务端,也可让服务端去链接客户端获取(经过抓取数据方式,数据获取分两个模式,一个主动模式,一个被动模式),zabbix软件基于C++开发,监控中心须要一个PHP的web环境,由于要开启一个web界面配置和管理
  • 单台server节点(即一台server),理论上 能够支持上万台客户端
    • 瓶颈:在于采集数据的量,虽然支持上万台,但监控的项目过多,仍是会致使zabbix效率下降;因此,当服务器大到必定规模的时候,就须要对zabbix进行优化
    • 解决方法:能够增长一些代理点,这些代理点充当server,替代server去采集数据,最终获得分析结果再汇报给主服务端server
  • 目前zabbix软件,最新版本3.4,官方文档
    • 更新快,使用的用户多
  • zabbix架构里,包括了5个组件:
    • zabbix-server 监控中心,接收客户端上报信息,负责配置、统计、操做数据
    • 数据存储 存放数据,好比mysql
    • web界面 也叫web UI,在web界面下操做配置是zabbix简单易用的主要缘由(若是没有web界面,就没法在浏览器上配置它)
    • zabbix-proxy 可选组件,它能够代替zabbix-server的功能,减轻server的压力(当机器量不少的时候,可使用zabbix-proxy)
      • 有时候,服务器分布在多个机房里,每一个机房的服务器之间都是一个单独的内网,这时候就能够在某一个局域网里搭建一个 zabbix-proxy ,用这台 proxy 去监控局域网里的机器
    • zabbix-agent 客户端软件(每一台客户端都须要安装agent),负责采集各个监控服务或项目的数据,并上报

监控流程图:

输入图片说明

19.3/19.4/19.6 安装zabbix

安装zabbix

  • 官网下载地址
  • wget repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  • rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
  • yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
  • 会连带安装httpd和php
  • 若是mysql以前没有安装的话,须要根据lamp那一章的mysql安装方法安装mysql
  • vim /etc/my.cnf //须要增长配置
character_set_server = utf8
  • 重启mysqld服务后,进入mysql命令行,建立zabbix库
    • create database zabbix character set utf8;
  • 再建立用户
    • grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'aming-zabbix';
  • 导入数据
  • cd /usr/share/doc/zabbix-server-mysql-3.2.7
  • gzip -d create.sql.gz
  • mysql -uroot -pxxx zabbix < create.sql
  • systemctl start httpd; systemctl enable httpd
  • vim /etc/zabbix/zabbix_server.conf //修改或增长
DBHost=127.0.0.1 //在DBName=zabbix上面增长
DBPassword=aming-zabbix //在DBuser下面增长
  • systemctl start zabbix-server
  • systemctl enable zabbix-server
  • netstat -lntp |grep zabbix //查看监听端口
  • 浏览器访问http://ip/zabbix/ web界面下面配置zabbix
  • 用户名Admin 密码zabbix
  • 进入后台第一件事情就是修改密码

安装zabbix

  • 准备工做
    • 两台机器,一台做为服务端(监控中心),另一台做为它的客户端
  • 背景
    • zabbix,能够直接yum安装,但须要安装epel扩展源,在epel扩展源里面安装的zabbix的版本,最高是2.2版本,比较旧,因此使用官方提供的repo源
  • 这里实验使用的zabbix3.2版本
  1. 首先访问官网下载地址,选择对应的版本,并提供对应的发行版,而后选择download,跳转到一个界面,找到这个rpm包(包含release),也就是说yum源在这个里面,下图所示,复制该连接

输入图片说明

  1. 在两台机器都须要下载它
A机器
[root@hf-01 ~]# wget wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm

B机器
[root@hf-02 ~]# wget wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  1. 下载完以后,安装rpm包(实际上就是安装了一个yum源仓库)
A机器安装rpm包
[root@hf-01 ~]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm

B机器安装rpm包
[root@hf-02 ~]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
  1. 查看/etc/yum.repos.d/目录下面会看到增长了一个zabbix.repo
[root@hf-01 ~]# ls /etc/yum.repos.d/
CentOS-Base.repo       CentOS-fasttrack.repo  CentOS-Vault.repo  zabbix.repo
CentOS-CR.repo         CentOS-Media.repo      epel.repo.1
CentOS-Debuginfo.repo  CentOS-Sources.repo    epel-testing.repo
[root@hf-01 ~]# 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@hf-01 ~]#
  1. 再有了这个zabbix.repo源以后,就能够yum安装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 //webUI ,web界面
    • zabbix-web-mysql //web和mysql相关组件
  • PS:在服务端是须要安装这些全部的包,而在客户端仅仅须要安装 zabbix-agent 包便可
A机器
[root@hf-01 ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql

B机器
[root@hf-02 ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
  1. zabbix 是基于php环境的,也就是说用的是php 的代码编写的web界面,也就说这个zabbix 至关于一个站点
  2. 安装mysql,若是mysql以前没有安装的话,须要根据lamp那一章的mysql安装方法安装mysql
  • 固然yum安装mysql、或mariadb也能够
  • 安装mysql
A机器(由于以前安装过mysql)
[root@hf-01 ~]# !ps
ps aux| grep mysql
root      1203  0.0  0.1 115388  1684 ?        S    01:22   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/hf-01.pid
mysql     1498  0.1 45.3 973552 458376 ?       Sl   01:22   0:03 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/hf-01.err --pid-file=/data/mysql/hf-01.pid
root      2586  0.0  0.0 112676   980 pts/1    R+   02:10   0:00 grep --color=auto mysql
[root@hf-01 ~]#
  1. 修改mysql的配置文件,修改/etc/my.cnf文件,设定默认的字符集
A机器
[root@hf-01 ~]# vim /etc/my.cnf
在[mysqld]下添加字符集

character_set_server = utf8
保存退出
  • 若是不设置字符集,那么zabbix的web界面,设置成中文的话,可能就会出现乱码
  1. 修改完mysql的配置文件后,重启mysql服务
  • /etc/init.d/mysqld restart
A机器
[root@hf-01 ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 
[root@hf-01 ~]#
  1. 重启mysqld服务后,进入mysql命令行(第一次进入mysql命令行),建立zabbix库,并指定编码为utf8
    • create database zabbix character set utf8;
A机器
[root@hf-01 ~]# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@hf-01 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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;        //建立zabbix库,并指定编码为utf8
Query OK, 1 row affected (0.00 sec)

mysql>
  1. 再建立用户,这个用户是须要让web(php)代码链接mysql的,监控中心zabbix mysql服务,启动的前提就是要链接mysql;客户端采集了数据,须要把这些数据传递给服务端,那么服务端怎么把这些数据写入到MySQL去,这时就涉及到了mysql 的用户,涉及到了mysql 的数据库;用哪个用户,去写入那一个库。
  • grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'hanfeng-zabbix';
mysql> grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'hanfeng-zabbix';
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@hf-01 ~]#
  1. 退出mysql的命令行后,导入原始的数据,若缺乏这些数据,zabbix就没有办法工做,就没有办法在web界面下展示给咱们
  • zabbix-server-mysql-3.2.11 这块用tab键补全,有可能版本号不一样
A机器
[root@hf-01 ~]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/
[root@hf-01 zabbix-server-mysql-3.2.11]#
  1. 在/usr/share/doc/zabbix-server-mysql-3.2.11/目录下有一个create.sql.gz压缩包,将它解压,解压完以后生成了一个.sql的文件
A机器
[root@hf-01 zabbix-server-mysql-3.2.11]# ls
AUTHORS  ChangeLog  COPYING  create.sql.gz  NEWS  README
[root@hf-01 zabbix-server-mysql-3.2.11]# gzip -d create.sql.gz
[root@hf-01 zabbix-server-mysql-3.2.11]# ls
AUTHORS  ChangeLog  COPYING  create.sql  NEWS  README
[root@hf-01 zabbix-server-mysql-3.2.11]#
  1. 而后拿到create.sql文件,将它导入到zabbix库里面去
A机器
[root@hf-01 zabbix-server-mysql-3.2.11]# mysql -uroot -phanfeng zabbix < create.sql 
Warning: Using a password on the command line interface can be insecure.
[root@hf-01 zabbix-server-mysql-3.2.11]#
  1. 启动zabbix服务,启动zabbix报错
  • systemctl start zabbix-server
[root@hf-01 ~]# systemctl start zabbix-server
[root@hf-01 ~]#
  1. 启动httpd服务,在启动http服务以前,先查看nginx服务是否启动,若启动了nginx,就监听了80端口,就须要去停掉nginx服务,再去启动httpd服务
[root@hf-01 ~]# ps aux |grep nginx
root      2866  0.0  0.0 112676   984 pts/1    R+   03:06   0:00 grep --color=auto nginx
[root@hf-01 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1517/master         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1191/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1517/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      2749/mysqld         
tcp6       0      0 :::22                   :::*                    LISTEN      1191/sshd           
[root@hf-01 ~]# systemctl start httpd
[root@hf-01 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1517/master         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1191/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1517/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      2749/mysqld         
tcp6       0      0 :::80                   :::*                    LISTEN      2874/httpd          
tcp6       0      0 :::22                   :::*                    LISTEN      1191/sshd           
[root@hf-01 ~]#
  • 这时就发现httpd服务监听了80端口
  1. 若须要开机启动httpd服务和zabbix服务,则须要将它加入到服务的列表中去
  • systemctl enable httpd
  • systemctl enable zabbix-server
A机器
[root@hf-01 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@hf-01 ~]# systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@hf-01 ~]#
  • 若nginx设置了开机启动,则须要取消开机启动
    • systemctl disable nginx
    • chkconfig nginx off
  1. 查看zabbix服务进程
[root@hf-01 ~]# ps aux |grep zabbix
zabbix    2863  0.0  0.3 251752  3332 ?        S    03:04   0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
root      2926  0.0  0.0 112676   984 pts/1    R+   03:15   0:00 grep --color=auto zabbix
[root@hf-01 ~]#
  1. 查看zabbix监听的端口
[root@hf-01 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1517/master         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1191/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1517/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      2749/mysqld         
tcp6       0      0 :::80                   :::*                    LISTEN      2874/httpd          
tcp6       0      0 :::22                   :::*                    LISTEN      1191/sshd           
[root@hf-01 ~]#
  • 错误:
    • 这里看到服务启动了,但并无zabbix监听的端口
  1. 查看zabbix并无监听端口后,首先检查zabbix的错误日志,错误日志路径/var/log/zabbix/zabbix_server.log
[root@hf-01 ~]# tail /var/log/zabbix/zabbix_server.log
  2863:20180103:033242.719 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  2863:20180103:033242.719 database is down: reconnecting in 10 seconds
  2863:20180103:033252.720 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  2863:20180103:033252.720 database is down: reconnecting in 10 seconds
  2863:20180103:033302.721 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  2863:20180103:033302.721 database is down: reconnecting in 10 seconds
  2863:20180103:033312.722 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  2863:20180103:033312.723 database is down: reconnecting in 10 seconds
  2863:20180103:033322.724 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  2863:20180103:033322.724 database is down: reconnecting in 10 seconds
[root@hf-01 ~]#
  • 虽然zabbix服务有进程,但没有完全的起来,说明不可以链接mysql,因此还须要更改zabbix的配置文件
  1. 更改zabbix的配置文件,配置文件为/etc/zabbix/zabbix_server.conf
A机器
[root@hf-01 ~]# vim /etc/zabbix/zabbix_server.conf

搜索/DBHost
在DBName=zabbix上面增长
DBHost=127.0.0.1

在DBuser下面增长
DBPassword=hanfeng-zabbix

保存退出
  • 由于mysql和zabbix装在同一台机器上,这里的 DBHost能够写localhost 或者127.0.0.1;若是是在生产环境上,有时候为了提高zabbix的性能,可能会把MySQL装在其余机器上,这是的DBHost,就须要写上mysql的ip
  1. 更改完zabbix配置文件,就能够启动zabbix服务了,由于以前启动了zabbix服务,这里只需restart重启下便可
A机器
[root@hf-01 ~]# systemctl restart zabbix-server
[root@hf-01 ~]#
  1. 这时再来查看下zabbix进程,有29个(正常状况下,都是这么多进程)
A机器
[root@hf-01 ~]# ps aux |grep zabbix |wc -l
29
[root@hf-01 ~]#
  1. 查看监听的端口,zabbix监听的端口为10051端口
A机器
[root@hf-01 ~]# netstat -lntp |grep zabbix
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      3303/zabbix_server  
tcp6       0      0 :::10051                :::*                    LISTEN      3303/zabbix_server  
[root@hf-01 ~]#
  1. 接下来就是配置web界面了(须要关闭防火墙和规则,不然浏览器没法访问)
  • 在浏览器输入IP地址(即监控中心的IP地址),如192.168.74.129/zabbix 去访问

输入图片说明

  • 不少人会有疑问,仅仅启动了httpd 服务,没有去作任何的配置,由于yum安装zabbix,它默认安装httpd 及它的配置文件,一切都会帮你配置好了
  1. 再打开zabbix界面后,点击 Next step ,会出现一个提示,出现OK的都不用管,会看到提示须要去设置php的timezone时区,以下图

输入图片说明

  1. 设置php的timezone时区,在php的配置文件中设置,默认php的配置文件在/etc/php.ini 里面
A机器
[root@hf-01 ~]# vim /etc/php.ini

搜索 /timezone
将 ;date.timezone 改成以下

date.timezone = Asia/Shanghai
保存退出
  1. 在定义完php的配置文件,还须要重启apache
[root@hf-01 ~]# systemctl restart httpd
[root@hf-01 ~]#

29.这时再来刷新浏览器,会发现都变成OK了php

输入图片说明

30.这时再来 Next step ,来配置数据库相关信息mysql

  • host :MySQL所在机器IP
  • port:0为默认端口3306,若是有改动就修改
  • name:库的名字
  • user:库的用户
  • password:用户的密码

输入图片说明

  1. 而后再选择Next step ,配置站点名字相关

输入图片说明

  • host:站点主机名
  • port:端口,若是有改动就改,没改动,默认就是10051
  • name:站点的名字,你喜欢就好
  1. 配置完成后会有一个信息显示,若是配置错误,能够back返回上一步从新修改

输入图片说明

  1. 安装成功后,会有提示界面,以下图

输入图片说明

  1. 登陆管理页,默认的帐号是Admin,密码为zabbixlinux

  2. 在登陆进zabbix以后,首先须要去更改密码(由于默认的密码你们都知道的),如果在线上环境不更改密码,很容易被别人拿到后台权限ios

  • 更改密码,先选择 Administration ,而后选择 Users

输入图片说明

  • 而后找到Admin,并点进去,选择 Change password 修改密码和选择语言(支持中文),而后保存退出

输入图片说明

  • 这时候密码改了,但看到界面仍是英文版,刷新浏览器便可,会看到变成中文版

输入图片说明

  • 这时在退出zabbix,再从新进入下,使用新的密码,会看到从新进入了,这就是zabbix的web界面了

客户端安装zabbix(B机器)

  • 在客户端上也须要下载zabbix的yum源
  • wget repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  • rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
  • yum install -y zabbix-agent
  • vim /etc/zabbix/zabbix_agentd.conf //修改以下配置
Server=127.0.0.1修改成Server=192.168.133.130 //定义服务端的ip(被动模式)
 ServerActive=127.0.0.1修改成ServerActive=192.168.133.130 //定义服务端的ip(主动模式)
Hostname=Zabbix server修改成Hostname=aming-123 //这是自定义的主机名,一会还须要在web界面下设置一样的主机名
  • systemctl start zabbix-agent
  • systemctl enable zabbix-agent
  1. 首先客户端下载
B机器
[root@hf-02 ~]# wget wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  1. 下载完以后,安装rpm包(实际上就是安装了一个yum源仓库)
B机器
[root@hf-02 ~]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
  1. 客户端,编辑zabbix的配置文件,文件为/etc/zabbix/zabbix_agentd.conf
B机器
[root@hf-02 ~]# vi /etc/zabbix/zabbix_agentd.conf

Server=192.168.202.130
# 定义服务端的ip(被动模式)

ServerActive=192.168.133.130    
#定义服务端的ip(主动模式)
#这个涉及到一个主动和被动模式;若是这里不填写服务中心的IP,那么就只能使用被动模式;这个IP是主动模式时候用的

Hostname=Zabbix server修改成Hostname=hf-02 
#这是自定义的主机名,一会还须要在web界面下设置一样的主机名

保存退出
  1. 启动zabbix服务
[root@hf-02 ~]# systemctl start zabbix-agent
[root@hf-02 ~]#
  1. 客户端查看zabbix服务,监听的端口,客户端监听的端口是10050
[root@hf-02 ~]# ps aux |grep zabbix
zabbix    2566  0.0  0.1  80592  1280 ?        S    13:16   0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
zabbix    2567  0.0  0.1  80592  1296 ?        S    13:16   0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix    2568  0.0  0.1  80592  1836 ?        S    13:16   0:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix    2569  0.0  0.1  80592  1836 ?        S    13:16   0:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix    2570  0.0  0.1  80592  1836 ?        S    13:16   0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix    2571  0.0  0.2  80720  2180 ?        S    13:16   0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root      2573  0.0  0.0 112664   972 pts/0    R+   13:17   0:00 grep --color=auto zabbix
[root@hf-02 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1301/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1997/master         
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      2566/zabbix_agentd  
tcp6       0      0 :::22                   :::*                    LISTEN      1301/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1997/master         
tcp6       0      0 :::10050                :::*                    LISTEN      2566/zabbix_agentd  
[root@hf-02 ~]#
  1. 将zabbix加入到启动列表里面,让它开机启动
  • systemctl enable zabbix-agent
[root@hf-02 ~]# 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@hf-02 ~]#
  1. 这样客户端的zabbix就配置完成

19.5 忘记Admin密码如何作

忘记Admin密码如何作

  • 进入mysql命令行,选择zabbix库
  • mysql -uroot -p zabbix
  • update users set passwd=md5(‘newpasswd’) where alias=‘Admin’;
  • 这样就更改了Admin用户的密码

忘记zabbix密码

  • 有时由于时间长了,zabbix管理员帐号密码给忘记了
  • 解决办法:
    • 重置zabbix密码,就是直接更改数据库里的数据便可
  1. 首先进入到mysql命令行里面
A机器
[root@hf-01 ~]# mysql -uroot -phanfeng
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 342
Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>
  1. 使用zabbix库
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. 查看zabbix相关的表,之后服务器监控的主机越多,那么这些表会愈来愈大,因此须要去指定合适的监控策略
  • 好比说:数据量须要保存多长时间,那么在定义这个监控项目的时候就该想到,要保留1个月仍是1年,仍是其余时间;
  • 好比,监控的站点服务量很大的话,一天就要涨好几个G,那么你的服务器磁盘能支持保存多长时间;
show tables;
  1. zabbix的密码,默认存放的表是users里面
  2. 查看users表
  • desc users;
mysql> desc users;
+----------------+---------------------+------+-----+---------+-------+
| Field          | Type                | Null | Key | Default | Extra |
+----------------+---------------------+------+-----+---------+-------+
| userid         | bigint(20) unsigned | NO   | PRI | NULL    |       |
| alias          | varchar(100)        | NO   | UNI |         |       |
| name           | varchar(100)        | NO   |     |         |       |
| surname        | varchar(100)        | NO   |     |         |       |
| passwd         | char(32)            | NO   |     |         |       |
| url            | varchar(255)        | NO   |     |         |       |
| autologin      | int(11)             | NO   |     | 0       |       |
| autologout     | int(11)             | NO   |     | 900     |       |
| lang           | varchar(5)          | NO   |     | en_GB   |       |
| refresh        | int(11)             | NO   |     | 30      |       |
| type           | int(11)             | NO   |     | 1       |       |
| theme          | varchar(128)        | NO   |     | default |       |
| attempt_failed | int(11)             | NO   |     | 0       |       |
| attempt_ip     | varchar(39)         | NO   |     |         |       |
| attempt_clock  | int(11)             | NO   |     | 0       |       |
| rows_per_page  | int(11)             | NO   |     | 50      |       |
+----------------+---------------------+------+-----+---------+-------+
16 rows in set (0.01 sec)

mysql>
  • 须要修改的就是passwd的表
  1. 修改密码
  • update users set passwd=md5(‘newpasswd’) where alias=‘Admin’;
mysql> update users set passwd=md5('aminglinux') where alias='Admin';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql>
  1. 查看表的状况
  • select * from users\G;
mysql> select * from users\G;
*************************** 1. row ***************************
        userid: 1
         alias: Admin
          name: Zabbix
       surname: Administrator
        passwd: 683cb8e76a8889fdc5161e3fa7e51f2d
           url: 
     autologin: 1
    autologout: 0
          lang: zh_CN
       refresh: 30
          type: 3
         theme: default
attempt_failed: 0
    attempt_ip: 
 attempt_clock: 0
 rows_per_page: 50
*************************** 2. row ***************************
        userid: 2
         alias: guest
          name: 
       surname: 
        passwd: d41d8cd98f00b204e9800998ecf8427e
           url: 
     autologin: 0
    autologout: 900
          lang: en_GB
       refresh: 30
          type: 1
         theme: default
attempt_failed: 0
    attempt_ip: 
 attempt_clock: 0
 rows_per_page: 50
2 rows in set (0.00 sec)

ERROR: 
No query specified

mysql>
  1. 修改之后就能够去尝试用新密码登陆zabbix了,这就是充值zabbix管理员密码
相关文章
相关标签/搜索