Zabbix rapid deployment + monitoring nginx

Prepare two centos7 virtual machines

Insert picture description here

Turn off firewall time synchronization

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

1. Upload zabbix yum source to install 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. Start mysql to create a zabbix database authorized user

[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. Import the data into the zabbix database

[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. Configure to start zabbix

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

Insert picture description here

Modify the time zone, otherwise the page will report an error for a while
[root@localhost ~]# vim /etc/httpd/conf.d/zabbix.conf 
改成上海时区

Insert picture description here

Start zabbix and view the port
[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. Visit zabbix

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Modify Chinese interface

Insert picture description here
Insert picture description here
Insert picture description here

The page data is garbled to solve the garbled

Insert picture description here

[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

Insert picture description here

2. Upload zabbix yum source to install 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. Configure and start zabbix_agent

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

Insert picture description here
Insert picture description here

[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. Test whether it is connected to the server

Download zabbix-get test on server
[root@localhost ~]# yum -y install zabbix-get
[root@localhost ~]# zabbix_get -s 192.168.27.137 -k agent.ping
1
返回值为1 则为 ok

3. Install and monitor nginx pv_uv

pv visits The amount of page visits, the
number of uv visits per visit refers to the number of visits by independent visitors, and one computer terminal is one visitor.

To monitor nginx, first install nginx
先安装epel源
[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum -y install nginx
[root@localhost ~]# systemctl start nginx
There is no log after installing nginx, let's take ab pressure test, production log
[root@localhost ~]# yum -y install httpd-tools
[root@localhost ~]# ab -n 100 -c 100 http://192.168.27.137/
Collect pv_uv first create a directory editing script to put the script
[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
Custom create key value and restart 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                                                
Test on 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. Add host configuration monitoring items on the zabbix page

Insert picture description here
Insert picture description here
Insert picture description here

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

5. Add graphics

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

6. View the graph to view the data

Insert picture description here

Guess you like

Origin blog.csdn.net/Q274948451/article/details/108746289