19.1 Linux监控平台介绍
- cacti、nagios、zabbix、smokeping、open-falcon等等
- cacti、smokeping偏向基础监控,成图非常漂亮
- cacti、nagios、zabbix服务端监控中心,需要PHP环境支持,其中zabbix和cacti都需要mysql作为数据存储,nagios不用存储历史数据,注重服务或者监控项的状态,zabbix会获取服务或者监控项目的数据,会把数据记录到数据库里,从而可以成图
- open-falcon为小米公司开发,开源后受到诸多大公司和运维工程师的追捧,适合大企业,滴滴、360、新浪微博、京东等大公司在使用这款监控软件,值得研究
19.2 zabbix监控介绍
- C/S架构,基于C++开发,监控中心支持web界面配置和管理
- 单server节点可以支持上万台客户端
- 最新版本3.4 ,官网文档https://www.zabbix.com/manuals
- 5个组件
- zabbix-server 监控中心,接收客户端上报信息,负责配置、统计、操作数据
- 数据存储 存放数据,比如mysql
- web界面 也叫web UI ,在web界面下操作配置是zabbix简单易用的主要原因
- zabbix-proxy 可选组件,它可以代替zabbix-server的功能,减轻server的压力
- zabbix-agent 客户端软件,负责采集各个监控服务或项目的数据,并上报
zabbix监控流程图
19.3/19.4/19.6 安装zabbix
安装zabbix
- 官网下载地址 https://www.zabbix.com/download?zabbix=3.2&os_distribution=centos&os_version=7&db=MySQL
- rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
[[email protected] ~]# rpm -i http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm 警告:/var/tmp/rpm-tmp.8EUWZ1: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
#官网有附带教程
- yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
[[email protected] ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
- 会连带安装httpd和php
- 如果mysql之前没有装的话,需要根据lamp那一章的mysql安装方法安装msyql
#启动mysql
[[email protected] mysql]# /etc/init.d/mysqld start
- vim /etc/my.cnf //需要增加配置
character_set_server = utf8 - 重启mysql服务后,进入mysql命令行,创建zabbix库
[[email protected] mysql]# systemctl restart mysql
mysql> create database zabbix character set utf8;
Query OK, 1 row affected (0.00 sec)
- 再创建用户
mysql> grant all on zabbix.* to ‘zabbix‘@‘127.0.0.1‘ identified by ‘qingyunzabbix‘;
Query OK, 0 rows affected (0.02 sec)
#让zabbix web 服务可以连接数据库
- 导入数据
#进入该目录
[[email protected] mysql]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/
#压缩包需要解压一下
[[email protected] zabbix-server-mysql-3.2.11]# ls
AUTHORS ChangeLog COPYING create.sql.gz NEWS README
[[email protected] zabbix-server-mysql-3.2.11]# gzip -d create.sql.gz
[[email protected] zabbix-server-mysql-3.2.11]# ls
AUTHORS ChangeLog COPYING create.sql NEWS README
#导入库里面
[[email protected] zabbix-server-mysql-3.2.11]# mysql -uroot zabbix < create.sql
- 启动 zabbix-server服务
[[email protected] zabbix-server-mysql-3.2.11]# systemctl start zabbix-server
#检查zabbix服务
[[email protected] zabbix-server-mysql-3.2.11]# ps aux |grep zabbix
zabbix 2267 0.0 0.3 254580 3496 ? S 16:41 0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbi_server.conf
root 2270 0.0 0.0 112676 984 pts/0 R+ 16:41 0:00 grep --color=auto zabbix
#如果之前安装过Nginx,需要先检查是否启动
[[email protected] zabbix-server-mysql-3.2.11]# ps aux | grep nginx
root 2272 0.0 0.0 112676 980 pts/0 R+ 16:41 0:00 grep --color=auto nginx
#启动httpd 并 ps
[[email protected] zabbix-server-mysql-3.2.11]# systemctl start httpd
[[email protected] zabbix-server-mysql-3.2.11]# ps aux |grep httpd
root 2279 0.3 1.5 394412 15456 ? Ss 16:42 0:00 /usr/sbin/httpd -DFOREGROUND
apache 2287 0.0 0.7 394544 7692 ? S 16:42 0:00 /usr/sbin/httpd -DFOREGROUND
apache 2288 0.0 0.7 394544 7692 ? S 16:42 0:00 /usr/sbin/httpd -DFOREGROUND
apache 2289 0.0 0.7 394544 7692 ? S 16:42 0:00 /usr/sbin/httpd -DFOREGROUND
apache 2290 0.0 0.7 394544 7692 ? S 16:42 0:00 /usr/sbin/httpd -DFOREGROUND
apache 2291 0.0 0.7 394544 7692 ? S 16:42 0:00 /usr/sbin/httpd -DFOREGROUND
root 2293 0.0 0.0 112676 984 pts/0 R+ 16:42 0:00 grep --color=auto httpd
#查看是否监听80端口
[[email protected] zabbix-server-mysql-3.2.11]# 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 934/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1018/master
tcp6 0 0 :::80 :::* LISTEN 2279/httpd
tcp6 0 0 :::22 :::* LISTEN 934/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1018/master
tcp6 0 0 :::3306 :::* LISTEN 1845/mysqld
- 加入服务,设置开机启动
[[email protected] 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.
[[email protected] zabbix-server-mysql-3.2.11]# 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.
#如果安装过Nginx 需要停掉
[[email protected] zabbix-server-mysql-3.2.11]# systemctl disable nginx
- 查看日志
#通过查看监听端口,发现没有监听端口
#需要查看日志排查问题
[[email protected] ~]# less /var/log/zabbix/zabbix_server.log
- vim /etc/zabbix/zabbix_server.conf //修改或增加
DBHost=127.0.0.1 //在DBName=zabbix上面增加
DBPassword=qingyunzabbix //在DBuser下面增加
#编辑配置文件之后,需要重启服务,加载配置文件
[[email protected] ~]# systemctl restart zabbix-server
[[email protected] ~]# ps aux |grep zabbix
- netstat -lntp | grep zabbix //查看监听端口
[[email protected] ~]# netstat -lntp |grep zabbix
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 2375/zabbix_server
tcp6 0 0 :::10051 :::* LISTEN 2375/zabbix_server
- 浏览器访问http://ip/zabbix/ web界面下面配置zabbix
#设置时区
[[email protected] ~]# vim /etc/php.ini
#编辑好配置文件后,重启httpd
[[email protected] ~]# systemctl restart httpd
#重启完成后,刷新将不报错
- 用户名admin 密码zabbix
- 进入后台第一件事情就是修改密码
备注:修改完密码后,可以设置成中文显示。
zabbix客户端安装
- 在客户端上也需要下载zabbix的yum源
#下载yum源
[[email protected] ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
获取http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
警告:/var/tmp/rpm-tmp.JZlW14: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:zabbix-release-3.2-1.el7 ################################# [100%]
#安装
[[email protected] ~]# yum install -y zabbix-agent
#编辑配置文件
[[email protected] ~]# vim /etc/zabbix/zabbix_agentd.conf
内容如下
Server 配置被动模式
配置监控中心的ip
ServerActive 配置主动模式
设置客户端名称
- 启动服务
[[email protected] ~]# systemctl start zabbix-agent
[[email protected] ~]# ps aux |grep zabbix
zabbix 1180 0.0 0.1 80664 1264 ? S 17:54 0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbi_agentd.conf
zabbix 1181 0.0 0.1 80664 1300 ? S 17:54 0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix 1182 0.0 0.1 80664 1848 ? S 17:54 0:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix 1183 0.0 0.1 80664 1848 ? S 17:54 0:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix 1184 0.0 0.1 80664 1848 ? S 17:54 0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix 1185 0.0 0.2 80796 2196 ? S 17:54 0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root 1187 0.0 0.0 112676 984 pts/0 R+ 17:54 0:00 grep --color=auto zabbix
[[email protected] ~]# 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:80 0.0.0.0:* LISTEN 932/nginx: master p
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 917/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1010/master
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 1180/zabbix_agentd
tcp6 0 0 :::22 :::* LISTEN 917/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1010/master
tcp6 0 0 :::10050 :::* LISTEN 1180/zabbix_agentd
19.5 忘记Admin密码如何做
- 进入mysql命令行,选择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> 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.03 sec)
- 修改密码
#修改密码的命令 mysql> update users set passwd=md5(‘qingyun1‘) where alias= ‘Admin‘; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from users;
+--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+--------------+---------------+---------------+
| userid | alias | name | surname | passwd | url | autologin | autologout | lang | refresh | type | theme | attempt_failed | attempt_ip | attempt_clock | rows_per_page |
+--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+--------------+---------------+---------------+
| 1 | Admin | Zabbix | Administrator | 4e5a9284849f3af9ece4a2892b97dabb | | 1 | 0 | en_GB | 30 | 3 | default | 6 | 192.168.21.1 | 1517391222 | 50 |
| 2 | guest | | | d41d8cd98f00b204e9800998ecf8427e | | 0 | 900 | en_GB | 30 | 1 | default | 0 | | 0 | 50 |
+--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+--------------+---------------+---------------+
2 rows in set (0.00 sec)
* 这样子就更改了Admin用户密码
![](http://i2.51cto.com/images/blog/201801/31/34271b7457735c8a46af12ad355d8923.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
原文地址:http://blog.51cto.com/3622288/2067431