失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 基于 LNMP 部署 Zabbix 集中监控系统(图文详解 篇幅较长!)

基于 LNMP 部署 Zabbix 集中监控系统(图文详解 篇幅较长!)

时间:2023-08-13 07:16:09

相关推荐

基于 LNMP 部署 Zabbix 集中监控系统(图文详解 篇幅较长!)

文章目录

一、Zabbix 概述二、安装配置 Zabbix 服务1.环境概述2.关闭防火墙/安全机制/网络管理工具3.搭建 LNMP 架构①Nginx②MySQL(MariaDB)③PHP④PHP 测试网页4.安装 Zabbix Server①建议②部署过程③登录 Web 页面完成 Zabbix 配置5.配置 Client 代理端三、使用 Zabbix 管理平台1.启用中文界面2.Zabbix 监控服务器①创建主机②链接监控模板③查看主机列表④查看监控数据

一、Zabbix 概述

Zabbix 是一个基于 Web 管理界面的提供分布式系统/网络监控的企业级的开源解决方案

Zabbix 官方网址:【/cn/】,有中文版,比较友好,软件可以自由下载使用!

Zabbix 具备常见商业监控软件所具备的功能

能够监控主机性能、网络设备性能及数据库性能可定制告警机制,比较灵活:允许用户对事件发送基于 E-mail 的警告,可以保证相关运维人员对问题快速响应(半夜惊醒…)还可以利用所存储的数据来提供实时的图形化数据处理及报表,以实现对 Linux、Windows 主机的 7×24 小时集中监控

Zabbix 能够监控的项目:CPU、内存、磁盘、网卡流量、服务可用性等各种资源,强大!

二、安装配置 Zabbix 服务

1.环境概述

本实验是在 LNMP 的架构基础之上搭建 Zabbix,皆是使用 YUM 安装

2.关闭防火墙/安全机制/网络管理工具

hostnamectl set-hostname server'//另一台主机为client'susystemctl stop firewalld && systemctl disable firewalldsetenforce 0 && sed -i "s/SELINUX=*/SELINUX=disabled/g" /etc/selinux/config'//关闭安全访问控制机制及设置不再自启动'systemctl stop NetworkManager && systemctl disable NetworkManager'//NetworkManager和network是CentOS上的两种网络工具,可能会引起冲突''//这里选择关闭NetworkManager'

3.搭建 LNMP 架构

①Nginx

'//本地CentOS系统中的本地YUM仓库没没有Nginx,不能直接yum install''//这里我们选择配一个Nginx的YUM仓库'vim /etc/yum.repos.d/nginx.repo'//配置nginx的yum仓库'[nginx-stable]name=nginx stable repobaseurl=/packages/centos/$releasever/$basearch/gpgcheck=0enabled=1--yum clean all && yum makecache fast'//将软件包信息提前在本地缓存一份,用以提高搜索安装软件的速度'yum -y install nginxsystemctl start nginx.service && systemctl enable nginx.service--'//打开浏览器访问【192.168.126.11】测试nginx是否搭建成功'

②MySQL(MariaDB)

从 CentOS7 开始使用 MariaDB 作为默认数据库,安装效率较快,所以这里选择!

yum -y install mariadb-server mariadbsystemctl start mariadb.service && systemctl enable mariadb.servicenetstat -natp|grep 3306

--mysql_secure_installation'//执行mysql安全配置向导'NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we'll need the currentpassword for the root user. If you've just installed MariaDB, andyou haven't set the root password yet, the password will be blank,so you should just press enter here.Enter current password for root (enter for none): '//回车'OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.Set root password? [Y/n] y'//设置密码'New password: Re-enter new password: '//确认密码'Password updated successfully!Reloading privilege tables..... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y'//是否删除匿名用户'... Success!Normally, root should only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] y'//是否禁止root远程登录'... Success!By default, MariaDB comes with a database named 'test' that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] n'//是否删除test数据库'... skipping.Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] y'//是否重新加载权限表'... Success!Cleaning up...All done! If you've completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB!--mysql -uroot -p123123'//测试能否登录mysql数据库'show databases;exit

③PHP

rpm -Uvh /pub/epel/epel-release-latest-7.noarch.rpmrpm -Uvh /yum/el7/webtatic-release.rpm'//Uvh选项作用是升级软件包'yum -y install php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql'//安装PHP环境工具包,耗时较长'php -v'//查看php版本'

vim /etc/php-fpm.d/www.confuser = nginx'//第8行,修改'group = nginx'//第10行,修改'--vim /etc/nginx/conf.d/default.conf'//修改nginx配置文件以与php相关联'index index.php index.html index.htm;'//第10行,添加index.php文件'location ~ \.php$ {'//31-37行,取消注释并修改,配置php请求传送到后端的php-fpm模块的配置'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;'//将fastcgi_param中的/scripts改为$document_root,root是配置php程序纺织的根目录'include fastcgi_params;}--vim /etc/php.ini'//优化PHP配置文件'short_open_tag = On'//202行改为On,支持php短标签'expose_php = Off'//359修改为Off,隐藏php版本''//以下都是zabbix的配置要求'max_execution_time = 300'//368行,执行时间,在一个程序执行的过程中能够等待的执行时间,执行时间过程中如果没有执行完会结束该程序,以防出现卡死,默认30秒'max_input_time = 300'//378行,接受数据的等待时间'memory_limit = 128M'//389行,每个脚本的占用内存限制'post_max_size = 16M'//656行,post数据的最大限制'upload_max_filesize = 2M'//799,下载文件的大小限制'always_populate_raw_post_data = -1'//800行添加此句,可以用$HTTP_RAW_POST_DATA接受post raw data(原始未处理数据)'date.timezone = Asia/Shanghai'//878行,修改时区为上海'--systemctl start php-fpm && systemctl enable php-fpm && systemctl restart nginxnetstat -natp|grep 9000

④PHP 测试网页

vim /usr/share/nginx/html/info.php'/编写PHP测试首页/'<?phpphpinfo();?>--'//访问网页【192.168.126.11/info.php】测试'

vim /usr/share/nginx/html/info.php'//重新修改首页文件,测试数据库是否连接'<?php$link=mysqli_connect('127.0.0.1','root','123123');if ($link) echo "连接成功";else echo "连接失败";?>--'//访问网页【192.168.126.11/info.php】测试'

mysql -uroot -p123123CREATE DATABASE zabbix character set utf8 collate utf8_bin;'//创建zabbix库,并设置好字符集问题'GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY '123123';'//创建数据库用户及配置用户权限'flush privileges;'//重载权限表以生效'exit--vim /usr/share/nginx/html/info.php'//重改PHP首页,测试zabbix数据库是否连接成功'<?php$link=mysqli_connect('127.0.0.1','zabbix','123123');if ($link) echo "zabbix数据库连接成功";else echo "连接失败";?>--'//访问网页【192.168.126.11/info.php】测试'

4.安装 Zabbix Server

①建议

可以去官网看看,帮助很大:/cn

目前来看,Zabbix 使用最稳定的版本是 4.0,LTS 指长期支持的版本

②部署过程

'//以上可做参考,建议看看,下面开始正文,放代码'rpm -Uvh /zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm'//安装升级zabbix存储库'yum clean all'//清除YUM缓存'yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent'//安装Zabbix server,Web前端,agent,耗时较长!'

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix'//导入初始架构和数据,系统将提示您输入新创建的密码'mysql -uzabbix -p123123'//登录数据库zabbix'show databases;use zabbix;show tables;'//可以查看到导入的数据'--cp -r /usr/share/zabbix/ /usr/share/nginx/html/'//-r表示递归复制目录'chown -R zabbix:zabbix /etc/zabbixchown -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/'//递归修改文件权限'--vim /etc/zabbix/zabbix_server.conf'//优化zabbix配置文件'DBHost=localhost'//91行,取消注释'DBPassword=123123'//124行,设置密码'--systemctl start zabbix-server.service && systemctl enable zabbix-server.service systemctl start zabbix-agent.service && systemctl enable zabbix-agent.servicenetstat -natp|grep 10051netstat -natp|grep 'zabbix'systemctl restart php-fpm.service && systemctl restart nginx

③登录 Web 页面完成 Zabbix 配置

'//登录zabbix网站【192.168.126.11/zabbix】,用户名:Admin,密码:zabbix'

再次确定后,会出来一个界面,提示你需要登录!

5.配置 Client 代理端

rpm -Uvh /zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpmyum -y install zabbix-agent'//安装zabbix存储库与agent代理服务'--vim /etc/zabbix/zabbix_agentd.conf'//修改zabbix代理配置文件'Server=192.168.126.11'//98行,指向监控服务器地址'ServerActive=192.168.126.11'//139行,指向监控服务器地址'Hostname=Zabbix-test'//150行,修改名称'--systemctl start zabbix-agent.service && systemctl enable zabbix-agent.servicenetstat -ntap |grep 'zabbix'

三、使用 Zabbix 管理平台

1.启用中文界面

2.Zabbix 监控服务器

①创建主机

②链接监控模板

③查看主机列表

④查看监控数据

还有很多很多应用,小伙伴自行探索~

如果觉得《基于 LNMP 部署 Zabbix 集中监控系统(图文详解 篇幅较长!)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。