CentOS7下zabbix 6.0 LTS源码搭建部署
zabbix基本概述
zabbix是基于web界面的分布式系统监控与网络设备监控系统,能监控各种网络参数,并提供灵活的通知机制,以便管理员快速定位故障并解决
zabbix由两个部分组成: zabbix-server(服务端):zabbix的核心组件,zabbix server可以单独监视远程服务器的状态;也可以与zabbix agent配合,可以轮询zabbix agent主动接收监视数据(agent方式),同时还可以被动接收zabbix agent 发送的数据(traping方式 )zabbix agent(客户端):安装在需要被监控的服务器上,主要完成对硬件信息或与操作系统有关的内存、CPU等信息的收集
环境说明
软件 | 版本 | 备注 |
zabbix | 6.0.13 | |
mysql | 8.0.27 | mysql作为zabbix后端数据库,需要I浓浓DBengin |
NGINX | 1.20.0 | |
PHP | 7.4.7 | zabbix6.0 需要PHP版本7.25以上8.0以下 |
zabbix6.0 对相关软件版本要求较高,需要php7.25以上php8.0以下版本支持,若使用mysql数据库,其最低要求为mysql8.0
NGINX安装略
配置nginx.conf支持php解析
vim /mnt/nginx/conf/nginx.conf#配置如下server { listen 80; server_name localhost; location / { root html; index index.php index.html index.htm; } location / { index index.php index.html index.htm; } location ~ \.php$ { #root /mnt/nginx/html/zabbix/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
PHP安装
安装依赖包
yum -y install libxml2-devel sqlite-devel bzip2 bzip2-devel libcurl libcurl-devel
安装oniguruma:
一个正则表达式的库,在编译安装php时,使用--with-mbstring扩展模块需要oniguruma的支持
yum install https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-6.9.6-1.el7.remi.x86_64.rpmyum install https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-devel-6.9.6-1.el7.remi.x86_64.rpm
或源码:
wgethttps://github.com/kkos/oniguruma/releases/download/v6.9.5_rev1/onig-6.9.5-rev1.tar.gz -O onig-6.9.5.tar.gz tar xf onig-6.9.5.tar.gz cd onig-6.9.5 ./configure --prefix=/mnt/oniguruma --libdir=/lib64 make && make install
下载安装PHP
编译参数可查看:PHP: 其他变更 - Manual
wget https://www.php.net/distributions/php-7.4.7.tar.gztar xf php-7.4.7.tar.gz cd php-7.4.7/./configure --prefix=/mnt/php \--with-config-file-path=/mnt/php/etc \--with-bz2 \--with-curl \--enable-ftp \--enable-sockets \--disable-ipv6 \--enable-gd \-with-jpeg \--enable-fpm \--enable-mbstring \--with-openssl \--enable-bcmath \-with-gettext \--with-ldap-sasl \--with-mysqli \--with-pdo-mysql \--enable-bcmath \--with-freetype \--with-ldap=shared \--enable-calendar \--enable-dom \--enable-xml \--with-libdir=lib64
执行安装
make && make install
安装成功
Installing shared extensions: /mnt/php/lib/php/extensions/no-debug-non-zts-20190902/
Installing PHP CLI binary: /mnt/php/bin/
Installing PHP CLI man page: /mnt/php/php/man/man1/
Installing PHP FPM binary: /mnt/php/sbin/
Installing PHP FPM defconfig: skipping
Installing PHP FPM man page: /mnt/php/php/man/man8/
Installing PHP FPM status page: /mnt/php/php/php/fpm/
Installing phpdbg binary: /mnt/php/bin/
Installing phpdbg man page: /mnt/php/php/man/man1/
Installing PHP CGI binary: /mnt/php/bin/
Installing PHP CGI man page: /mnt/php/php/man/man1/
Installing build environment: /mnt/php/lib/php/build/
Installing header files: /mnt/php/include/php/
Installing helper programs: /mnt/php/bin/
program: phpize
program: php-config
Installing man pages: /mnt/php/php/man/man1/
page: phpize.1
page: php-config.1
/mnt/pack/php-7.4.7/build/shtool install -c ext/phar/phar.phar /mnt/php/bin
ln -s -f phar.phar /mnt/php/bin/phar
Installing PDO headers: /mnt/php/include/php/ext/pdo/
配置php.ini(zabbix硬性要求)
php.ini是php运行的核心配置文件
若没有自动生成php.ini文件
解压路径下复制:php.ini-development/php.ini-production
一个开发环境使用的,一个是生产环境使用的。根据自己的需要,修改配置文件并复制到/mnt/php/lib/目录下
cp php.ini-development /mnt/php/etc/php.inivim /mnt/php/etc/php.ini407 max_execution_time = 300428 memory_limit = 128M696 post_max_size = 16M848 upload_max_filesize = 2M417 max_input_time = 300972 date.timezone = Asia/Shanghai
配置php-fpm.conf(php-fpm进程的配置文件)
启用php-fpm进程,配置nginx支持php
cd /mnt/php/etccp php.fpm.conf.default php-fpm.confvim php-fpm-conf17 pid = run/php-fpm.pid#确认pid位置18 user = nginx#程序用户19 group = nginx#程序组
配置www.conf(php-fpm.d目录下)
是php-fpm进程服务的扩展配置文件
cp php-fpm.d/www.conf.default php-fpm.d/www.confvim /mnt/php/etc/php-fpm.d/www.conf28 user = nginx29 group = nginx127 pm.max_children = 50 #最多空闲进程数132 pm.start_servers = 20 #启动时开启的进程数137 pm.min_spare_servers = 5 #最少空闲进程数142 pm.max_spare_servers = 35 #最大空闲进程数
查看php版本
php -vPHP 7.4.7 (cli) (built: Mar 5 2023 17:56:31) ( NTS )Copyright (c) The PHP GroupZend Engine v3.4.0, Copyright (c) Zend Technologies
启动php-fpm进程
/mnt/php/sbin/php-fpm
PHP页面访问测试
vim /mnt/nginx/html/index.php
安装MySQL8
Mysql8.0.27 要求gcc的版本在4.8以上,版本低于4.8,需要自行升级
mysql从5.5版本开始,不再使用./configure编译,而是使用cmake编译器。
mysql从8.0.16版本开始,要求cmake的版本是cmake3以上
centos7.6默认安装的是cmake2.8.12.2和gcc4.8.5,这是为考虑向下兼容centos6.2及稳定性,但对编辑安装mysql8.0.16会形成阻碍,所以安装前建议升级cmake到cmake3以上
安装cmake
yum -y remove cmakewget https://github.com/Kitware/CMake/releases/download/v3.19.5/cmake-3.19.5.tar.gztar xf cmake-3.19.5.tar.gzcd cmake-3.19.5/#创建build文件夹,打开build文件夹,执行配置命令./bootstrap --prefix=/mnt/cmake3gmakemake install
升级gcc
wget ftp://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gztar xf gcc-9.2.0.tar.gzcd gcc-9.2.0/#载编译需要的依赖包./contrib/download_prerequisites./configure --prefix=/mnt/gcc4/ --enable-bootstrap --enable-checking=release --enable-threads=posix --enable-languages=c,c++,objc,obj-c++ --disable-multilib.
编译gcc报错:
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
configure: error: I suspect your system does not have 32-bit development libraries (libc and headers). If you have them, rerun configure with --enable-multilib. If you do not have them, and want to build a 64-bit-only compiler, rerun configure with --disable-multilib.
解决报错:
yum install glibc-devel.i686yum install libgcc.i686
再次执行configure命令成功,安装
make -j4make install
编译完成后,还需要将原来的gcc环境用新版本的gcc替换掉,否则mysql在安装时还是用的原来的gcc
依次执行:
mv /usr/bin/gcc /usr/bin/gcc447mv /usr/bin/g++ /usr/bin/g++447mv /usr/bin/c++ /usr/bin/c++447mv /usr/bin/cc /usr/bin/cc447ln -s /mnt/gcc4/bin/gcc /usr/bin/gccln -s /mnt/gcc4/bin/g++ /usr/bin/g++ln -s /mnt/gcc4/bin/c++ /usr/bin/c++ln -s /mnt/gcc4/bin/cc /usr/bin/ccmv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bakln -s /mnt/gcc4/lib64/libstdc++.so.6.0.27 /usr/lib64/libstdc++.so.6
验证gcc版本
gcc -v使用内建 specs。COLLECT_GCC=gccCOLLECT_LTO_WRAPPER=/mnt/gcc4/libexec/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper目标:x86_64-pc-linux-gnu配置为:./configure --prefix=/mnt/gcc4/ --enable-bootstrap --enable-checking=release --enable-threads=posix --enable-languages=c,c++,objc,obj-c++ --disable-multilib.线程模型:posixgcc 版本 9.2.0 (GCC)
安装编译mysql8.0
tar xf mysql-boost-8.0.27.tar.gzcd mysql-8.0.27/cmake -DCMAKE_INSTALL_PREFIX=/mnt/mysql8 -DMYSQL_DATADIR=/mnt/mysql8/data -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=/mnt/mysql8/boost
mysql编译报错
-- Running cmake version 3.19.5-- Found Git: /usr/bin/git-- This is .el7. as found from 'rpm -qf /'-- Looking for a devtoolset compilerCMake Warning at CMakeLists.txt:347 (MESSAGE):Could not find devtoolset compiler/linker in /opt/rh/devtoolset-10CMake Warning at CMakeLists.txt:349 (MESSAGE):You need to install the required packages:yum install devtoolset-10-gcc devtoolset-10-gcc-c++ devtoolset-10-binutilsCMake Error at CMakeLists.txt:351 (MESSAGE):Or you can set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER explicitly.-- Configuring incomplete, errors occurred!
根据报错提示安装devtoolset
yum -y install ll centos-release-sclyum install devtoolset-10-gcc devtoolset-10-gcc-c++ devtoolset-10-binutils提示:Is this ok [y/d/N]: Exiting on user command您的事务已保存,请执行:yum load-transaction /tmp/yum_save_tx.2023-03-02.23-21.M4_Kgg.yumtx 重新执行该事务yum load-transaction /tmp/yum_save_tx.2023-03-02.23-21.M4_Kgg.yumtxyum install devtoolset-10-gcc devtoolset-10-gcc-c++ devtoolset-10-binutils
报错:Please do not build in-source. Out-of source builds are highly
CMake Error at CMakeLists.txt:536 (MESSAGE):Please do not build in-source. Out-of source builds are highlyrecommended: you can have multiple builds for the same source, and there isan easy way to do cleanup, simply remove the build directory (note that'make clean' or 'make distclean' does not work)You can force in-source build by invoking cmake with-DFORCE_INSOURCE_BUILD=1-- Configuring incomplete, errors occurred!See also "/mnt/pack/mysql-8.0.27/CMakeFiles/CMakeOutput.log".
原因:建议不要构建源代码
解决:编译时加入字段 -DFORCE_INSOURCE_BUILD=1
cmake -DCMAKE_INSTALL_PREFIX=/mnt/mysql8 -DMYSQL_DATADIR=/mnt/mysql8/data -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=/mnt/boost1_8 -DFORCE_INSOURCE_BUILD=1 -DDOWNLOAD_BOOST=1make && make install
安装完成修改my.ini文件(根据环境)
[mysqld]port=3306basedir=/mnt/mysql8datadir=/mnt/mysql-datapid-file =/mnt/mysql8/mysql.pidsocket =/tmp/mysql.sockmax_connections=1000max_connect_errors=100character-set-server=utf8mb4log_error =/var/log/mysqld.logdefault-storage-engine=INNODBdefault_authentication_plugin=mysql_native_passwordlower_case_table_names = 1interactive_timeout = 1800wait_timeout = 1800lock_wait_timeout = 3600tmp_table_size = 64Mmax_heap_table_size = 64M[mysql]default-character-set=utf8mb4[client]port=3306default-character-set=utf8mb4
初始化数据库:
chown -R mysql.mysql /mnt/mysql8#初始化bin/mysqld --initialize --user=mysql --datadir=/mnt/mysql-data#初始化成功自动生成密码:root@localhost: ZkIG+i%gw1k8
启动mysql
cd /mnt/mysql8后台启动:bin/mysqld_safe --user=mysql &or使用安全模式进入mysql8 /mnt/mysql8/bin/mysqld_safe --defaults-file=/etc/my.cnf
登录数据库,修改原密码
[root@centos7-1 mysql8]# ./bin/mysql -uroot -p#修改登录密码:mysql> alter user 'root'@'localhost' identified by '010203';Query OK, 0 rows affected (0.02 sec)#查看版本号mysql> select version();+-----------+| version() |+-----------+| 8.0.27 |+-----------+1 row in set (0.00 sec)#查看目前用户mysql> select user,host from mysql.user;+------------------+-----------+| user | host |+------------------+-----------+| mysql.infoschema | localhost || mysql.session | localhost || mysql.sys | localhost || root | localhost |+------------------+-----------+4 rows in set (0.00 sec)
配置变量环境
vim /etc/profile# add mysqlexport PATH=$PATH:/usr/local/mysql8/bin. /etc/profile
配置启动项
cp /mnt/mysql8/support-files/mysql.server /etc/init.d/mysqld/etc/init.d/mysql stopservice mysqld startStarting MySQL... [ 确定 ]ss -anpt |grep mysqlLISTEN 0 70 [::]:33060 [::]:* users:(("mysqld",pid=75468,fd=21))LISTEN 0 128 [::]:3306 [::]:*
zabbix安装部署
安装zabbix服务端
下载地址:https://www.zabbix.com/download
1安装依赖包
yum -y install net-snmp-devel libevent-devel unixODBC-devel libxml2-devel libcurl-devel libssh2-devel OpenIPMI-devel openldap openldap-devel
解压编译安装zabbix
tar xf zabbix-6.0.13.tar.gz cd zabbix-6.0.13./configure --prefix=/mnt/zabbix \sysconfdir=/etc/zabbix \--enable-server \--enable-agent2 \--enable-proxy \--enable-java \--with-mysql \--with-net-snmp \--with-libcurl \--with-openipmi \--with-unixodbc \--with-ldap \--with-ssh2 \--with-zlib \--with-libevent \--with-openssl \--with-libpcre \--enable-ipv6
备注:安装mysql、snmp、curl
从 Zabbix 3.0.0 起,STMP 认证需要需要 cURL 7.20.0 或更高版本的 --with-libcurl 配置选项。
从 Zabbix 2.2.0 起,虚拟机监控需要 --with-libcurl 和 --with-libxml2 配置选项
执行安装
make install
报错:
mv -f $depbase.Tpo $depbase.Poparse.c: 在函数‘eval_get_last_function_token’中:parse.c:389:2: 错误:只允许在 C99 模式下使用‘for’循环初始化声明 for(int i = ctx->ops.values_num - 1; i >= 0; i --) ^parse.c:389:2: 附注:使用 -std=c99 或 -std=gnu99 来编译您的代码make[3]: *** [parse.o] 错误 1make[3]: 离开目录“/mnt/pack/zabbix-6.2.7/class="lazy" data-src/libs/zbxeval”make[2]: *** [all-recursive] 错误 1make[2]: 离开目录“/mnt/pack/zabbix-6.2.7/class="lazy" data-src/libs”make[1]: *** [all-recursive] 错误 1make[1]: 离开目录“/mnt/pack/zabbix-6.2.7/class="lazy" data-src”make: *** [all-recursive] 错误 1
#该错误的意思是:只允许在C99模式下使用‘for’循环初始化声明。
c语言有很多标准,以前的标准不允许for(int i=0;;)这种格式,而c99标准才允许的。
修改:
cp /mnt/pack/zabbix-6.0.13/class="lazy" data-src/libs/zbxeval/parse.c{,.bak}vim /mnt/pack/zabbix-6.0.13/class="lazy" data-src/libs/zbxeval/parse.c将: for (int i = ctx->ops.values_num - 1; i >= 0; i --)改为:391 int i;392 for (i = ctx->ops.values_num - 1; i >= 0; i --)
报错:
mv -f $depbase.Tpo $depbase.Pomisc.c: 在函数‘eval_get_next_function_token’中:misc.c:260:2: 错误:只允许在 C99 模式下使用‘for’循环初始化声明for(int i = token_index + 1; i < ctx->stack.values_num; i++)^misc.c:260:2: 附注:使用 -std=c99 或 -std=gnu99 来编译您的代码make[3]: *** [misc.o] 错误 1make[3]: 离开目录“/mnt/pack/zabbix-6.0.13/class="lazy" data-src/libs/zbxeval”make[2]: *** [install-recursive] 错误 1make[2]: 离开目录“/mnt/pack/zabbix-6.0.13/class="lazy" data-src/libs”make[1]: *** [install-recursive] 错误 1make[1]: 离开目录“/mnt/pack/zabbix-6.0.13/class="lazy" data-src”make: *** [install-recursive] 错误 1
解决;
cp /mnt/pack/zabbix-6.0.13/class="lazy" data-src/libs/zbxeval/misc.c{,.bak}vim /mnt/pack/zabbix-6.0.13/class="lazy" data-src/libs/zbxeval/misc.c259 int i;260 for( i = token_index + 1; i < ctx->stack.values_num; i++)
安装完成后查看目录内容
yum -y install treetree /mnt/zabbix//mnt/zabbix/├── bin│ └── zabbix_js├── lib│ └── modules├── sbin│ ├── zabbix_agent2│ ├── zabbix_agentd│ ├── zabbix_java│ │ ├── bin│ │ │ └── zabbix-java-gateway-6.0.13.jar│ │ ├── lib│ │ │ ├── android-json-4.3_r3.1.jar│ │ │ ├── logback-classic-1.2.9.jar│ │ │ ├── logback-console.xml│ │ │ ├── logback-core-1.2.9.jar│ │ │ ├── logback.xml│ │ │ └── slf4j-api-1.7.32.jar│ │ ├── settings.sh│ │ ├── shutdown.sh│ │ └── startup.sh│ ├── zabbix_proxy│ └── zabbix_server└── share├── man│ └── man8│ ├── zabbix_agent2.8│ ├── zabbix_proxy.8│ └── zabbix_server.8└── zabbix├── alertscripts└── externalscripts13 directories, 18 files
配置zabbix
cp /etc/zabbix/zabbix_server.conf{,.bak}vim /etc/zabbix/zabbix_server.conf 12 ListenPort=10051 38 LogFile=/mnt/zabbix/log/zabbix_server.log 87 DBHost=127.0.0.1 99 DBName=zabbix115 DBUser=zabbix123 DBPassword=123.com140 DBPort=3306
添加虚拟用户
group zabbixuseradd -g zabbix zabbix
配置zabbix数据库(zabbix要求创建数据库要指定字符集,否则中文会乱码)
mysql -uroot -p#为MySQL设置密码set password for root@localhost = password('010203');create database zabbix character set utf8 collate utf8_bin;grant all privileges on zabbix.* to zabbix@localhost identified by '123.com';flush privileges;exit
zabbix要求像数据库导入数据 表 数据....
ps:注意导入顺序
cd /mnt/pack/zabbix-6.0.13/database/mysql/lsdata.sql history_pk_prepare.sql Makefile.am schema.sqldouble.sql images.sql Makefile.inmysql -uroot -p010203 zabbix
启动zabbix
/mnt/zabbix/sbin/zabbix_serverss -anpt |grep zabbixLISTEN 0 128 *:10051 : users:(("zabbix_server",pid=79205,fd=9),("zabbix_server",pid=79202,fd=9),("zabbix_server"
部署前端代码进行访问
将zabbix源码包中的PHP文件复制到nginx目录下
cp -r /mnt/pack/zabbix-6.0.13/ui/* /mnt/nginx/html/zabbixls /mnt/nginx/html/zabbix/chown -R nginx.nginx /mnt/nginx/html/zabbix/
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341