Implemente el sistema de monitoreo centralizado Zabbix basado en LNMP (imágenes y textos detallados, ¡mayor extensión!)

Uno, descripción general de Zabbix

Zabbix es una solución de código abierto de nivel empresarial que proporciona un sistema distribuido / monitoreo de red basado en una interfaz de administración web.

Sitio web oficial de Zabbix : [ https://www.zabbix.com/cn/ ], hay una versión en chino, que es más amigable, y el software se puede descargar y usar libremente.

Zabbix tiene las funciones de un software de monitoreo comercial común :

  1. Capacidad para monitorear el rendimiento del host, el rendimiento del equipo de red y el rendimiento de la base de datos
  2. Mecanismo de alarma personalizable, más flexible: permite a los usuarios enviar advertencias por correo electrónico a los eventos, lo que puede garantizar que el personal de operación y mantenimiento relevante responda rápidamente a los problemas (se despierta en medio de la noche ...)
  3. Los datos almacenados también se pueden utilizar para proporcionar informes y procesamiento de datos gráficos en tiempo real para lograr un monitoreo centralizado de 7 × 24 horas de los hosts de Linux y Windows

Proyectos que Zabbix puede monitorear : CPU, memoria, disco, tráfico de la tarjeta de red, disponibilidad del servicio y otros recursos, ¡poderoso!


Dos, instale y configure el servicio Zabbix

1. Panorama ambiental

Anfitrión Sistema operativo dirección IP Software principal
Servidor CentOS7.9 192.168.126.11 LNMP 、 Zabbix
Cliente CentOS7.9 192.168.126.12 Agente Zabbix

Este experimento es para construir Zabbix basado en la arquitectura LNMP, todos los cuales se instalan usando YUM


2. Apague el cortafuegos, el mecanismo de seguridad y las herramientas de gestión de la red.

hostnamectl set-hostname server		'//另一台主机为client'
su

systemctl stop firewalld && systemctl disable firewalld

setenforce 0 && sed -i "s/SELINUX=*/SELINUX=disabled/g" /etc/selinux/config
'//关闭安全访问控制机制及设置不再自启动'

systemctl stop NetworkManager && systemctl disable NetworkManager
'//NetworkManager和network是CentOS上的两种网络工具,可能会引起冲突'
'//这里选择关闭NetworkManager'

3. Construya la arquitectura LNMP

①Nginx

'//本地CentOS系统中的本地YUM仓库没没有Nginx,不能直接yum install'
'//这里我们选择配一个Nginx的YUM仓库'

vim /etc/yum.repos.d/nginx.repo		'//配置nginx的yum仓库'

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

--
yum clean all && yum makecache fast
'//将软件包信息提前在本地缓存一份,用以提高搜索安装软件的速度'

yum -y install nginx

systemctl start nginx.service && systemctl enable nginx.service

--
'//打开浏览器访问【192.168.126.11】测试nginx是否搭建成功'
Marcos Marcos

②MySQL (MariaDB)

Dado que CentOS7 usa MariaDB como la base de datos predeterminada, la eficiencia de la instalación es más rápida, ¡así que elija aquí!

yum -y install mariadb-server mariadb

systemctl start mariadb.service && systemctl enable mariadb.service

netstat -natp|grep 3306
Marcos
--
mysql_secure_installation		'//执行mysql安全配置向导'

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you 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 MariaDB
root 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 anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y		'//是否删除匿名用户'
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures 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 can
access.  This is also intended only for testing, and should be removed
before 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 far
will 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 MariaDB
installation should now be secure.

Thanks for using MariaDB!

--
mysql -uroot -p123123		'//测试能否登录mysql数据库'

show databases;

exit
Marcos

③PHP

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
'//Uvh选项作用是升级软件包'

yum -y install php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql
'//安装PHP环境工具包,耗时较长'

php -v		'//查看php版本'
Marcos
vim /etc/php-fpm.d/www.conf

user = 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 nginx

netstat -natp|grep 9000
Marcos

④Página de prueba de PHP

vim /usr/share/nginx/html/info.php		'/编写PHP测试首页/'

<?php
 phpinfo();
?>

--
'//访问网页【192.168.126.11/info.php】测试'
Marcos
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】测试'
Marcos
mysql -uroot -p123123

CREATE 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】测试'
Marcos

4. Instale Zabbix Server

①Recomendación

Puedes ir al sitio web oficial para echar un vistazo, ayuda mucho: https://www.zabbix.com/cn

Marcos Marcos

En la actualidad, la versión más estable utilizada por Zabbix es 4.0, y LTS se refiere a la versión soportada a largo plazo.

Marcos

②El proceso de implementación

'//以上可做参考,建议看看,下面开始正文,放代码'

rpm -Uvh https://repo.zabbix.com/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,耗时较长!'
Marcos
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/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/
'//递归修改文件权限'

--
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.service

netstat -natp|grep 10051
netstat -natp|grep 'zabbix'

systemctl restart php-fpm.service && systemctl restart nginx
Marcos

③Inicie sesión en la página web para completar la configuración de Zabbix

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

MarcosMarcos

MarcosMarcos

Marcos Marcos Marcos

Después de confirmar nuevamente, aparecerá una interfaz que le pedirá que inicie sesión.

Marcos Marcos Marcos Marcos

5. Configurar el agente de cliente

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
'//安装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.service

netstat -ntap |grep 'zabbix'
Marcos

Tres, use la plataforma de gestión Zabbix

1. Habilite la interfaz china

Marcos Marcos

2. Servidor de monitoreo Zabbix

①Crear anfitrión

Marcos

②Plantilla de monitoreo de enlaces

Marcos

Marcos

③Ver la lista de hosts

Marcos

④Ver datos de monitoreo

Marcos
Hay muchas, muchas aplicaciones, los amigos exploran por sí mismos ~

Supongo que te gusta

Origin blog.csdn.net/weixin_51486343/article/details/115009942
Recomendado
Clasificación