安装和配置zabbix-5.0.20

一.zabbix安装

1.上传包zabbix-5.0.20.tar.gz 到/usr/local/ 下
2.解压包:tar -xzvf zabbix-5.0.20.tar.gz 并且:mv zabbix-5.0.20 zabbix
3.进入到目录:cd  /usr/local/zabbix/database/mysql  (mysql自己安装
4.将zabbix的数据文件导入到本机安装的mysql中(mysql自己安装
5.安装nginx、php做前端访问(nginx自己安装​​​​​​​)

先关的依赖包:
[root@localhost local]# yum -y install unixODBC-devel net-snmp-devel libevent-devel libxml2-devel libcurl-devel gcc gcc-c++ mysql-devel

[root@localhost local]# groupadd zabbix
[root@localhost local]# useradd -g zabbix zabbix -s /sbin/nologin  #设置zabbix为不可登录用户
进入mysql(mysql自己安装)中: 
[root@localhost local]# mysql -uroot -p
> create database zabbix character set utf8 collate utf8_bin;
> grant all privileges on zabbix.* to 'zabbix'@'%' identified by 'zabbix';
> flush privileges;
> show databases;
> use zabbix;
> source /usr/local/zabbix/database/mysql/schema.sql
> source /usr/local/zabbix/database/mysql/images.sql
> source /usr/local/zabbix/database/mysql/data.sql

5.编译

#这个是在zabbix的安装目录下执行
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2

make && make install
1.如果报错configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config
# yum -y install net-snmp-devel
2.如果报错configure: error: SSH2 library not found
# yum -y install libssh2-devel
3.如果报错configure: error: Unable to use libevent (libevent check failed)
# yum -y install libevent-devel
4.如果报错configure: error: Unable to find "go" executable in path
# yum -y install go
5.如果遇到报错configure: error: Curl library not found
# yum -y install curl-devel
6.如果报错configure: error: Not found libxml2 library
# yum -y install libxml2 libxml2-devel 
***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************

最后出现这个才算编译成功!
./configure完成之后在zabbix的安装目录里面会出现Makefile文件!
如果没有Makefile说明 ./configure 有问题!
make && make install

6.设置相关配置

vim /usr/local/zabbix/etc/zabbix_server.conf

DBHost=数据库IP
DBName=数据库库名
DBUser=用户名
DBPassword=密码

DBHost=192.168.23.0.100  #你安装数据库的机器ip
DBName=zabbix            #你安装数据库的zabbix库
DBUser=zabbix            #你安装数据库的zabbix用户
DBPassword=zabbix        #你安装数据库的zabbix用户密码


设置开机开机自启
[root@localhost init.d]# cp /usr/local/zabbix/misc/init.d/fedora/core/* /etc/init.d
[root@localhost zabbix]# chkconfig zabbix_server on
[root@localhost zabbix]# chkconfig zabbix_agentd on
[root@localhost init.d]# vim /etc/init.d/zabbix_server
BASEDIR=/usr/local/zabbix
[root@localhost init.d]# vim /etc/init.d/zabbix_agentd
BASEDIR=/usr/local/zabbix

#启动zabbix
/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start

如果上面的方法不行
可以cd /etc/init.d
[root@localhost init.d]# ./zabbix_server start
[root@localhost init.d]# ./zabbix_agentd start
启动报错
[root@localhost sbin]# ./zabbix_server
./zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
解决办法:
[root@localhost sbin]# find / -name libmysqlclient.so.20
/usr/local/mysql/lib/libmysqlclient.so.20
[root@localhost sbin]# ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64
[root@localhost sbin]# ./zabbix_server
[root@localhost sbin]# ./zabbix_agentd 
[root@localhost sbin]# ps -ef |grep zabbix
zabbix    73951      1  0 16:04 ?        00:00:00 ./zabbix_server
zabbix    73967      1  0 16:05 ?        00:00:00 ./zabbix_agentd
zabbix    73968  73967  0 16:05 ?        00:00:00 ./zabbix_agentd: collector [idle 1 sec]
zabbix    73969  73967  0 16:05 ?        00:00:00 ./zabbix_agentd: listener #1 [waiting for connection]
zabbix    73970  73967  0 16:05 ?        00:00:00 ./zabbix_agentd: listener #2 [waiting for connection]
zabbix    73971  73967  0 16:05 ?        00:00:00 ./zabbix_agentd: listener #3 [waiting for connection]
zabbix    73972  73967  0 16:05 ?        00:00:00 ./zabbix_agentd: active checks #1 [idle 1 sec]
root      73977  73327  0 16:05 pts/3    00:00:00 grep --color=auto zabbix


7.配置zabbix前端界面

配置zabbix-server前端界面
前端界面在zabbix源码包下面的ui文件件中,复制前端文件到nginx的html中

[root@localhost ui]# cd  /usr/local/zabbix/ui
[root@localhost ui]# cp -ar * /usr/local/nginx/html/

在nginx.conf添加两个location字段 (nginx自己安装

        location / {
            root   html;
            index  index.html index.htm index.php;
        }
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name; #这个是对应前面的html路径
            fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;
            include        fastcgi.conf;
        } 

8.安装PHP不建议安装PHP8,建议安装php-7.4.33.tar.gz,安装方法和下面是一样的)

将php-8.0.8.tar.gz上传到/usr/local/目录下
解压:tar -zxvf  php-8.0.8.tar.gz
# mv php-8.0.8 php
# cd php

编译  在PHP的安装目录

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib --with-iconv --with-curl --with-ldap --with-gettext --with-openssl --with-pear --with-jpeg --with-freetype --enable-fpm --enable-xml --enable-sockets --enable-soap --enable-pcntl --enable-cli --enable-ftp --enable-mbstring --enable-bcmath --enable-gd
make && make install
1 ./configure 配置如果遇到No package ‘libxml-2.0‘ found报错
# yum -y install libxml2
# yum -y install libxml2-devel

2 ./configure 配置如果遇到No package ‘sqlite3‘ found报错
# yum install sqlite-devel

3 ./configure 提示 No package oniguruma found 报错
# yum install -y epel-release
# yum install -y oniguruma oniguruma-devel

4. 如果make&&make install 报错/usr/bin/ld: ext/ldap/ldap.o: undefined reference to symbol 'ber_memfree'
编辑MakeFile文件:vim MakeFile
找到开头是'EXTRA_LIBS'的配置 ,在结尾加上 "-llber"

#EXTRA_LIBS = -lcrypt -lresolv -lcrypt -lrt -lldap -lutil -lrt -lm -ldl -lxml2 -lssl -lcrypto -lsqlite3 -lz -lcurl -lxml2 -lssl -lcrypto -lonig -lsqlite3 -lxml2 -lxml2 -lxml2 -lxml2 -lxml2 -lz -lssl -lcrypto -lcrypt -llber

5.如果报错 configure: error: Cannot find ldap.h
# yum -y install openldap openldap-devel 

6.如果报错 configure: error: Cannot find ldap libraries in /usr/lib
# cp -frp /usr/lib64/libldap* /usr/lib/

设置PHP相关配置

找到 php.ini-production,复制到/usr/local/php下,并改名为php.ini:

# cp php.ini-production /usr/local/php/php.ini

设置让PHP错误信息打印在页面上(可以不设置)

# vim /usr/local/php/php.ini 
display_errors = On
 


修改php-fpm配置文件:
# cd /usr/local/php/etc
# cp php-fpm.conf.default php-fpm.conf

# vim php-fpm.conf
pid = run/php-fpm.pid  #去掉前面的分号

# cd php-fpm.d
# cp www.conf.default www.conf
[root@localhost php]# vim php.ini

post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
mysqli.default_socket = /tmp/mysql.sock      #此sock文件按mysql实际运行生成的sock文件为准
pdo_mysql.default_socket = /tmp/mysql.sock   #此sock文件按mysql实际运行生成的sock文件为准
设置启动项

复制启动脚本:
[root@localhost php]# cp /usr/local/php/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php]# chmod 755 /etc/init.d/php-fpm
[root@localhost php]# chkconfig php-fpm  on
[root@localhost php]# /etc/init.d/php-fpm start    #php-fpm启动命令
[root@localhost php]# /etc/init.d/php-fpm stop     #php-fpm停止命令
[root@localhost php]# /etc/init.d/php-fpm restart  #php-fpm重启命令

9.验证浏览器输入:ip/setup.php

这一步要将下载的文件放到对应的路径中

 

 设置完成后登录用户名:Admin 密码:zabbix

先设置中文吧 

日乐购  一堆的报错

mysqli::real_connect(): Passing null to parameter #7 ($flags) of type int is deprecated [zabbix.php:21 → require_once() → ZBase->run() → ZBase->initDB() → DBconnect() → MysqlDbBackend->connect() → mysqli->real_connect() in include/classes/db/MysqlDbBackend.php:173]
Optional parameter $table_alias declared before required parameter $sql_parts is implicitly treated as a required parameter [zabbix.php:21 → require_once() → ZBase->run() → ZBase->authenticateUser() → CWebUser::checkAuthentication() → CApiWrapper->__call() → CFrontendApiWrapper->callMethod() → CApiWrapper->callMethod() → CFrontendApiWrapper->callClientMethod() → CLocalApiClient->callMethod() → CLocalApiClient->isValidMethod() → CRegistryFactory->getObject() → CApiService->__construct() → CApiService->pk() → CApiService->getTableSchema() → CAutoloader->loadClass() → require() in include/classes/core/CAutoloader.php:77]
Optional parameter $table_alias declared before required parameter $sql_parts is implicitly treated as a required parameter [zabbix.php:21 → require_once() → ZBase->run() → ZBase->authenticateUser() → CWebUser::checkAuthentication() → CApiWrapper->__call() → CFrontendApiWrapper->callMethod() → CApiWrapper->callMethod() → CFrontendApiWrapper->callClientMethod() → CLocalApiClient->callMethod() → CLocalApiClient->isValidMethod() → CRegistryFactory->getObject() → CApiService->__construct() → CApiService->pk() → CApiService->getTableSchema() → CAutoloader->loadClass() → require() in include/classes/core/CAutoloader.php:77]
Optional parameter $table_alias declared before required parameter $sql_parts is implicitly treated as a required parameter [zabbix.php:21 → require_once() → ZBase->run() → ZBase->authenticateUser() → CWebUser::checkAuthentication() → CApiWrapper->__call() → CFrontendApiWrapper->callMethod() → CApiWrapper->callMethod() → CFrontendApiWrapper->callClientMethod() → CLocalApiClient->callMethod() → CLocalApiClient->isValidMethod() → CRegistryFactory->getObject() → CApiService->__construct() → CApiService->pk() → CApiService->getTableSchema() → CAutoloader->loadClass() → require() in include/classes/core/CAutoloader.php:77]
Optional parameter $table_alias declared before required parameter $sql_parts is implicitly treated as a required parameter [zabbix.php:21 → require_once() → ZBase->run() → ZBase->authenticateUser() → CWebUser::checkAuthentication() → CApiWrapper->__call() → CFrontendApiWrapper->callMethod() → CApiWrapper->callMethod() → CFrontendApiWrapper->callClientMethod() → CLocalApiClient->callMethod() → CLocalApiClient->isValidMethod() → CRegistryFactory->getObject() → CApiService->__construct() → CApiService->pk() → CApiService->getTableSchema() → CAutoloader->loadClass() → require() in include/classes/core/CAutoloader.php:77]
setcookie(): Passing null to parameter #5 ($domain) of type string is deprecated [zabbix.php:21 → require_once() → ZBase->run() → ZBase->authenticateUser() → CWebUser::checkAuthentication() → CWebUser::setSessionCookie() → zbx_setcookie() → setcookie() in include/func.inc.php:107]

 1. 然后 网上找了一个大佬的博客  解决方法如下:

[root@localhost db]# vim /usr/local/nginx/html/include/classes/db/DB.php

                // add output options
                //$sql_parts = self::applyQueryOutputOptions($table_name, $options, $table_alias, $sql_parts);
                $sql_parts = self::applyQueryOutputOptions($table_name, $options, $sql_parts, $table_alias);
                // add filter options
                //$sql_parts = self::applyQueryFilterOptions($table_name, $options, $table_alias, $sql_parts);
                $sql_parts = self::applyQueryFilterOptions($table_name, $options, $sql_parts, $table_alias);
                // add sort options
                //$sql_parts = self::applyQuerySortOptions($table_name, $options, $table_alias, $sql_parts);
                $sql_parts = self::applyQuerySortOptions($table_name, $options, $sql_parts, $table_alias);
                return $sql_parts;

private static function applyQueryOutputOptions($table_name, array $options, array $sql_parts, $table_alias = null) {
                if ($options['countOutput']) {
                        $sql_parts['select'][] = 'COUNT('.self::fieldId('*', $table_alias).') AS rowscount';

 if (is_array($options['filter'])) {
                $sql_parts = self::dbFilter($table_name, $options, $sql_parts, $table_alias);

        private static function dbFilter($table_name, array $options, array $sql_parts, $table_alias = null) {
                $table_schema = self::getSchema($table_name);
                $filter = [];

 private static function applyQuerySortOptions($table_name, array $options, array $sql_parts, $table_alias = null) {
                 $table_schema = self::getSchema($table_name);

 2.然后这些搞完了之后,只剩下这个两个报错了

mysqli::real_connect(): Passing null to parameter #7 ($flags) of type int is deprecated [hosts.php:22 → require_once() → ZBase->run() → ZBase->initDB() → DBconnect() → MysqlDbBackend->connect() → mysqli->real_connect() in include/classes/db/MysqlDbBackend.php:173]
setcookie(): Passing null to parameter #5 ($domain) of type string is deprecated [hosts.php:22 → require_once() → ZBase->run() → ZBase->authenticateUser() → CWebUser::checkAuthentication() → CWebUser::setSessionCookie() → zbx_setcookie() → setcookie() in include/func.inc.php:107]

网上找了好久都没有找到有用的文档,然后我发现了几个关键的东西include/classes/db/MysqlDbBackend.php:173include/func.inc.php:107这两个是两个配置文件啊那就看看这两个配置文件对应行数173行和107

[root@localhost db]# vim /usr/local/nginx/html/include/classes/db/MysqlDbBackend.php

[root@localhost include]# vim /usr/local/nginx/html/include/func.inc.php

 然后重启一下php

[root@localhost include]# /etc/init.d/php-fpm restart

神奇的好了   后续有问题再补充

二. zabbix监控项配置

1.zabbix_agent下载  >>积分下载

 查看你自己的linux机器是什么版本的内核 

 在需要被监控的机器上安装zabbix_agent

[root@localhost local]# groupadd zabbix
[root@localhost local]# useradd -g zabbix zabbix -s /sbin/nologin   #新建zabbix用户并将其加入到zabbix组,并将他设置为不可登录的类型的用户
[root@localhost local]# mkdir zabbix_agent
[root@localhost local]# ls
bin  conf  etc  games  include  jdk1.8.0_333  lib  lib64  libexec  mysql  nginx  sbin  share  src  zabbix_agent  zabbix_agent-5.0.28-linux-3.0-amd64-static.tar.gz
[root@localhost local]# tar -zxvf zabbix_agent-5.0.28-linux-3.0-amd64-static.tar.gz -C zabbix_agent
./
./bin/
./bin/zabbix_sender
./bin/zabbix_get
./conf/
./conf/zabbix_agentd/
./conf/zabbix_agentd/userparameter_examples.conf
./conf/zabbix_agentd/userparameter_mysql.conf
./conf/zabbix_agentd.conf
./sbin/
./sbin/zabbix_agentd
[root@localhost local]# cd zabbix_agent/conf
[root@localhost conf]# ls
zabbix_agentd  zabbix_agentd.conf
[root@localhost conf]# vim zabbix_agentd.conf 
Server=10.123.123.122         #zabbxi_server主机
ServerActive=10.123.123.122   #zabbxi_server主机
Hostname=10.123.123.123       #zabbxi_agent主机

  

启动zabbix_agent

[root@localhost sbin]# /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.conf
[root@localhost sbin]# ps -ef |grep zabbix
zabbix    24366      1  0 16:11 ?        00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd -c /usr/local/zabbix_agent/conf/zabbix_agentd.conf
zabbix    24367  24366  0 16:11 ?        00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix    24368  24366  0 16:11 ?        00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix    24369  24366  0 16:11 ?        00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix    24370  24366  0 16:11 ?        00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix    24371  24366  0 16:11 ?        00:00:00 /usr/local/zabbix_agent/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root      24373  24184  0 16:11 pts/4    00:00:00 grep --color=auto zabbix

然后在zabbix_server机器配置

 

问题1:解决图形中中文字符乱码

 先在自己的电脑上找到一款字体,最好也是找ttf格式的字体格式 

[root@localhost zabbix]# find / -name fonts
/boot/grub2/fonts
/etc/fonts
/var/lib/docker/overlay2/e5f26680ebc31607d42f2963e7e76dfd7fbbf7a328c132870121ef439d3706b0/diff/etc/fonts
/var/lib/docker/overlay2/e5f26680ebc31607d42f2963e7e76dfd7fbbf7a328c132870121ef439d3706b0/diff/usr/local/share/fonts
/var/lib/docker/overlay2/e5f26680ebc31607d42f2963e7e76dfd7fbbf7a328c132870121ef439d3706b0/diff/usr/share/fonts
/usr/share/fonts
/usr/include/X11/fonts
/usr/local/jdk1.8.0_333/jre/lib/fonts
/usr/local/nginx/html/assets/fonts
/usr/local/nginx/html/zabbix/assets/fonts
/usr/local/zabbix/ui/assets/fonts
[root@localhost fonts]# cd /usr/local/nginx/html/assets/fonts
[root@localhost fonts]# ls
DejaVuSans.ttf
因为我们是通过nginx来作为前端转发的所以只要修改nginx中的html里面的字体配置文件就行了
[root@localhost fonts]# mv DejaVuSans.ttf DejaVuSans.ttf.2022.9.21
然后将我们刚刚选的字体上传上来
[root@localhost fonts]# ls
DejaVuSans.ttf.2022.9.21  simfang.ttf
[root@localhost fonts]# mv simfang.ttf DejaVuSans.ttf
[root@localhost fonts]# ll
总用量 11072
-rw-r--r-- 1 root root 10578152 10月 15 2019 DejaVuSans.ttf
-rw-r--r-- 1 root root   756072 5月  30 14:22 DejaVuSans.ttf.2022.9.21

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小邋遢2.0

你的鼓励将是我创作的最大动力~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值