Linux云计算架构-Zabbix4-4-6监控apache和mysql

Linux云计算架构-Zabbix4-4-6监控apache和mysql

1. 环境介绍

zabbix4-4-6基于LAMP环境部署。
服务器IP:192.168.8.173
客户端IP:192.168.8.172
服务端可以正常监控服务端本身和远程客户端。

在这里插入图片描述

2. 监控客户端apache

2.1 安装apache,并测试获取apache状态

# 配置apache
# yum安装apache
[root@client ~]# yum install -y httpd

# 修改httpd配置文件,在末尾添加本地服务器状态页面
[root@client ~]# vim /etc/httpd/conf/httpd.conf 
ExtendedStatus On
<location /server-status>
 SetHandler server-status
 Order allow,deny 
 Allow from 127.0.0.1 192.168.8.0/24
</location>

95 ServerName localhost:80
# 重启httpd服务,并放行80端口号
[root@client ~]# systemctl restart httpd.service 
[root@client ~]# netstat -antup | grep httpd
tcp6       0      0 :::80                   :::*                    LISTEN      9624/httpd
[root@client ~]# firewall-cmd --permanent --zone=public --add-port=80/tcp
success
[root@client ~]# firewall-cmd --reload 
success

查看网址:http://192.168.8.172/server-status是否显示正常,该页面用于收集客户端上apache服务的信息。

在这里插入图片描述

2.2 客户端添加apache模板

为客户端添加apache模板
在这里插入图片描述
在这里插入图片描述

2.3 查看apache监控数据

查看最新数据:
在这里插入图片描述
查看图形:
在这里插入图片描述
查看所有最新数据:
在这里插入图片描述
查看所有最新数据的图形:
在这里插入图片描述
在这里插入图片描述

2.4 对apache进行压力测试

# 压测测试一下
[root@client ~]# ab -n 1000 -c 1000 http://192.168.8.172/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.8.172 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.4.6
Server Hostname:        192.168.8.172
Server Port:            80

Document Path:          /
Document Length:        4897 bytes

Concurrency Level:      1000
Time taken for tests:   0.462 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Non-2xx responses:      1000
Total transferred:      5168000 bytes
HTML transferred:       4897000 bytes
Requests per second:    2162.65 [#/sec] (mean)
Time per request:       462.395 [ms] (mean)
Time per request:       0.462 [ms] (mean, across all concurrent requests)
Transfer rate:          10914.64 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   14  16.1      1      39
Processing:     2   88 134.6     18     420
Waiting:        2   88 134.7     17     420
Total:         12  102 146.3     20     458

Percentage of the requests served within a certain time (ms)
  50%     20
  66%     37
  75%    239
  80%    245
  90%    440
  95%    446
  98%    448
  99%    449
 100%    458 (longest request)

在这里插入图片描述
内存使用35.63MB,cpu使用0.5%

3. 监控客户端mysql

3.1 安装mysql数据库并设置zabbix用户

# 安装mysql数据库
[root@client ~]# yum install mariadb-server -y
# 启动并设置开机自启
[root@client ~]# systemctl start mariadb.service 
[root@client ~]# systemctl enable mariadb.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
# 登录数据库,创建zabbix用户,并授权usage
[root@client ~]# mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> grant usage on *.* to zabbix@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit;
Bye
# 测试下zabbix用户是否可以登录数据库
[root@client ~]# mysql -uzabbix -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> exit
Bye

3.2 添加mysql监控模板文件并配置zabbix用户免密登录

# 复制一份mysql监控模板文件
[root@client ~]# cp /usr/share/doc/zabbix-agent-4.4.6/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/
# 查看客户端配置文件
[root@client ~]# vim /etc/zabbix/zabbix_agentd.conf
290 Include=/etc/zabbix/zabbix_agentd.d/*.conf
# 设置zabbix用户免密登录
[root@client ~]# vim /etc/my.cnf.d/client.cnf
[client]
user=zabbix
password=123456

# 测试zabbix免密登录
[root@client ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select user();
+------------------+
| user()           |
+------------------+
| zabbix@localhost |
+------------------+
1 row in set (0.00 sec)

# 重启zabbix客户端
[root@client ~]# systemctl restart zabbix-agent
[root@client ~]# systemctl enable zabbix-agent

3.3 添加zabbix的mysql监控模板

在这里插入图片描述
在这里插入图片描述

3.4 查看mysql数据

点了应用之后,数据可能出来的比较慢
在这里插入图片描述
查看堆叠数据图
在这里插入图片描述
在这里插入图片描述
有很多项都没数据,因为没有客户端连接数据库。

3.5 压测mysql数据库

# mysqlslap是mysql数据库自带的压测工具,可模拟出大量客户端对数据库同时进行操作,通过监控数据库来了解数据库的性能。
[root@client ~]# mysqlslap -uroot -p --concurrency=100 --number-of-queries=1000 --number-int-cols=5 --number-char-cols=20 --auto-generate-sql
Enter password:     # 没有密码,直接回车
Benchmark
	Average number of seconds to run all queries: 1.148 seconds      # 运行所有语句的平均秒数
	Minimum number of seconds to run all queries: 1.148 seconds      # 运行所有语句的最小描述
	Maximum number of seconds to run all queries: 1.148 seconds      # 运行所有语句的最大秒数
	Number of clients running queries: 100     # 客户端数量
	Average number of queries per client: 10   # 每个客户端运行查询的平均数

--concurrency   # 当前客户端连接数
--number-of-queries    # 总的测试查询次数
--number-int-cols   # 生成5个int类型的列
--number-char-cols   # 生成20个char类型的列
--auto-generate-sql   # 自动生成sql脚本

可以看到已经有数据产生了。
在这里插入图片描述
以上就是使用zabbix监控apache和mysql数据库的全过程了。说实话,zabbix4-4-6版本会比zabbix3-4-3版本配置监控apache和mysql容易一些,但也有很多类似的地方。即是zabbix4-4-6有很多地方都优化了,也更方便了。

猜你喜欢

转载自blog.csdn.net/weixin_36522099/article/details/108014702