zabbix快速部署 +监控nginx

准备二台centos7的虚拟机

在这里插入图片描述

关掉防火墙 时间同步

先安装ntpdate
[root@localhost ~]# yum -y install ntpdate
[root@localhost ~]# ntpdate pool.ntp.org
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0

一.上传zabbix yum源 安装zabbix_server端

[root@localhost ~]# ls
anaconda-ks.cfg  zabbix_Aliyun.repo
[root@localhost ~]# mv zabbix_Aliyun.repo /etc/yum.repos.d/
[root@localhost ~]# yum -y install zabbix-server-mysql zabbix-agent zabbix-web-mysql maraidb mariadb-server

1.启动mysql 创建zabbix数据库 授权用户

[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# mysql
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

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

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

2.把数据导入zabbix数据库

[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql-4.2.8/create.sql.gz |mysql -uzabbix -pzabbix zabbix
进入mysql数据库查看下是否导入成功

[root@localhost ~]# mysql
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| zabbix             |
+--------------------+
5 rows in set (0.00 sec)

MariaDB [(none)]> 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
MariaDB [zabbix]> show tables;

有数据为导入成功

3.配置启动zabbix

[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf 
只改下password,剩下不用改

在这里插入图片描述

修改下时区,不然一会页面报错
[root@localhost ~]# vim /etc/httpd/conf.d/zabbix.conf 
改成上海时区

在这里插入图片描述

启动zabbix 并查看端口
[root@localhost ~]# systemctl start zabbix-server zabbix-agent httpd
[root@localhost ~]# netstat -nltpu |egrep "10050 |10051 |80"
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      14840/zabbix_agentd 
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      14845/zabbix_server 
tcp6       0      0 :::10050                :::*                    LISTEN      14840/zabbix_agentd 
tcp6       0      0 :::10051                :::*                    LISTEN      14845/zabbix_server 
tcp6       0      0 :::80                   :::*                    LISTEN      14838/httpd         

4.访问zabbix

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

修改中文界面

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

页面数据有乱码 解决乱码

在这里插入图片描述

[root@localhost ~]# cd /usr/share/zabbix/assets/fonts/
有个软连接 把他删除了 上传个中文字体 改成原来的名字即可
[root@localhost fonts]# ll
lrwxrwxrwx. 1 root root 33 9月  23 00:05 graphfont.ttf -> /etc/alternatives/zabbix-web-font
[root@localhost fonts]# rm -rf graphfont.ttf 
[root@localhost fonts]# mv simkai.ttf graphfont.ttf

在这里插入图片描述

二.上传zabbix yum源 安装zabbix_agent端

[root@localhost ~]# ls
anaconda-ks.cfg  zabbix_Aliyun.repo
[root@localhost ~]# mv zabbix_Aliyun.repo /etc/yum.repos.d/
[root@localhost ~]# yum -y install  zabbix-agent 

1.配置启动zabbix_agent

[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf 

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

[root@localhost ~]# systemctl start zabbix-agent
查看端口
[root@localhost ~]# netstat -nltpu |grep 10050
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      13461/zabbix_agentd 
tcp6       0      0 :::10050                :::*                    LISTEN      13461/zabbix_agentd 

2.测试与server端是否相通

在server端下载zabbix-get 测试
[root@localhost ~]# yum -y install zabbix-get
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k agent.ping
1
返回值为1 则为 ok

3.安装监测nginx pv_uv

pv 访问量 页面访问量,访问一次增加一次
uv 访问数 指独立访客访问数,一台电脑终端为一个访客。

想要监测nginx 首先要安装nginx
先安装epel源
[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum -y install nginx
[root@localhost ~]# systemctl start nginx
刚安装完nginx 没有日志,我们拿ab 压测一下,生产点日志
[root@localhost ~]# yum -y install httpd-tools
[root@localhost ~]# ab -n 100 -c 100 http://192.168.27.137/
收集pv_uv 先创建个放脚本的目录 编辑脚本
[root@localhost ~]# mkdir /etc/zabbix/scripts
[root@localhost ~]# cd /etc/zabbix/scripts/
[root@localhost scripts]# vim check_nginx.sh
#!/bin/bash
case $1 in
        pv)
                cat /var/log/nginx/access.log |wc -l
        ;;
        uv)
                cat /var/log/nginx/access.log |awk '{print $1}' |sort |uniq |wc -l
        ;;
esac

测试下
[root@localhost scripts]# sh check_nginx.sh pv
100
[root@localhost scripts]# sh check_nginx.sh uv
1
自定义创建键值 并重启zabbix-agnet
[root@localhost scripts]# vim /etc/zabbix/zabbix_agentd.d/nginx.conf
UserParameter=pv_uv[*],/etc/zabbix/scripts/check_nginx.sh $1     
添加完 要重启zabbix_agent
[root@localhost scripts]# systemctl restart zabbix-agent                                                
在zabbix_server端测试
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k pv_uv[pv]
sh: /etc/zabbix/scripts/check_nginx.sh: 权限不够

报错显示权限不够,去zabbix_agent端给脚本加个执行权限
[root@localhost ~]# chmod +x /etc/zabbix/scripts/check_nginx.sh 
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k pv_uv[pv]
cat: /var/log/nginx/access.log: 权限不够
0

没有权限查看/var/log 去zabbix_agent端加
[root@localhost scripts]# chmod -R 777 /var/log/
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k pv_uv[pv]
100
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k pv_uv[uv]
1

收集到了,去zabbix页面添加监控项

4.在zabbix页面添加主机配置监控项

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

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

5.添加图形

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

6.查看图形 查看数据

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Q274948451/article/details/108746289