zabbix使用手动、自动、使用api添加agent
添加主机
开启一个server2
装上zabbix-agent
yum install zabbix-agent-4.0.5-1.el7.x86_64.rpm -y
现在server1上添加(上一篇文章的快速搭建zabbix的方法)
手动添加
创建主机
IPMI 智能平台管理接口(采集硬件信息)
再主机模板
server2上
vim /etc/zabbix/zabbix_agentd.conf
systemctl start zabbix-agent
cat /var/log/zabbix/zabbix_agentd.log
自动发现功能
这时候就会自动发现
再查看主机,就会拥有server2
自动注册
开启server3 安装agent 修改配置文件的连接地址为server1的
server3重起agent服务即可
一开始是灰的,但是过一会刷新就好
API方式添加主机
server1:
vim zabbix-json
curl -s -XPOST -H "Content-Type: application/json-rpc" -d '
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "Admin",
"password": "zabbix"
},
"id": 1,
"auth": null
}' http://172.25.11.1/zabbix/api_jsonrpc.php | python -m json.tool
chmod +x zabbix-api
./zabbix-api
-s 静默输出
再次修改
获取主机
curl -s -XPOST -H "Content-Type: application/json-rpc" -d '
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": [
"hostid",
"host"
],
"selectInterfaces": [
"interfaceid",
"ip"
]
},
"id": 1,
"auth": "bc279aa141cbd536ac79fa79724579de"
}' http://172.25.11.1/zabbix/api_jsonrpc.php | python -m json.tool
运行脚本获取server3的信息
删除主机
curl -s -XPOST -H "Content-Type: application/json-rpc" -d '
{
"jsonrpc": "2.0",
"method": "host.delete",
"params": [
"10271" #这个为你要删除的主机的hostid
],
"id": 1,
"auth": "bc279aa141cbd536ac79fa79724579de"
}' http://172.25.11.1/zabbix/api_jsonrpc.php | python -m json.tool
创建主机
curl -s -XPOST -H "Content-Type: application/json-rpc" -d '
{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "server3",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "172.25.11.3",
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "2"
}
],
"templates": [
{
"templateid": "10001"
}
]
},
"id": 1,
"auth": "bc279aa141cbd536ac79fa79724579de"
}' http://172.25.11.1/zabbix/api_jsonrpc.php | python -m json.tool
这样就会添加主机
监控服务
server2 开启httpd
server3 开启nginx
yum install -y gcc make pcre-devel zlib-devel
./configure --prefix=/usr/local/nginx --with-http_stub_status_module
make &&make install
vim nginx.conf
加入
location /status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
[[email protected] nginx]# /usr/local/nginx/sbin/nginx
[[email protected] nginx]# curl http://127.0.0.1/status
Active connections: 1
server accepts handled requests
1 1 1
Reading: 0 Writing: 1 Waiting: 0
curl -s http://127.0.0.1/status |grep Active|awk '{print $3}'
流程
user->web ui -> zabbix server -> zabbix agent -> shell -> zabbix server -> mysql -> web ui
cd /etc/zabbix/zabbix_agentd.d/
cp userparameter_mysql.conf userparameter_nginx.conf
vim userparameter_nginx.conf
UserParameter=nginx.active,curl -s http://127.0.0.1/status |grep Active|awk '{print $3}'
UserParameter=nginx.accept,curl -s http://127.0.0.1/status |awk NR==3| awk '{print $1}'
systemctl restart zabbix-agent
server1
yum install zabbix-get-4.0.5-1.el7.x86_64.rpm -y
zabbix_get -s 172.25.11.3 -p 10050 -k "nginx.active"
zabbix_get -s 172.25.11.3 -p 10050 -k "nginx.accept"
有上角的监控项
图上角创建图形
ab -c 100 -n 1000 http://172.25.11.3/index.html
[[email protected] ~]# ab -c 100 -n 1000 http://172.25.11.3/index.html
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Percentage of the requests served within a certain time (ms)
50% 37
66% 39
75% 40
80% 40
90% 41
95% 43
98% 219
99% 240
100% 247 (longest request)
更换字体
scp simkai.ttf server1:/usr/share/zabbix/fonts
vim /usr/share/zabbix/include/defines.inc.php
%s/graphfont/simkai/g
监控数据库
自身带的监控项太少了
server1
mkdir /var/lib/zabbix
vim /var/lib/zabbix/.my.cnf
[mysql]
host = localhost
user = root
password = westos
socket = /var/lib/mysql/mysql.sock
[mysqladmin]
host = localhost
user = root
password = westos
socket = /var/lib/mysql/mysql.sock
systemctl restart zabbix-agent
但是自带的监控项太少了
下面添加一个插件 plugins:percona-zabbix-templates
get percona-zabbix-templates-1.1.8-1.noarch.rpm
yum install percona-zabbix-templates-1.1.8-1.noarch.rpm -y
cd /var/lib/zabbix/percona/templates
cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
cd ../scripts/
vim ss_get_mysql_stats.php.cnf
<?php
$mysql_user = 'root';
$mysql_pass = 'westos';
systemctl restart zabbix-agent
./get_mysql_stats_wrapper.sh gg
scp zbx_percona_mysql_template.xml server1:/root/
浏览器中导入模板
点上聚合图形
就会有191个插件了
www.onealert.com 注册报警帐号
虚拟机怎么上网
vim /etc/sysconfig/network
NERWORKING=yes
NOZEROCONF=yes
GATEWAY=172.25.11.250
vim /etc/resolve.conf nameserver 114.114.114.114
真机
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
sysctl -p
firewall-cmd --add-masquerade
server1
vim /etc/zabbix/zabbix_server.conf
/AlertScriptsPath
cd /usr/lib/zabbix/alertscripts
wget http://www.onealert.com/agent/release/oneitsm_zabbix_release-1.2.0.tar.gz
tar -zxf oneitsm_zabbix_release-1.2.0.tar.gz
cd oneitsm/bin
bash install.sh 862acef6-15b9-e2bb-87b8-f691a4316833
这时就会有 自动添加的