Zabbix 6.2.3部署搭建(基于LNMP平台) 您所在的位置:网站首页 百度网盘下载劵怎么赠送 Zabbix 6.2.3部署搭建(基于LNMP平台)

Zabbix 6.2.3部署搭建(基于LNMP平台)

2023-12-23 17:58| 来源: 网络整理| 查看: 265

系统版本 CentOS Linux 7 (Core) 内核版本 Linux 3.10.0-1160.el7.x86_64 Nginx nginx-1.22.1 PHP php-8.1.11 MySQL mysql-8.0.31 Zabbix zabbix-6.2.3

Linux使用的最小化安装,很多工具没有,在实际部署过程中进行安装,安装过程中绝大部分错误都是因为缺少了依赖或者缺少模块。 提前关闭防火墙以及selinux

一、软件下载

软件下载均来自官网(也可通过国内的镜像源下载),版本根据实际情况可自行选择,安装过程尽可能参考官方文档,对部署其他系统也能有一定参考

1、官网下载Ngnix

下载地址:http://nginx.org/en/download.html image

2、官网下载PHP

下载地址:https://www.php.net/downloads.php image

3、官网下载MySQL

Mysql没使用yum源安装,感觉下载会很慢,直接下载的,本次部署使用的rpm全量包,也可自行选择二进制安装 下载地址:https://dev.mysql.com/downloads/mysql/

image

image

4、官网下载Zabbix

zabbix依旧选择下载源码自行编译安装,其他安装方式可参考官方文档 下载地址:https://www.zabbix.com/cn/download_sources#62 image

二、LNMP安装

在/opt下创建installpackge目录,上传安装包,之后的包均放在该位置 image

1、Nginx源码安装 1.1依赖-解压编译安装 systemctl stop firewalld yum -y install gcc gcc-c++ zlib-devel pcre-devel tar -zxvf nginx-1.22.1.tar.gz ./configure --prefix=/opt/nginx make && make install 安装完成进行启动验证 cd /opt/nginx/sbin ./nginx

image image

1.2安装问题

安装只指定了安装路径,有其他需求./configure --help image 问题:/configure: error: the HTTP gzip module requires the zlib library. image

解决:可能就是缺乏某个依赖,安装相关的依赖即可

2、PHP源码安装 2.1解决依赖-编译安装 ##zabbix ui需要php的很多模块支持这些依赖都是测试后必须的 yum -y install libxml2-devel sqlite-devel libpng-devel libjpeg-devel freetype-devel openssl-devel bzip2-devel libcurl-devel readline-devel rpm -ivh https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-6.9.8-1.el7.remi.x86_64.rpm rpm -ivh https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-devel-6.9.8-1.el7.remi.x86_64.rpm wget https://libzip.org/download/libzip-1.3.2.tar.gz --no-check-certificate tar -zxvf libzip-1.3.2.tar.gz cd libzip-1.3.2 rpm -qa| grep libzip| xargs rpm -e ##卸载掉自带的,一般版本都会过低后面生成Makefile会报错 ./configure make && make install export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" ##添加libzip的临时环境变量否则configure会识别不到 tar -zxvf php-8.1.11.tar.gz ##要想正常进入zabbix的ui界面很多模块都必须安装,否者会一直报连接被拒,如需其他模块参考中文文档 ./configure --prefix=/opt/php --enable-fpm --enable-shared --enable-soap --with-openssl --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --enable-gd --with-jpeg --with-freetype --with-gettext --enable-mbstring --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-readline --enable-shmop --enable-sockets --with-zip --enable-mysqlnd-compression-support --with-pear --enable-pcntl --enable-posix --enable-simplexml make && make install cd /opt/php/etc mv php-fpm.conf.default php-fpm.conf cd /opt/php/etc/php-fpm.d mv www.conf.default www.conf cp /opt/installpackge/php-8.1.11/php.ini-development /opt/php/lib/php.ini ##php.ini-development为开发环境使用 #创建启动用户 groupadd www-data useradd -g www-data www-data #修改配置文件 vim /opt/php/etc/php-fpm.d/www.conf ##修改以下参数 user = www-data group = www-data vim /opt/php/lib/php.ini cgi.fix_pathinfo=0 启动PHP cd /opt/php/sbin ./php-fpm 2.2Ngnix配置php vim /opt/ngnix/conf/nginx.conf #添加以下内容 location / { root html; index index.php index.html index.htm; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } #nginx重新加载 ./nginx -s reload #创建php测试文件 echo "" >> /opt/nginx/html/index.php 浏览器访问http://192.168.110.183/index.php

image

image

2.3安装问题

PHP中文文档:https://www.php.net/manual/zh/install.unix.nginx.php image

问题:configure: WARNING: unrecognized options: --with-mysql 解决:./configure --help 查看configure的正确语法,重新编译php支持mysql,改用--with-pdo-mysql image

问题:configure: error: Package requirements (libxml-2.0 >= 2.9.0) were not met:No package 'libxml-2.0' found Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables LIBXML_CFLAGS and LIBXML_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details. image 解决:缺少libxml依赖,安装即可

3、MySQL安装(rpm安装) 3.1 安装 groupadd mysql useradd -g mysql mysql cd /opt/install tar -xvf mysql-8.0.31-1.el7.x86_64.rpm-bundle.tar rpm -ivh mysql-community-common-8.0.31-1.el7.x86_64.rpm rpm -ivh mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-8.0.31-1.el7.x86_64.rpm rpm -ivh mysql-community-client-8.0.31-1.el7.x86_64.rpm rpm -ivh mysql-community-icu-data-files-8.0.31-1.el7.x86_64.rpm rpm -ivh mysql-community-server-8.0.31-1.el7.x86_64.rpm rpm -ivh mysql-community-devel-8.0.31-1.el7.x86_64.rpm su - mysql ##切记使用mysql用户启动,否则重启之后就会应为文件权限出现各种问题 systemctl start mysqld grep 'temporary password' /var/log/mysqld.log ##mysql启动还没有设置密码,会生成一个临时的 mysql -uroot -p mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; ##MyNewPass4!为设置的密码,有复杂度检验。 3.2 安装问题

mysql官方文档:https://dev.mysql.com/doc/refman/8.0/en/linux-installation-rpm.html

问题:Error: Package: mysql-community-server-8.0.31-1.el7.x86_64 (/mysql-community-server-8.0.31-1.el7.x86_64) Requires: mysql-community-icu-data-files = 8.0.31-1.el7 You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest image 解决:需要先安装mysql-community-icu-data-files-8.0.31-1.el7.x86_64.rpm再安装server包

问题:warning: mysql-community-libs-8.0.31-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY error: Failed dependencies: mariadb-libs is obsoleted by mysql-community-libs-8.0.31-1.el7.x86_64 解决:yum remove mysql-libs

image

问题:mysql需要密码 image

解决:grep 'temporary password' /var/log/mysqld.log

后续启动zabbix——server:zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory 其实是缺少libmysqlclient.so.18,我们使用得8.0的包对应的是libmysqlclient.so.22 解决:官网下载mysql-community-libs-compat老版本rpm包(或者使用wget下载) wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm yum -y install mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm

问题:mysqld: File './binlog.index' not found (OS errno 13 - Permission denied)使用了root用户启动mysql重启之后报错 解决:/var/lib/mysql目录下有文件所有权为root了,修改回来即可

三、Zabbix安装(源码安装) 1、编译安装 zabbix不能使用root用户启动 groupadd zabbix useradd -g zabbix zabbix tar -zxvf zabbix-6.2.3.tar.gz ##安装依赖,检查时可能会出现很多依赖缺失,这边把安装过程中的依赖都写下来了,要是报类似的错误可以去安装相关的依赖 wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm ##安装net-snmp-devel会需要libmysqlclient.so.18,mysql8.0提供的是22所以这边下载的5.7的lib yum install -y net-snmp-devel OpenIPMI-devel libevent-devel curl-devel cd /opt/install/zabbix-6.2.3 ./configure --prefix=/opt/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi ##模块选择去掉了ipv6,测试时发现直接使用该模块,网络会出问题,远程会直接掉 make install

image

2、创建zabbix数据库 ##创建Zabbix数据库 mysql -uroot -p create database zabbix character set utf8 collate utf8_bin; create user zabbix@'%' identified by 'password'; ##password为zabbix用户密码,不能太简单 grant all privileges on zabbix.* to 'zabbix'@'%'; flush privileges; SET GLOBAL log_bin_trust_function_creators = 1; ##不执行这句初始zabbix库时会报错

image

3、初始化zabbix库 ##执行源码中的三个建库语句,有需要的自行看官方文档 cat /opt/installpackge/zabbix-6.2.3/database/mysql/schema.sql | mysql -uzabbix -p zabbix cat /opt/installpackge/zabbix-6.2.3/database/mysql/images.sql | mysql -uzabbix -p zabbix cat /opt/installpackge/zabbix-6.2.3/database/mysql/data.sql | mysql -uzabbix -p zabbix 4、修改配置启动服务 vim /opt/zabbix/etc/zabbix_server.conf #取消DBPassword的注释修改为自己的密码 DBPassword=mypasswd cd /opt/zabbix/sbin ./zabbix_server ./zabbix_agentd

image

5、安装网页界面 5.1、 复制界面文件 #在nginx的html文件下新建zabbix文件夹,将源码包中的ui文件下的所有内容复制过去 mkdir -p /opt/ngnix/html/zabbix cp -r /opt/installpackge/zabbix-6.2.3/ui/* /opt/ngnix/html/zabbix/ http://192.168.110.183/zabbix/setup.php

image

image

5.2、修改php配置

修改php配置(zabbix需要php的很多模块,官方文档并未说出,要是还有少的模块可以单独安装需要的模块,这里是安装完才写的文档,需要的模块都提前安装了)打开php.ini按照要求将post_max_size、max_execution_time、max_input_time的值调整为最低要求值后重启php image

5.3配置数据库 允许mysql远程登陆 mysql -uroot -p use mysql select User,authentication_string,Host from user; ##mysql默认不允许远程登陆,如果你的用户Host为locahost则执行以下语句 update user set host='%' where user='zabbix'; flush privileges;

image

image 疯狂下一步会出现 Unable to create the configuration file.(无法创建配置文件) 相当于web用户无法往/opt/nginx/html/zabbix/conf中写入,可以按照提示手动导入,也可以执行chmod 777 /opt/nginx/html/zabbix/conf

默认用户:Admin 默认密码:zabbix

image

6、问题及解决(大多依赖问题,未列出全部)

官方文档(更换其他软件版本可参考文档的最低支持)https://www.zabbix.com/documentation/6.0/zh/manual/installation/requirements 问题:configure: error: MySQL library not found 解决:缺少mysql开发库之前下载的全量包直接安装,yum -y install /opt/installpackge/mysql-community-devel-8.0.31-1.el7.x86_64.rpm

问题:configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config 解决:yum install -y net-snmp-devel image

问题:configure: error: Invalid OPENIPMI directory - unable to find ipmiif.h 解决:yum install -y OpenIPMI-devel image

问题:ERROR 1419 (HY000) at line 2119: You do not have the SUPER privilege and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable) 解决: (初始化数据库前需要执行该语句,否则会失败,再次执行第一行就会提示表存在需要删库重建)mysql> SET GLOBAL log_bin_trust_function_creators = 1; image 参考:https://www.yuchenw.com/help/show.asp?id=3294 问题:zabbix_server [43308]: user zabbix does not exist zabbix_server [43308]: cannot run as root!

解决:需要建立启动zabbix的用户 image

问题:Host 'zabbix' is not allowed to connect to this MySQL server 解决:mysql不允许远程登陆执行 update user set host='%' where user='zabbix'; flush privileges;

问题:Error connecting to database: Access denied for user 'zabbix' @ 'localhost' to database 'zabbixdb' 解决:zabbix无zabbix库的权限需添加 grant all privileges on zabbix.* to 'zabbix'@'%'; flush privileges;



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有