您的位置:首页 > 理论基础 > 计算机网络

运维监控系统——配置服务监控项(Http,Nginx,MySQL)

2019-06-18 13:52 771 查看

一、添加自带的http监控项

1.在浏览器中给server2添加http的监控项

  • http是zabbix自带的监控模版
  • 配置 —>主机 —> server2 —> 模板 —>选择 —> Template App HTTP Service—> 添加 —>更新



点击server2的监控项可以看到http服务正在运行

二、添加nginx监控

zabbix中没有nginx的监控项,所以要在agent端部署nginx服务

1.部署nginx服务并测试

(1)安装nginx的依赖性

[root@server3 ~]# yum install gcc pcre-devel zlib-devel -y

(2)解压安装包,关闭debug日志,编译安装

[root@server3 ~]# ls
nginx-1.16.0.tar.gz  zabbix-agent-4.0.5-1.el7.x86_64.rpm
[root@server3 ~]# tar zxf nginx-1.16.0.tar.gz    ##解压安装包
[root@server3 ~]# ls
nginx-1.16.0  nginx-1.16.0.tar.gz  zabbix-agent-4.0.5-1.el7.x86_64.rpm
[root@server3 ~]# cd nginx-1.16.0
[root@server3 nginx-1.16.0]# vim auto/cc/gcc    ##关闭debug日志
[root@server3 nginx-1.16.0]#
[root@server3 nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module
##编译,需要添加http_stub_status_module模块,这是用来监控http状态的

[root@server3 nginx-1.16.0]# make && make install



(3)编辑配置文件

[root@server3 nginx-1.16.0]# cd /usr/local/nginx/conf/
[root@server3 conf]# vim nginx.conf

location /status {
stub_status on;    ##状态监控开启
access_log off;    ##不记录状态监控的日志
allow 127.0.0.1;   ##只允许管理员查看
deny all;          ##其他的都拒绝
}



(4)语法检测,开启服务

[root@server3 conf]# ../sbin/nginx  -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server3 conf]# ../sbin/nginx


(5)访问测试:

[root@server3 conf]# curl http://127.0.0.1/status
Active connections: 1
server accepts handled requests
1 1 1
Reading: 0 Writing: 1 Waiting: 0


(6)安装httpd,模拟访问量

[root@server3 conf]# yum install -y httpd
[root@server3 conf]# ab -c 1 -n 1000 http://127.0.0.1/status

[root@server3 conf]# curl http://127.0.0.1/status

[root@server3 conf]# curl -s  http://127.0.0.1/status
Active connections: 1
server accepts handled requests
1003 1003 1003


(7)截取连接数

[root@server3 conf]# curl -s  http://127.0.0.1/status | grep Active | awk '{print $3}'

2 . 创建nginx监控项

(1)编辑一个监控项配置文件

[root@server3 conf]# cd /etc/zabbix/zabbix_agentd.d/
[root@server3 zabbix_agentd.d]# ls
userparameter_mysql.conf

[root@server3 zabbix_agentd.d]# cp userparameter_mysql.conf userparameter_nginx.conf
[root@server3 zabbix_agentd.d]# ls
userparameter_mysql.conf  userparameter_nginx.conf

[root@server3 zabbix_agentd.d]# vim userparameter_nginx.conf

UserParameter=nginx.active,curl -s  http://127.0.0.1/status | grep Active | awk '{print $3}'



(2)server端获得数据

server1: 安装zabbix-get

[root@server1 ~]# ls
4.0  zabbix-api
[root@server1 ~]# cd 4.0/

[root@server1 4.0]# yum install zabbix-get-4.0.5-1.el7.x86_64.rpm

[root@server1 4.0]# zabbix_get -s 172.25.16.3 -p 10050 -k "nginx.active"
1


3.浏览器中配置

创建监控项,其中键值必须和文件中一致

  • 配置—> 主机—> server3—> 监控项—> 创建监控项

  • 编辑监控项的名称,输入键值—>添加


  • 选择图形— 3ff7 >创建图形—>编辑图形的名称---->点击监控项那一栏的添加,勾选刚刚创建的监控项—>添加




  • 可以看到图形添加成功

  • 新打开一个标签页,访问172.25.6.3,出现的是nginx的默认测试页

  • 点击刚刚添加的图形,点击预览 ,可以看到图形出现变化,但现在的字体是乱码

4.替换字体

下载自己喜欢的字体放在 /usr/share/zabbix/fonts/目录下,编辑 /usr/share/zabbix/include/ defines.inc.php 文件,将原来的字体graphfont.ttf替换成simkai.ttf

[root@server1 ~]# cd /usr/share/zabbix/fonts/
[root@server1 fonts]# ls
graphfont.ttf    ##原有的字体
[root@server1 fonts]# ls
graphfont.ttf  simkai.ttf     ##新下载的字体
[root@server1 fonts]# cd  ../include/
[root@server1 include]# ls
[root@server1 include]# vim defines.inc.php

:%s/graphfont/simkai/g


5.再次查看图形,字体改变

6.再添加一个监控项:nginx.accept

[root@server3 ~]# curl -s  http://127.0.0.1/status
Active connections: 1
server accepts handled requests
1060 1060 1062
Reading: 0 Writing: 1 Waiting: 0
[root@server3 ~]# curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $1}'
1061


(1)编辑配置文件,添加新的监控项

[root@server3 ~]# vim /etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf

UserParameter=nginx.active,curl -s  http://127.0.0.1/status | grep Active | awk '{print $3}'
UserParameter=nginx.accept,curl -s  http://127.0.0.1/status |awk NR==3 | awk '{print $1}'


重启服务

[root@server3 ~]# systemctl restart zabbix-agent


(2)server端get数据

[root@server1 include]# zabbix_get -s 172.25.6.3 -p 10050 -k "nginx.accept"

(3)浏览器配置

创建监控项 将图形更新,添加一个监控项

  • 配置 —>主机 —>server3 —> 监控项 —> 创建监控项


  • 选择图形–>点击之前创建的图形—>将新的监控项添加进去



  • 更新后查看图形

  • 模拟1000访问量,观察图形

    [root@server3 ~]# ab -c 1 -n 1000 http://127.0.0.1/status


三、zabbix监控mysql服务

1.给Zabbix server主机添加zabix自带的mysql监控模版

  • 配置 —>主机 —> Zabbix servers —>模板 —>选择 —>Template DB MySQl —> 选择 —> 添加(顶上去) —> 更新



配置mysql

(1)存活检测

[root@server1 ~]# cd /var/lib
[root@server1 lib]# ls

[root@server1 lib]# mysqladmin -uzabbix -predhat -h 127.0.0.1 | grep -c alive    ##存活检测 1表示存活 0表示挂了
1

(2)创建一个zabbix目录,新建一个.my.cnf文件

[root@server1 lib]# mkdir zabbix
[root@server1 lib]# ls
[root@server1 lib]# cd zabbix/
[root@server1 zabbix]# ls
[root@server1 zabbix]# vim .my.cnf

[mysql]
host=localhost
user=root
password=redhat
socket=/var/lib/mysql/mysql.sock

[mysqladmin]
host=localhost
user=root
password=redhat
socket=/var/lib/mysql/mysql.sock
[root@server1 zabbix]#

重启zabbix-agent服务
[root@server1 zabbix]# systemctl restart zabbix-agent



(3)server1访问数据库产生数据

[root@server1 zabbix]# mysql -p
Enter password:
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| zabbix             |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> USE zabbix;

MariaDB [zabbix]> SELECT * FROM users;


(4)浏览器图形中查看到数据

可以看到他只增加了14个监控项,这在实际的生产环境中显然是不够的,所以我们继续增加监控项


2.通过percona监控mysql

percona:开源的mysql分析工具

(1)安装percona模版

[root@server1 ~]# rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm


(2)拷贝userparameter_percona_mysql.conf文件到被监控的mysql服务器上 ( server1:/etc/zabbix/zabbix_agentd.d/)

[root@server1 ~]# cd /var/lib/zabbix/
[root@server1 zabbix]# ls
percona
[root@server1 zabbix]# cd percona/
[root@server1 percona]# ls
scripts  templates
[root@server1 percona]# cd scripts/
[root@server1 scripts]# ls
get_mysql_stats_wrapper.sh  ss_get_mysql_stats.php

[root@server1 scripts]# cd ../templates/
[root@server1 templates]# ls
userparameter_percona_mysql.conf
zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml

[root@server1 templates]# cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/


(3)由于percona的监控脚本是用php写的,所以需要准备好php运行环境,将zabbix的数据库和密码写入php脚本中

[root@server1 templates]# cd  ../scripts/
[root@server1 scripts]# ls
get_mysql_stats_wrapper.sh  ss_get_mysql_stats.php
[root@server1 scripts]# vim ss_get_mysql_stats.php.cnf

<?php
$mysql_user = 'root';
$mysql_pass = 'redhat';
?>
[root@server1 scripts]# systemctl restart zabbix-agent



(4)检测percona的脚本,过滤监控项

[root@server1 scripts]# cd /etc/zabbix/zabbix_agentd.d/
[root@server1 zabbix_agentd.d]# ls
userparameter_mysql.conf  userparameter_percona_mysql.conf

[root@server1 zabbix_agentd.d]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh  gg
0


(5)浏览器中导入模版,添加监控项

导入成功之后有293个监控项

  • 配置 —>主机 —> 群组 —> Templates/Operabing systems —> 导入 —> Brwose选择模板存放的位置 —> 勾选聚合图形 —>导入
  • 配置—>主机 —>模板 —>选择percona模板 —>更新


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: