用lnmp的zabbix部署

1.zabbix服务端安装

//安装依赖包
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel
安装过程略....

//下载zabbix
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz
下载过程略....

//解压
[root@localhost src]# tar xf zabbix-4.0.3.tar.gz

//创建zabbix用户和组
[root@localhost ~]# groupadd -r zabbix
[root@localhost ~]# useradd -r -g zabbix -M -s /sbin/nologin zabbix


//配置zabbix数据库
[root@localhost mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123!';
Query OK, 0 rows affected, 2 warnings (0.29 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye

[root@localhost ~]# cd /usr/src/zabbix-4.0.3/database/mysql/
[root@localhost mysql]# ls
data.sql  images.sql  schema.sql
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.



//编译安装zabbix
[root@localhost ~]# cd /usr/src/zabbix-4.0.3
[root@localhost zabbix-4.0.3]# ./configure --enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2

[root@localhost zabbix-4.0.3]# make install

2.zabbix服务端配置

[root@localhost ~]# ls /usr/local/etc/
zabbix_agentd.conf  zabbix_agentd.conf.d  zabbix_server.conf  zabbix_server.conf.d

//修改服务端配置文件
//设置数据库信息
[root@localhost ~]# vim /usr/local/etc/zabbix_server.conf
....
DBPassword=zabbix123!       //设置zabbix数据库连接密码


//启动zabbix_server和zabbix_agentd
[root@localhost ~]# zabbix_server
[root@localhost ~]# zabbix_agentd
[root@localhost ~]# ss -antl
State       Recv-Q Send-Q      Local Address:Port                     Peer Address:Port
LISTEN      0      128                     *:22                                  *:*
LISTEN      0      100             127.0.0.1:25                                  *:*
LISTEN      0      128                     *:10050                               *:*
LISTEN      0      128                     *:10051                               *:*
LISTEN      0      128             127.0.0.1:9000                                *:*
LISTEN      0      128                    :::80                                 :::*
LISTEN      0      128                    :::22                                 :::*
LISTEN      0      100                   ::1:25                                 :::*
LISTEN      0      80                     :::3306                               :::*

3.zabbix的web界面安装

//修改/etc/php.ini的配置并重启php-fpm
[root@localhost ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done

[root@localhost ~]# cd  /usr/src/zabbix-4.0.3
[root@localhost zabbix-4.0.3]# ls
aclocal.m4  ChangeLog     config.log     configure.ac  frontends   m4           man      README
AUTHORS     compile       config.status  COPYING       include     Makefile     misc     sass
bin         conf          config.sub     database      INSTALL     Makefile.am  missing  src
build       config.guess  configure      depcomp       install-sh  Makefile.in  NEWS
[root@localhost zabbix-4.0.3]# mkdir /usr/local/nginx/html/zabbix
[root@localhost zabbix-4.0.3]# cp -a frontends/php/* /usr/local/nginx/html/zabbix
[root@localhost zabbix-4.0.3]# chown -R nginx.nginx /usr/local/nginx/html/zabbix

配置nginx的配置文件
[root@localhost ~]# cd /usr/local/nginx/conf/
[root@localhost conf]# vim nginx.conf
   server {
        listen       80;
        server_name  zabbix.wangqing.com;  	## 将域名设置为zabbix.nginx.com       

        location / {				
                    root  html/zabbix;       	## 将访问的位置改为html/zabbix
            index  zabbix.php index.html;   ##将访问的文件设置为zabbix.php
        }
        
        location ~ \.php$ {
            root           html/zabbix;						## 将访问的位置改为html/zabbix
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  zabbix.php;                                    ## 将访问的php文件修改为zabbix.php
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

4.设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php

[root@localhost conf]# pwd
/usr/local/nginx/html/zabbix/conf
[root@localhost conf]# 
[root@localhost conf]# chmod 777 /usr/local/nginx/html/zabbix/conf

5.效果测试

在这里插入图片描述
zabbix密码zabbix123!
在这里插入图片描述
用户Admin,密码zabbix
在这里插入图片描述
在这里插入图片描述

5.用zabbix监控nginx状态

1.编写nginx的配置文件,开启status,
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
        location /status {
            stub_status on;
}
[root@localhost ~]# nginx -s reload
2.编写脚本
[root@localhost ~]# cd /scripts/
[root@localhost scripts]# cat accepts.sh 
#!/binbash

accepts=$(curl http://192.168.90.128/status 2>/dev/null|awk 'NR==3{print $1}')

echo "$accepts"
[root@localhost scripts]# cat requests.sh 
#!/bin/bash

requests=$(curl http://192.168.90.128/status 2>/dev/null|awk 'NR==3{print $3}')

echo "$requests"

3.给脚本执行权限并将其宿主改为zabbix
[root@localhost ~]# ll /scripts/
总用量 8
-rwxr-xr-x. 1 zabbix zabbix 108 1月   2 10:11 accepts.sh
-rwxr-xr-x. 1 zabbix zabbix 111 1月   2 10:10 requests.sh
[root@localhost ~]# ll /scripts/ -d
drwxr-xr-x. 2 zabbix zabbix 43 1月   2 11:44 /scripts/

4.修改zabbix配置文件
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf

UnsafeUserParameters=1
UserParameter=check_accepts, /bin/bash /scripts/accepts.sh
UserParameter=check_requests, /bin/bash /scripts/requests.sh


5.在Zabbix server上添加监控项

在这里插入图片描述

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

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值