当前位置:网站首页>Zabbix安装及配置应用
Zabbix安装及配置应用
2022-06-11 12:05:00 【乌托邦为什么被占用了】
一、Zabbix简介
zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案,可用于监视各种网络参数,保证服务器系统的安全运营,提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
zabbix由2部分构成,zabbix server与可选组件zabbix agent。zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。本手册说明的是在CentOS6下zabbix server的详细部署过程。
二、服务端安装与配置过程
2.1 安装前设定:
- 2.1.1 关闭selinux:
vi /etc/selinux/config
SELINUX=disabled
- 2.1.2添加zabbix的官方yum源:
2.4版:rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
3.0版:rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
2.2 搭建LNMP环境:
- 安装mysql(5.6以上)、php-fpm(5.4以上)、nginx(也可以使用httpd,nginx需添加配置,httpd直接启动即可),均使用yum方式安装
(php最小安装参数:yum -y install php55w php55w-fpm php55w-gd php55w-mbstring php55w-mysql php55w-xml php55w-bcmath) - !!注!!:zabbix3.x要想使用SMTP,那么需要7.20.0及以上版本的curl并且zabbix服务端在编译安装时需要添加–with-libcurl模块,CentOS自带版本太低,需升级:
rpm -Uvh http://www.city-fan.org/ftp/contrib/yum-repo/rhel6/x86_64/city-fan.org-release-1-13.rhel6.noarch.rpm
yum install libcurl
若报如下图所示错误,升级libnghttp2:
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/libnghttp2-1.6.0-1.el6.1.x86_64.rpm
yum install libnghttp2 1):zabbix官方文档要求:如果php版本>=5.6.0要设置php.ini里always_populate_raw_post_data = -1
2):nginx配置文件/etc/nginx/conf.d/default.conf添加server如下:server { listen 80; server_name zabbix.example.com; access_log /var/log/nginx/zabbix.access.log main; index index.php index.html index.html; root /home/www/zabbix; location / { try_files $uri $uri/ /index.php?$args; } location ~ .*\.(php)?$ { expires -1s; try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; } }- 安装依赖组件包
yum -y install iksemel libssh2 zabbix-server-mysql zabbix-web-mysql mysql-server zabbix-agent install net-snmp-devel net-snmp-libs net-snmp-perl net-snmp-utils net-snmp
- PHP参数配置(httpd):
使用vi命令打开配置文件:vi /etc/httpd/conf.d/zabbix.conf
配置相关参数如下:
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value always_populate_raw_post_data -1
php_value date.timezone Asia/Shanghai
保存退出。
- PHP参数配置(nginx):
打开php配置文件:vim /etc/php.ini
修改参数配置如下(并取消注释):
date.timezone = Asia/Shanghai
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
- 配置mysql数据库,修改密码、导入数据表,初始化数据库:
- 启动数据库:service mysqld start
- 登陆数据库:mysql -uroot -p
- 创建zabbix的数据库:create database zabbix character set utf8 collate utf8_bin;
(数据库名zabbixdb,数据库字符集采用utf8用以支持中文)
- 授权zabbix系统用户访问Mysql数据库所有表:grant all privileges on zabbix.* to [email protected] identified by 'zabbix';
(以上三点在mysql命令环境下执行)
- 导入zabbix数据库表结构(2.4下三条命令,3.0中是一个gz压缩包,解压得creat.sql一个文件(gzip -d create.sql.gz),如下格式导入):
2.4:
mysql -uroot -p123456 zabbix < /usr/share/doc/zabbix-server-mysql-2.4.6/create/schema.sql
mysql -uroot -p123456 zabbix < /usr/share/doc/zabbix-server-mysql-2.4.6/create/images.sql
mysql -uroot -p123456 zabbix < /usr/share/doc/zabbix-server-mysql-2.4.6/create/data.sql
3.0:
cd /usr/share/doc/zabbix-server-mysql-3.0.4 && gzip -d create.sql.gz
mysql -uroot -p123456 zabbix < /usr/share/doc/zabbix-server-mysql-3.0.4/create.sql
2.3 zabbix配置:
- 创建zabbix用户:
useradd -g zabbix zabbix
(若已有该账户,视情况决定是否需要改密码)
passwd zabbix
- 编辑zabbix的配置文件:
使用vi命令打开配置文件:vi /etc/zabbix/zabbix_server.conf
配置相关参数如下:
DBHost=localhost;
DBName=zabbix;
DBUser=zabbix;
DBPassword=zabbix;
DBPort=3306
保存退出。
=============选作:配置优化=========
vim /usr/local/etc/zabbix_server.conf
StartPollers=90
CacheSize=1024M
StartDiscoverers=10
StartPollersUnreachable=80
HousekeepingFrequency=1
MaxHousekeeperDelete=100
StartPingers=10
StartIPMIPollers=10
StartTrappers=20
StartDBSyncers=8
LogSlowQueries=1000
================================
- 拷贝web文件:
mkdir -p /home/www/zabbix
cp -r -a /usr/share/zabbix/* /home/www/zabbix/
2.4 开启防火墙端口(tcp\80,10050,10051 udp\10050,10051):
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT
iptables -A INPUT -m state --state NEW -m udp -p udp --dport 10050 -j ACCEPT
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 10051 -j ACCEPT
iptables -A INPUT -m state --state NEW -m udp -p udp --dport 10051 -j ACCEPT
service iptables save
2.5 启动与登陆:
- 启动zabbix:/etc/init.d/zabbix-server start
- 浏览器打开以下网址,登陆zabbix:http://localhost/zabbix (http://zabbix.showjoy.com)
- 成功打开zabbix页面后,自定义配置即可,初始web账户:Admin/zabbix;
- setup配置校验提示:PHP bcmath extension missing....,
安装bcmath:yum install php54w-bcmath --skip-broken,根据主机php版本替换安装包名称,若有问题可以考虑如下方式全装:
(yum install *bcmath* --skip-broken)
2.6 日志:
服务端默认日志位置:/var/log/zabbix/zabbix_server.log
三、客户端安装与配置
3.1 zabbix客户端安装
===yum安装===
- 添加zabbix的官方yum源:
2.4:rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
3.0:rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
- 执行安装命令:
yum -y install zabbix-agent
3.2 zabbix客户端配置
- 编辑客户端配置文件:vim /etc/zabbix/zabbix_agentd.conf
- 修改配置如下(假设服务端/Proxy的IP为10.20.0.100,根据实际情况酌情修改,Hostname自定义):
Server=10.20.0.100
ServerActive=10.20.0.100
Hostname=Cilent001 - 关闭SElinux:setenforce 0
- 开启防火墙端口(默认10050,其他用到什么开什么):
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT
iptables -A INPUT -m state --state NEW -m udp -p udp --dport 10050 -j ACCEPT - 客户端启动:service zabbix-agent start
- 说明:本文档中并未通过zabbix_Proxy实现中转,即模式为zabbix_server---zabbix_agent,若后端服务器数目过大,可考虑通过zabbix_proxy减轻server压力,安装过程类似于zabbix_agentd,然后将zabbix_agentd端配置文件中的Server指向zabbix_proxy,将zabbix_proxy配置文件中的Server指向zabbix_server即可;
3.3 邮件告警配置
- 安装mailx:yum -y install mailx
- 编辑客户端配置如下:/etc/mail.rc

- 查看/etc/zabbix/zabbix_server.conf获取脚本文件目录(AlertScriptsPath配置项),创建邮件脚本:
#!/bin/bash
#export LANG=zh_CN.UTF-8
messages=`echo $3 | tr '\r\n' '\n'`
subject=`echo $2 | tr '\r\n' '\n'`
echo "${messages}" | mail -s "${subject}" $1 >>/tmp/sendmail.log 2>&1
- 设置脚本、日志(sendmail.log)权限:
chmod +x sendmail.sh
chown zabbix:zabbix sendmail.sh
chown zabbix:zabbix /tmp/sendmail.log - 测试邮件发送:
./sendmail.sh [email protected] "测试邮件标题" "测试邮件内容"
- web配置:1.报警媒介类型、2.用户--报警媒介(注:用户组权限需赋予读写)、3.动作,默认动作内容配置可修改,可参考:
http://xianglinhu.blog.51cto.com/5787032/1636436;
3.4 短信告警
- 查看/etc/zabbix/zabbix_server.conf获取脚本文件目录(AlertScriptsPath配置项),创建短信发送脚本(实现短信发送自行实现,示例脚本发送短信格式为:./sendSMS.sh 手机号 "内容"):
- 设置脚本、日志(sendmail.log)权限:
touch /tmp/SMS.log
chown zabbix:zabbix /tmp/SMS.log
chown zabbix:zabbix sendSMS.sh
chmod +x sendSMS.sh - 测试短信发送:
./sendSMS.sh 15700090909 "" "哈哈哈"
3.5 微信告警
四、使用服务端监控客户端
- 打开zabbix配置页面执行配置:configuration(配置)–>Hosts(主机)–host(创建主机),如图4.2配置,然后切换到Template标签,设置链接监控模板 Template OS Linux
- 解决中文乱码:从windows系统中复制楷体(simkai.ttf)到zabbix字体目录中,
windows字体目录:C:\Windows\Fonts\simkai.ttf
zabbix字体目录:/usr/share/zabbix/fonts(/home/www/zabbix/fonts) - 修改zabbix配置文件:vim /usr/share/zabbix/include/defines.inc.php(/home/www/zabbix/include/defines.inc.php),修改如下内容:
define('ZBX_FONT_NAME', 'simkai');
define('ZBX_GRAPH_FONT_NAME', 'simkai');
五、自定义监控项:
- 主机添加后通过绑定现有模版可以实现一些默认监控项的监控,设置示警媒介后即可实现告警,若要实现特定的监控功能,需自定义监控项,在客户端配置UserParameter,管理界面配置调用即可,简要说明如下.
- 在客户端配置文件zabbix_angentd.conf里面配置UserParameter,语法如下:
不带参数:UserParameter=key,command
带指定个数的参数:UserParameter=key[*],command
包含一个key和一个命令(command,可以是一条命令,也可以是一个脚本调用),key必须整个系统唯一,配置好之后,重启客户端,然后再web配置item、设置触发器即可;
| 参数 | 描述 |
| Key | 必须全局唯一,[*]表示里面可以传递多个参数 |
| Command | 需要执行的脚本,key的[]里面的参数一一对应$1到$9,一共9个参数,$0表示脚本自身。 |
- 示例一:
定义:UserParameter=ping[*],echo $1
监控:ping[0] -----将一直返回0
ping[aaa] -----将一直返回 'aaa'
- 示例二:
定义:UserParameter=mysql.ping[*],mysqladmin -u$1 -p$2 ping | grep -c alive
监控:mysql.ping[zabbix,our_password] -----传递用户名和密码监控MySQL
- 示例三:
定义:UserParameter=wc[*],grep -c "$2" $1
监控:wc[/etc/passwd,root] -----返回passwd文件中包含root字符的行数
边栏推荐
- [JUC supplementary] immutable object, shared meta mode, final principle
- 程序员常用的命令符
- [JUC supplementary] atomic class, unsafe
- Apple mobileone: the mobile terminal only needs 1ms of high-performance backbone
- PS does not display text cursor, text box, and does not highlight after selection
- Streaking? Baa!
- [file upload vulnerability 06] server file content detection and bypass experiment + image horse production method (based on upload-labs-14 shooting range)
- Merge two ordered arrays (C language)
- [digital signal processing] correlation function (property of correlation function | maximum value of correlation function | maximum value of autocorrelation function | maximum value of cross correlat
- Notes on brushing questions (13) -- binary tree: traversal of the first, middle and last order (review)
猜你喜欢

Yapi installation

mysql 导入宝塔中数据库data为0000-00-00,enum为null出错

【LeetCode】1049. Weight of the last stone II (wrong question 2)

JS to realize the rotation chart (riding light). Pictures can be switched left and right. Moving the mouse will stop the rotation

Elk - x-pack set user password

苹果MobileOne: 移动端仅需1ms的高性能骨干
![[Chapter II Relationship between genes and chromosomes] summary of biological knowledge - Biology in grade one of senior high school](/img/f0/9f78682798a7874ba176797a6b22ca.png)
[Chapter II Relationship between genes and chromosomes] summary of biological knowledge - Biology in grade one of senior high school

Qt中radioButton使用

Notes on topic brushing (XIV) -- binary tree: sequence traversal and DFS, BFS

你管这破玩意儿叫 MQ?
随机推荐
Iframe value transfer
C# 将OFD转为PDF
Intl.numberformat set number format
Hamiltonian graph
The role of Gerber file in PCB manufacturing
Adjust the array order so that odd numbers precede even numbers (C language)
Maximum water container
2020-07 study notes sorting
Qt中radioButton使用
Apple mobileone: the mobile terminal only needs 1ms of high-performance backbone
CVPR 2022 | 文本引导的实体级别图像操作ManiTrans
Addition of large numbers (C language)
Gestion de projets logiciels 7.1. Concept de base du calendrier du projet
Yapi installation
typescript 编译选项和配置文件
Where is it safer to open an account for soda ash futures? How much does it cost to buy soda ash futures?
P2580 "so he started the wrong roll call"
大数相加(C语言)
Let you understand bubble sorting (C language)
golang利用异或^交换两个变量以及加解密