当前位置: 首页 > news >正文

LNMP+Zabbix安装部署(Zabbix6.0 Lnmp+Zabbix Installation and Deployment)

LNMP+Zabbix安装部署(Zabbix6.0)

简介

LNMP(Linux + Nginx + MySQL + PHP)是一种流行的Web服务器架构,广泛用于搭建高性能的网站和应用程序。Zabbix 是一个开源的监控软件,可以用来监控网络、服务器和应用程序的性能和健康状态。将 Zabbix 集成到 LNMP 架构中可以提供全面的监控解决方案。下面将介绍如何在一个 LNMP 环境中安装和部署 Zabbix。

安装环境:

系统:centos7.0

nginx版本:1.20

php版本:php7.2.34

mysql版本:mysql8.0.30

zabbix版本:zabbix6.0.1

1、zabbix server端安装    

1.1、关闭系统防火墙    

systemctl stop firewalld.service

systemctl disable firewalld.service

firewall-cmd --state

sed -i '/^SELINUX=.*/c SELINUX=disabled' /etc/selinux/config

sed -i 's/^SELINUXTYPE=.*/SELINUXTYPE=disabled/g' /etc/selinux/config

grep --color=auto '^SELINUX' /etc/selinux/config

setenforce 0

1.2、mysql部署    

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.30-1.el7.x86_64.rpm-bundle.tar    

tar -xvf mysql-8.0.30-1.el7.x86_64.rpm-bundle.tar

rpm -ivh mysql-community-* --force --nodeps

mkdir -p /data/mysql

chown mysql:mysql /data/mysql

           vim /etc/my.cnf

[mysqld]

datadir=/data/mysql

socket=/var/lib/mysql/mysql.sock    

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

character-set-server=utf8mb4

collation-server=utf8mb4_general_ci

port=3306

lower_case_table_names=1

max_connections=4096

           启动数据库:

yum -y install libaio

systemctl enable mysqld    

systemctl start mysqld

           获取密码登录mysql:

cat /var/log/mysqld.log | grep password

mysql -uroot -pkegsOfDBY9?K

set global validate_password.policy=0;

set global validate_password.length=6;

set global validate_password.mixed_case_count=0;

alter user 'root'@'localhost' identified by 'abc123';

create database zabbix character set utf8 collate utf8_bin;

create user 'zabbix'@'localhost' identified with mysql_native_password by 'abc123';

grant all privileges on zabbix.* to 'zabbix'@'localhost';

flush privileges;

1.3、nginx部署    

rpm -Uvh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.20.0-1.el7.ngx.x86_64.rpm

mkdir /data/nginx

mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak

      vim /etc/nginx/nginx.conf

user  nginx;

worker_processes  auto;

error_log  /var/log/nginx/error.log notice;

pid        /var/run/nginx.pid;

               events {

    worker_connections  1024;

}

           http {

    include       /etc/nginx/mime.types;

    default_type  application/octet-stream;

           

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

               access_log  /var/log/nginx/access.log  main;

    sendfile        on;

    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    server {

      listen       80;

      server_name  localhost;

      root         /data/nginx;

      location / {

        index  index.php index.html index.htm;

      }

      location ~ \.php$ {

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        include        fastcgi_params;

      }

    }

}

           systemctl enable nginx

systemctl start nginx

systemctl status nginx

netstat -ntlp |grep 80

1.4、PHP部署    

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo    

yum -y install epel-release

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum -y install gcc gcc-c++ php72w-cli php72w-fpm php72w-gd php72w-mbstring php72w-bcmath php72w-xml php72w-ldap php72w-mysqlnd

sed -i "s/max_execution_time = 30/max_execution_time = 300/g" /etc/php.ini

sed -i "s/max_input_time = 60/max_input_time = 300/g" /etc/php.ini

sed -i "s/post_max_size = 8M/post_max_size = 16M/g" /etc/php.ini

cd /data/nginx/

vim index.php

<?phpphpinfo();?>

systemctl enable php-fpm

systemctl start php-fpm

netstat -ntlp |grep 9000

           使用浏览器验证一下Nginx和PHP:

1.5、zabbix-server部署    

groupadd zabbix

useradd -g zabbix -M -s /sbin/nologin zabbix

wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.1.tar.gz    

tar -xf zabbix-6.0.1.tar.gz

cd zabbix-6.0.1/

yum -y install  mysql-devel pcre-devel openssl-devel zlib-devel libxml2-devel net-snmp-devel net-snmp libssh2-devel OpenIPMI-devel libevent-devel openldap-devel libcurl-devel

./configure --sysconfdir=/etc/zabbix --enable-server --with-mysql --with-net-snmp --with-libxml2 --with-ssh2 --with-openipmi --with-zlib --with-libpthread --with-libevent --with-openssl --with-ldap --with-libcurl --with-libpcre

make install

vim /etc/zabbix/zabbix_server.conf

ListenPort=10051

LogFile=/tmp/zabbix_server.log

DBHost=localhost

DBName=zabbix

DBUser=zabbix

DBPassword=abc123

Timeout=4

LogSlowQueries=3000

StatsAllowedIP=127.0.0.1

#向数据库中导入zabbix的库表及数据(注意导入的顺序)

mysql -uzabbix -pabc123 zabbix < /root/zabbix-6.0.1/database/mysql/schema.sql

mysql -uzabbix -pabc123 zabbix < /root/zabbix-6.0.1/database/mysql/images.sql

mysql -uzabbix -pabc123 zabbix < /root/zabbix-6.0.1/database/mysql/data.sql

           #移动zabbix前端页面到网站根目录

cp -rf /root/zabbix-6.0.1/ui/* /data/nginx/

vim /usr/lib/systemd/system/zabbix-server.service

[Unit]

Description=Zabbix Server with MySQL DB

After=syslog.target network.target mysqld.service    

[Service]

Type=simple

ExecStart=/usr/local/sbin/zabbix_server -f

User=zabbix

[Install]

WantedBy=multi-user.target

           #重新加载system文件

systemctl daemon-reload

systemctl enable zabbix-server

systemctl start zabbix-server

1.6、Web端初始化    

1)、输入IP直接跳转至zabbix网页端

2)、这里已经调整过PHP的配置文件,如果还有问题的可以编辑/etc/php.ini ,调整对应字段的值即可    

3)、配置DB连接

4)、这里自定义Zabbix主机名称即可    

5)、安装

cp /data/nginx/conf/zabbix.conf.php.example /data/nginx/conf/zabbix.conf.php

chown zabbix:zabbix /data/nginx/conf/zabbix.conf.php    

vim /data/nginx/conf/zabbix.conf.php

#只修改PASSWORD的密码

$DB['PASSWORD']                 = 'abc123';

默认账号密码:Admin zabbix

1.7、解决zabbix 6.0 中文乱码问题    

将window的C:\Windows\Fonts路径下将楷体的ttf文件复制到linux的 /data/web/assets/fonts 目录下

#替换配置文件中的默认字体

sed -i 's/DejaVuSans/simkai/g' /data/nginx/include/defines.inc.php

zabbix不支持主机名中存在中文字符的,要让zabbix主机名支持中文,需要修改zabbix的php配置文件

vim /data/nginx/include/defines.inc.php

#将下面的字段(大概在1198 行)

define('ZBX_PREG_INTERNAL_NAMES', '([0-9a-zA-Z_\. \-]+)');

改成

define('ZBX_PREG_INTERNAL_NAMES', '([0-9a-zA-Z_\. \-\x{80}-\x{ff}]+)');

重启zabbix-server:

systemctl restart zabbix-server

2、zabbix agent端安装    

rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/6.0/rhel/7/x86_64/zabbix-agent-6.0.1-1.el7.x86_64.rpm?spm=a2c6h.25603864.0.0.4a7e7a10tEvrPp --nodeps

rpm -ivh http://mirror.centos.org/centos/7/os/x86_64/Packages/pcre2-10.23-2.el7.x86_64.rpm

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

ServerActive=127.0.0.1

Hostname=Zabbix server

Include=/etc/zabbix/zabbix_agentd.d/*.conf

启动Zabbix-agent服务:

systemctl start zabbix-agent

systemctl status zabbix-agent       

相关文章:

  • 02.05、链表求和
  • 【算法】回溯算法
  • spring boot知识点3
  • Dart 3.5 学习汇总(更新中)
  • 【Pandas】pandas Series last
  • Docker镜像拉取失败解决方案
  • centos7配置rsyslog日志服务器
  • 【阮一峰】5.函数
  • C++:并发编程基础
  • 【前端ES】ECMAScript 2023 (ES14) 引入了多个新特性,简单介绍几个不为人知但却好用的方法
  • 华为交换机堆叠技术简介配置
  • .NET SixLabors.ImageSharp v1.0 图像实用程序控制台示例
  • PBR光照模型相关知识
  • Spring核心思想之—AOP(面向切面编程)
  • 【笔记】LLM|Ubuntu22服务器极简本地部署DeepSeek+联网使用方式
  • Windows 图形显示驱动开发-WDDM 2.0-GPU 虚拟地址
  • 蓝桥杯单片机基础部分——单片机介绍部分
  • 浅析前端监控与埋点:洞察用户行为,优化产品体验
  • GTP3 大模型
  • vue3项目axios最简单封装 - ajax请求封装
  • 咸宁市委常委、市纪委书记官书云调任湖北省司法厅副厅长
  • 习近平会见古巴国家主席迪亚斯-卡内尔
  • 湖南省职业病防治院通报3岁女童确诊“铊中毒”:去年病例,编辑误写为“近日”
  • 山东14家城商行中,仅剩枣庄银行年营业收入不足10亿
  • 多人称华为手机忽现拍照模糊疑存缺陷,售后回应:主摄像头故障
  • 联合国秘书长吁印巴“最大程度克制”,特朗普:遗憾,希望尽快结束冲突