12月24日任务php
19.1 Linux监控平台介绍mysql
19.2 zabbix监控介绍linux
19.3/19.4/19.6 安装zabbixios
19.5 忘记Admin密码如何作nginx
监控对于一个企业而言是很是重要的,尤为对一些比较重要的业务,监控能够在问题出现之初就被发现,可以及时修复,较少损失。c++
建立的开源监控软件有:cacti、nagios、zabbix、smokeping、open-falcon等。web
cacti、smokeping偏向于基础监控,图形化显示很是漂亮。sql
cacti、zabbix支持web界面进行管理、控制,zabbix在这方面作得很好,配置简单;相对而言nagios须要修改配置文件等,步骤繁琐。cacti、nagios、zabbix服务端监控中心,须要php环境支持,其中zabbix和cacti都须要mysql做为数据存储,nagios不用存储历史数据,注意服务或者监控项的状态,zabbix会时刻获取服务或者监控项目的数据,并将数据记录到数据库里,从而能够出图。数据库
open-falcon是小米公司开发的,开源后受到诸多大公司和运维工程师的追捧,适合大公司,国内的不少大公司如滴滴、360、新浪微博、京东等大公司都在使用这款软件,值得研究。vim
C/S架构,基于c++开发,监控中心支持web界面配置和管理。
单server节点能够支持上万台客户端,并发高,其瓶颈在于数据采集的量,当服务器的规模达到必定程度后,就须要添加一些代理。
最新版本3.4,官方文档 https://www.zabbix.com/manuals
zabbix包括5个组件:
zabbix-server 监控中心,接收客户端上报信息,负责配置、统计、操做数据。
web UI 在web界面下操做配置,这也是zabbix简单易用的主要缘由。
zabbix-proxy 可选组件,能够代替zabbix-server的功能,减轻server的压力。
zabbix-agent 客户端软件,负责采集各个监控服务或项目的数据,并上报。
监控流程以下:
能够使用yum安装zabbix,epel仓库的zabbix较老,这里推荐使用新版本所对应的yum仓库来安装新版本。到http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/
目录下找到zabbix-release-3.2-1.el7.noarch.rpm
包,使用rpm命令安装便可。(能够根据须要安装版本,上述的地址和包只要修改版本号便可)
# 服务器和客户端都须要安装zabbix-release包 [root@server ~]# wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm [root@server ~]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
#服务器(会附带安装httpd和php,web界面须要) [root@server ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
# 若是你的服务器内已经有了mysql就不要再次安装了 [root@server ~]# yum install -y mysql [root@server ~]# vi /etc/my.cnf # 不设置的话,后续web界面设置为中文将会出现显示错误。 character_set_server = utf8 [root@server ~]# systemctl start mysql
# 建立zabbix库 mysql> create database zabbix character set utf8; # 授予权限 mysql> grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'zabbix';
# 默认的原始数据在/usr/share/doc/zabbix-server-mysql-你的版本/ [root@server ~]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/ [root@server zabbix-server-mysql-3.2.11]# gzip -d create.sql.gz [root@server zabbix-server-mysql-3.2.11]# mysql -uroot -p1 zabbix < create.sql # create.sql内的数据较多,导入过程须要一点时间
[root@server ~]# systemctl start zabbix-server # 启动httpd的时候须要注意一下,若是服务器内安装并启动了nginx服务器,须要关闭nginx,不然80端口被占用,致使httpd启动不了。 [root@server ~]# systemctl start httpd
[root@client ~]# wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm [root@client ~]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
[root@client ~]# yum install -y zabbix-agent
# 这里最关键的就是设置白名单 # 白名单的意义在于限定链接的服务器端,防止客户端信息泄露 [root@client ~]# vi /etc/zabbix/zabbix_agentd.conf # 指定服务器IP Server=127.0.0.1 改成 Server=192.168.65.133 # 主动模式,主动向服务器端上报信息 ServerActive=127.0.0.1 改成 ServerActive=192.168.65.133 Hostname=Zabbix server 改成 Hostname=client1 //这个名字随便写,方便区分 保存退出
[root@client ~]# systemctl start zabbix-agent
zabbix-server的端口号默认为10051,zabbix-agent的默认端口号为10050
查看日志,发现mysql没法链接
[root@test1 ~]# tail /var/log/zabbix/zabbix_server.log 2978:20180120:154842.481 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) ...
编辑配置文件
[root@server ~]# vim /etc/zabbix/zabbix_server.conf # mysql> grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'zabbix'; DBHost=127.0.0.1 //对应zabbix数据库和用户建立时的ip DBPassword=zabbix //对应zabbix数据库和用户建立时的密码 # 实际生产环境下,为了服务器的性能优化,mysql可能会装在其余服务器上,这时上述Host修改成实际mysql服务器的ip便可。
重启zabbix服务
[root@server ~]# systemctl restart zabbix-server
查看是否正常启动
[root@server ~]# 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:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1840/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2107/master tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 3012/zabbix_server tcp6 0 0 :::3306 :::* LISTEN 2064/mysqld tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::80 :::* LISTEN 2986/httpd tcp6 0 0 :::22 :::* LISTEN 1840/sshd tcp6 0 0 ::1:25 :::* LISTEN 2107/master tcp6 0 0 :::10051 :::* LISTEN 3012/zabbix_server [root@server ~]# ps aux |grep zabbix zabbix 3012 0.6 0.4 256256 4116 ? S 15:53 0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf zabbix 3015 0.0 0.2 256256 2464 ? S 15:53 0:00 /usr/sbin/zabbix_server: configuration syncer [waiting 60 sec for processes] zabbix 3016 0.0 0.2 256256 2672 ? S 15:53 0:00 /usr/sbin/zabbix_server: db watchdog [synced alerts config in 0.021593 sec, idle 60 sec] zabbix 3017 0.6 0.5 363200 5188 ? S 15:53 0:00 /usr/sbin/zabbix_server: poller #1 [got 0 values in 0.000006 sec, idle 5 sec] zabbix 3018 0.6 0.5 363200 5188 ? S 15:53 0:00 /usr/sbin/zabbix_server: poller #2 [got 0 values in 0.000008 sec, idle 5 sec] zabbix 3019 0.4 0.5 363200 5188 ? S 15:53 0:00 /usr/sbin/zabbix_server: poller #3 [got 0 values in 0.000004 sec, idle 5 sec] zabbix 3020 0.4 0.5 363200 5188 ? S 15:53 0:00 /usr/sbin/zabbix_server: poller #4 [got 0 values in 0.000012 sec, idle 5 sec] zabbix 3021 0.4 0.5 363200 5188 ? S 15:53 0:00 /usr/sbin/zabbix_server: poller #5 [got 0 values in 0.000017 sec, idle 5 sec] zabbix 3022 0.4 0.5 363200 5188 ? S 15:53 0:00 /usr/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000013 sec, idle 5 sec] zabbix 3023 0.0 0.3 256256 3576 ? S 15:53 0:00 /usr/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting for connection] zabbix 3024 0.0 0.3 256256 3576 ? S 15:53 0:00 /usr/sbin/zabbix_server: trapper #2 [processed data in 0.000000 sec, waiting for connection] zabbix 3025 0.0 0.3 256256 3576 ? S 15:53 0:00 /usr/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting for connection] zabbix 3027 0.0 0.3 256256 3576 ? S 15:53 0:00 /usr/sbin/zabbix_server: trapper #4 [processed data in 0.000000 sec, waiting for connection] zabbix 3028 0.0 0.3 256256 3576 ? S 15:53 0:00 /usr/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting for connection] zabbix 3029 0.1 0.2 258832 2604 ? S 15:53 0:00 /usr/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000008 sec, idle 5 sec] zabbix 3032 0.0 0.2 256256 2680 ? S 15:53 0:00 /usr/sbin/zabbix_server: alerter [sent alerts: 0 success, 0 fail in 0.009433 sec, idle 30 sec] zabbix 3033 0.0 0.2 256256 2460 ? S 15:53 0:00 /usr/sbin/zabbix_server: housekeeper [startup idle for 30 minutes] zabbix 3034 0.0 0.2 256332 2908 ? S 15:53 0:00 /usr/sbin/zabbix_server: timer #1 [processed 0 triggers, 0 events in 0.000154 sec, 0 maintenances in 0.002947 sec, idle 30 sec] zabbix 3035 0.0 0.2 256256 2820 ? S 15:53 0:00 /usr/sbin/zabbix_server: http poller #1 [got 0 values in 0.000652 sec, idle 5 sec] zabbix 3039 0.4 0.5 360616 5024 ? S 15:53 0:00 /usr/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.049212 sec, idle 60 sec] zabbix 3040 0.0 0.2 256256 2804 ? S 15:53 0:00 /usr/sbin/zabbix_server: history syncer #1 [synced 0 items in 0.000007 sec, idle 1 sec] zabbix 3041 0.0 0.2 256256 2804 ? S 15:53 0:00 /usr/sbin/zabbix_server: history syncer #2 [synced 0 items in 0.000003 sec, idle 1 sec] zabbix 3042 0.0 0.2 256256 2804 ? S 15:53 0:00 /usr/sbin/zabbix_server: history syncer #3 [synced 0 items in 0.000002 sec, idle 1 sec] zabbix 3043 0.0 0.2 256256 2804 ? S 15:53 0:00 /usr/sbin/zabbix_server: history syncer #4 [synced 0 items in 0.000003 sec, idle 1 sec] zabbix 3048 0.0 0.3 256256 3760 ? S 15:53 0:00 /usr/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.001462 sec, idle 3 sec] zabbix 3049 0.0 0.3 256256 3756 ? S 15:53 0:00 /usr/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000005 sec, idle 5 sec] zabbix 3050 0.0 0.2 256256 2572 ? S 15:53 0:00 /usr/sbin/zabbix_server: self-monitoring [processed data in 0.000008 sec, idle 1 sec] zabbix 3051 0.0 0.2 256256 2792 ? S 15:53 0:00 /usr/sbin/zabbix_server: task manager [processed 0 task(s) in 0.000485 sec, idle 5 sec] root 3064 0.0 0.0 112684 972 pts/0 S+ 15:54 0:00 grep --color=auto zabbix
[root@client ~]# systemctl start zabbix-agent Job for zabbix-agent.service failed because a configured resource limit was exceeded. See "systemctl status zabbix-agent.service" and "journalctl -xe" for details. [root@client ~]# systemctl status zabbix-agent.service ● zabbix-agent.service - Zabbix Agent Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; disabled; vendor preset: disabled) Active: activating (auto-restart) (Result: resources) since 二 ... 14:54:58 CST; 9s ago Process: 3413 ExecStart=/usr/sbin/zabbix_agentd -c $CONFFILE (code=exited, status=0/SUCCESS) ... 14:54:58 client systemd[1]: zabbix-agent.service neve... ... 14:54:58 client systemd[1]: Failed to start Zabbix Ag... ... 14:54:58 client systemd[1]: Unit zabbix-agent.service... ... 14:54:58 client systemd[1]: zabbix-agent.service failed.
解决方法:关闭selinux
[root@client ~]# setenforce 0 [root@client ~]# systemctl restart zabbix-agent [root@client ~]# ps aux | grep zabbix-agent root 3447 0.0 0.0 112680 980 pts/0 R+ 14:55 0:00 grep --color=auto zabbix-agent [root@client ~]# ps aux | grep zabbix zabbix 3440 0.0 0.1 80608 1252 ? S 14:55 0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf zabbix 3441 0.0 0.1 80608 1288 ? S 14:55 0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec] zabbix 3442 0.0 0.1 80608 1832 ? S 14:55 0:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection] zabbix 3443 0.0 0.1 80608 1836 ? S 14:55 0:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection] zabbix 3444 0.0 0.1 80608 1832 ? S 14:55 0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection] zabbix 3445 0.0 0.2 80736 2188 ? S 14:55 0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec] root 3449 0.0 0.0 112680 972 pts/0 R+ 14:55 0:00 grep --color=auto zabbix [root@client ~]# 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:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1321/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2145/master tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 3440/zabbix_agentd tcp6 0 0 :::3306 :::* LISTEN 2104/mysqld tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::22 :::* LISTEN 1321/sshd tcp6 0 0 ::1:25 :::* LISTEN 2145/master tcp6 0 0 :::10050 :::* LISTEN 3440/zabbix_agentd
Server_IP/zabbix
,回车,就会看到zabbix的配置页面。修改php的配置的文件
[root@server ~]# vim /etc/php.ini 定位到timezone timezone = Asia/Shanghai # 修改后重启httpd服务 [root@server ~]# systemctl restart httpd
刷新页面后查看
信息汇总
"Administration" --> "User" --> "Admin"
点击update按键,再次修改Adminy用户信息界面就显示为中文了!
点击修改密码,将新密码输入2次后,点击更新便可
退出当前用户,使用新密码从新登陆,界面以下(当前未配置监控的主机,显示的数据为空):
若是忘记Admin的密码,直接在mysql中的zabbix数据库内更新密码便可。
具体步骤以下:
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | test1 | | zabbix | +--------------------+ 6 rows in set (0.04 sec) mysql> use zabbix; mysql> show tables; +----------------------------+ | Tables_in_zabbix | +----------------------------+ | acknowledges | | actions | | alerts | | application_discovery | | application_prototype | ........ | trigger_discovery | | trigger_tag | | triggers | | users | | users_groups | | usrgrp | | valuemaps | +----------------------------+ 127 rows in set (0.01 sec) 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.00 sec) # 这里修改的是users表,修改密码使用MD5加密,指定alaias为Admin mysql> update users set passwd=md5('zabbix') where alias='Admin';
从新登陆网页,使用新密码登陆便可。