首页 技术 正文
技术 2022年11月21日
0 收藏 872 点赞 4,276 浏览 6280 个字

一,zabbix的用途:

zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案

zabbix能监视各种网络参数,保证服务器系统的安全运营;

并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题

zabbix由2部分构成:  zabbix server/运行在被监控端的zabbix agent

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

对应的源码可以访问这里获取: https://github.com/liuhongdi/

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,准备好lnmp环境:

1,需要的环境文档:

https://www.zabbix.com/documentation/current/manual/installation/requirements

2,需要的软件环境

php:7.2.0及以上

mysql: 5.5.62及以上

需要的php扩展包括:

gd: 2.0.28及以上
bcmath
ctype
libXML: 2.6.15及以上
session
sockets
mbstring
gettext

三,下载zabbix的源码安装包

1,官方下载站:

http://repo.zabbix.com/zabbix/

清华的国内镜像站:

https://mirrors.tuna.tsinghua.edu.cn/zabbix/

2,创建下载目录:

[root@blog zabbix]# mkdir /usr/local/source/zabbix

3,下载:

[root@blog zabbix]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.0.tar.gz

四,安装zabbix5.0

1,官方的安装文档地址:

https://www.zabbix.com/documentation/current/manual/installation/install

2,解压缩:

[root@blog zabbix]# tar -zxvf zabbix-5.0.0.tar.gz
[root@blog zabbix]# cd zabbix-5.0.0/

3,创建zabbix用户

[root@blog zabbix-5.0.0]# groupadd --system zabbix
[root@blog zabbix-5.0.0]# useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix

4,创建zabbix账号的home目录

[root@blog zabbix-5.0.0]# mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
[root@blog zabbix-5.0.0]# chown zabbix:zabbix /usr/lib/zabbix

5,创建zabbix数据库

创建数据库的文档地址

https://www.zabbix.com/documentation/current/manual/appendix/install/db_scripts

sql语句:

创建数据库

create database zabbix character set utf8 collate utf8_bin

创建zabbix数据库账号

create user 'zabbix'@'127.0.0.1' identified by 'zabbixpass';

给zabbix数据库账号授权

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

刷新数据库权限数据

flush PRIVILEGES;

6,导入数据:

说明:切换到源码目录/database/mysql/目录下后执行:

[root@blog mysql]$ /usr/local/soft/mysql/bin/mysql -uzabbix -pzabbixpass zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.

[root@blog mysql]$ /usr/local/soft/mysql/bin/mysql -uzabbix -pzabbixpass zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.

[root@blog mysql]$ /usr/local/soft/mysql/bin/mysql -uzabbix -pzabbixpass zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.

7,configure与安装

在源码目录下执行configure

[root@blog zabbix-5.0.0]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2  

安装

[root@blog zabbix-5.0.0]# make install

说明:configure时报错的解决:

报错1:

configure: error: MySQL library not found

解决:

[root@blog zabbix-5.0.0]# dnf install mysql-devel

报错2:

configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config

解决:

[root@blog zabbix-5.0.0]# dnf install -y net-snmp-devel

报错3:

configure: error: Unable to use libevent (libevent check failed)

解决:

[root@blog zabbix-5.0.0]# dnf install libevent-devel  -y

报错4:

configure: error: Unable to use libpcre (libpcre check failed)

解决:

[root@blog zabbix-5.0.0]# dnf -y install pcre*

8,查看安装效果:

查看zabbix_server的版本

[root@blog zabbix-5.0.0]# /usr/local/soft/zabbx-5.0.0/sbin/zabbix_server --version
zabbix_server (Zabbix) 5.0.0
Revision 9665d62db0 11 May 2020, compilation time: May 17 2020 09:37:03Copyright (C) 2020 Zabbix SIA
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.

查看zabbix_agentd的版本

[root@blog zabbix-5.0.0]# /usr/local/soft/zabbx-5.0.0/sbin/zabbix_agentd --version
zabbix_agentd (daemon) (Zabbix) 5.0.0
Revision 9665d62db0 11 May 2020, compilation time: May 17 2020 09:37:03Copyright (C) 2020 Zabbix SIA
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.

五,配置zabbix_server

编辑配置文件

[root@blog etc]# vi zabbix_server.conf

主要配置项:

LogFile=/data/zabbix_server/logs/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPort=3306

创建日志目录

[root@blog etc]# mkdir /data/zabbix_server/logs

六,配置zabbix_agentd

编辑配置文件

[root@blog etc]# vi zabbix_agentd.conf

主要配置项:

LogFile=/data/zabbix_agentd/logs/zabbix_agentd.log
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=jdweb

创建日志目录

[root@blog etc]# mkdir /data/zabbix_agentd/logs

七,启动zabbix_server

[root@blog etc]# /usr/local/soft/zabbx-5.0.0/sbin/zabbix_server

八,启动zabbix_agentd

[root@blog etc]# /usr/local/soft/zabbx-5.0.0/sbin/zabbix_agentd

九,为nginx配置zabbix用来做web管理的虚拟主机

创建网站root目录

[root@blog conf.d]# mkdir /data/dweb/zabbix

配置虚拟主机:

说明:这个文件要放到nginx的配置文件所在目录下,

我的机器上是:/usr/local/openresty/nginx/conf/conf.d,

大家根据自己机器上nginx的安装情况创建这个虚拟主机即可

[root@blog conf.d]# vi zabbix.conf 

内容:

server {
listen 80;
server_name zabbix.lhdtest.net;
root /data/dweb/zabbix/html;
index index.php index.html index.shtml index.htm;
access_log /data/logs/nginxlogs/zabbix.access_log;
error_log /data/logs/nginxlogs/zabbix.error_log; location / {
try_files $uri $uri/ /index.php?$args;
} location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_buffer_size 32k;
fastcgi_buffers 10240 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

配置完成后重启nginx

九,配置web界面

1,复制ui目录下的文件到虚拟主机目录下

[root@blog ui]# pwd
/usr/local/source/zabbix/zabbix-5.0.0/ui
[root@blog ui]# cp -axv ./ /data/dweb/zabbix/html/

2,访问url

http://zabbix.lhdtest.net/

会自动跳转到:

http://zabbix.lhdtest.net/setup.php

看截图,点next step

如果不满足zabbix配置的需求,更新php后重启php-fpm

无问题后点next step

数据库配置:输入数据库密码

此处输入保持默认即可,点next step按钮继续

这个页面显示我们配置的一个摘要,继续点 next step按钮

看到这个页面,表示安装无问题,点finish结束

3,如果安装过程中提示不能保存配置文件,

修改conf目录的权限:

[root@blog html]# chmod 766 /data/dweb/zabbix/html/conf/*

4,跳转到登录界面后:

用默认账号登录:

The default user name is Admin, password zabbix.

默认账号:

用户名:Admin

密码:zabbix

十,登录后配置中文/解决中文乱码/修改默认密码

1,配置中文,解决中文乱码,参见:

https://www.cnblogs.com/architectforest/p/12911721.html

2,web界面修改默认密码:

用默认密码登录后

左侧菜单->User settings->点 修改密码 按钮

修改为自定义密码后

点 更新 按钮即可

十一,使用systemd管理zabbix-server的服务

编辑zabbix-server的service文件

[root@blog system]# vi /usr/lib/systemd/system/zabbix-server.service 

内容:

[Unit]
Description=Zabbix Server
After=network.target
After=mysqld.service[Service]
Environment="CONFFILE=/usr/local/soft/zabbx-5.0.0/etc/zabbix_server.conf"
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/soft/zabbx-5.0.0/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0[Install]
WantedBy=multi-user.target

重新加载service文件

[root@blog system]# systemctl daemon-reload

启动命令:

[root@blog system]# systemctl start zabbix-server.service

停止命令:

[root@blog system]# systemctl stop zabbix-server.service

十二,查看centos版本:

[root@blog nginxlogs]$ cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,910
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,435
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,250
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,061
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,693
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,731