基于LNMP架构的zabbix监控

文章目录

实验环境:

服务端 192.168.100.120
客户端 192.168.100.110

一、LNMP安装环境

先关闭防火墙及核心防护

systemctl stop firewalld.service 
systemctl disable firewalld.service 
setenforce 0

1、安装nginx1.14

wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm #安装nginx官方源
或
vim /etc/yum.repos.d/nginx.repo   #手动创建nginx yum安装源
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

yum install nginx -y  #安装nginx,默认为nginx-1.12.2
systemctl start nginx
systemctl enable nginx
 
netstat -ntap | grep nginx #查看端口是否打开

基于LNMP架构的zabbix监控基于LNMP架构的zabbix监控

2、安装mysql 5.7

yum install -y mariadb-server mariadb

systemctl start mariadb.service 
systemctl enable mariadb.service 

mysql_secure_installation

3、安装PHP

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
或
yum install epel-release -y

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm  #yum仓库建立

yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql #安装软件包

php -v #查看PHP版本

4、配置nginx支持php

vim /etc/php-fpm.d/www.conf

#第8行修改#  user = nginx
#第10行修改# group = nginx


vim /etc/nginx/conf.d/default.conf

#第10行修改# index.php index.html index.htm;

 #配置php请求被传送到后端的php-fpm模块,默认情况下php配置块是被注释的,此时去掉注释并修改

location ~ \.php$ {
          root           /usr/share/nginx/html;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php; 
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          include        fastcgi_params;
      }


vim /etc/php.ini

#修改第359行#  expose_php = off #隐藏php版本
#修改第202行#  short_open_tag = on #支持php短标签

以下为zabbix配置要求

#修改第368行# max_execution_time = 300 #执行时间
#修改第378行  max_input_time = 300    #接收数据等待时间
#修改第389行  memory_limit = 128M    #每个脚本占用内存
#修改第656行  post_max_size = 16M    #POST数据大小
#修改第799行  upload_max_filesize = 2M #下载文件大小
#修改第800行 always_populate_raw_post_data = -1  #可以用 $HTTP_RAW_POST_DATA 接收post raw data
#修改第877行  date.timezone = Asia/Shanghai  #时区

##开启PHP服务并重启nginx服务
systemctl start php-fpm.service
systemctl enable php-fpm.service

netstat -ntap | grep 9000

systemctl restart nginx

基于LNMP架构的zabbix监控

#测试主页
vim /usr/share/nginx/html/info.php

<?php
 phpinfo();
?>

<?php
$link=mysqli_connect('127.0.0.1','zabbix','admin123');
if($link) echo "success!!!!!";
else echo "false!!!!!";
?>

基于LNMP架构的zabbix监控

5、测试连接数据库

vim /usr/share/nginx/html/info.php

<?php
$link=mysqli_connect('127.0.0.1','zabbix','admin123');
if($link) echo "success!!!!!";
else echo "false!!!!!";
?>

刷新浏览器
基于LNMP架构的zabbix监控

6、准备zabbix数据库

#准备zabbix数据库

mysql -u root -p123123

CREATE DATABASE zabbix character set utf8 collate utf8_bin;

GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';

flush privileges;

#测试是否还能登录数据库

vim /usr/share/nginx/html/info.php

<?php
$link=mysqli_connect('127.0.0.1','zabbix','admin123');
if ($link) echo "Zabbix数据库连接成功!";
else echo "Zabbix数据库连接失败!";
?>

再次刷新网页查看
基于LNMP架构的zabbix监控

二、部署zabbix Server

1、下载zabbix源并安装

rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm

yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y

2、修改配置文件

vim /etc/zabbix/zabbix_server.conf

38:LogFile=/var/log/zabbix/zabbix_server.log
49:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
82:SocketDir=/var/run/zabbix
91:DBHost=localhost                #注释去掉
100:DBName=zabbix
116:DBUser=zabbix
124:DBPassword=admin123           #修改本行
356:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
473:Timeout=4
516:AlertScriptsPath=/usr/lib/zabbix/alertscripts
527:ExternalScripts=/usr/lib/zabbix/externalscripts
563:LogSlowQueries=3000


grep -n '^'[a-Z] /etc/zabbix/zabbix_server.conf  #检查修改的配置文件是否正确

3、赋予权限

cp -r /usr/share/zabbix/ /usr/share/nginx/html/
chown -R zabbix:zabbix /etc/zabbix
chown -R zabbix:zabbix /usr/share/nginx/
chown -R zabbix:zabbix /usr/lib/zabbix/
chmod -R 755 /etc/zabbix/web/
chmod -R 777 /var/lib/php/session/

4、导入数据库内容到zabbix数据库

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

mysql -u zabbix -padmin123
use zabbix;
show tables;

#修改时区

vim /etc/httpd/conf.d/zabbix.conf

#修改第20行# php_value date.timezonde Asia/Shanghai

把所有服务都启动

systemctl start zabbix-server.service
systemctl enable zabbix-server.service 

systemctl start zabbix-agent.service
systemctl enable zabbix-agent.service

systemctl restart php-fpm.service
systemctl restart nginx

netstat -anpl | grep 10051

基于LNMP架构的zabbix监控

5、网页安装登录

登入网页http://192.168.100.120/zabbix/
基于LNMP架构的zabbix监控
基于LNMP架构的zabbix监控
基于LNMP架构的zabbix监控
基于LNMP架构的zabbix监控
基于LNMP架构的zabbix监控
基于LNMP架构的zabbix监控

三、配置代理端

需要安装zabbix-agent

rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm

yum -y install zabbix-agent

vim /etc/zabbix/zabbix_agentd.conf

PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.100.120     # 指向监控服务器
ServerActive=192.168.100.120      # 指问监控服务器
Hostname=test1                      #指定名称
Include=/etc/zabbix/zabbix_agentd.d/*.conf

systemctl start zabbix-agent.service
systemctl enable zabbix-agent.service

netstat -ntap |grep 'zabbix'

基于LNMP架构的zabbix监控

zabbix监控服务器

基于LNMP架构的zabbix监控
基于LNMP架构的zabbix监控

基于LNMP架构的zabbix监控

基于LNMP架构的zabbix监控

查看监控数据

基于LNMP架构的zabbix监控

上一篇:LNMP源码编译


下一篇:部署LNMP+zabbix(监控工具)