1、搭建zabbix服务,实现监控linux和windows的内存,cpu,磁盘,网络等基础指标
搭建zabbix服务主机:
yum install php-ldap httpd php-fpm php php-mysql zabbix40-server zabbix40-web zabbix40-agent mariadb-server
vim /etc/my.cnf
innodb_file_per_table=ON
skip_name_resolve=ON
vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai
systemctl start httpd mariadb zabbix-server zabbix-agent
mysql
create database zabbix charset 'utf8';
grant all on zabbix.* to 'zabbix'@'192.168.%.%' identified by '12345678';
grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by '12345678';
flush privileges;
gzip -d create.sql.gz ## zabbix40-server 没有此文件
vim create.sql
USE zabbix; ## 在第一行加上
cat ./create.sql | mysql -uzabbix -p12345678 -h127.0.0.1
vim /etc/zabbix/zabbix_server.conf
DBHost=192.168.0.138
DBUser=zabbix
DBPassword=12345678
DBPort=3306
ListenIP=192.168.0.0/24
ListenIP=127.0.0.1
systemctl restart zabbix-server zabbix-agent httpd php-fpm
http://127.0.0.1/zabbix/ ##安装完毕后 默认账号密码:admin;zabbix
vim /etc/zabbix/zabbix_agentd.conf
EnableRemoteCommands=1
UnsafeUserParameters=1
在另外一台Linux主机搭建zabbix-agent
yum install zabbix-agent
vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.0.138 ##指向服务器IP
ServerActive=192.168.0.138 ##指向服务器IP
UnsafeUserParameters=1
systemctl start zabbix-agent
在另外一台Windows主机搭建zabbix-agent
C:\Users\lianxiang\Downloads\zabbix_agents-4.0.12-win-i386\conf ##编辑配置文件,指向服务器
Server=192.168.0.138
ServerActive=192.168.0.138
cd C:\Users\lianxiang\Downloads\zabbix_agents-4.0.12-win-i386\bin
.\zabbix_agentd.exe -c C:\Users\lianxiang\Downloads\zabbix_agents-4.0.12-win-i386\conf\zabbix_agentd.conf -i
.\zabbix_agentd.exe -c C:\Users\lianxiang\Downloads\zabbix_agents-4.0.12-win-i386\conf\zabbix_agentd.conf -s
回到zabbix服务器,设置参数并查看效果:
创建Linux主机:
选择对应模板:
创建Windows主机:
选择对应模板:
添加完成后,可用性 ZBX 为绿色即添加成功
采集数据后情况:
2、搭建zabbix服务,监控nginx status
搭建一台nginx主机服务:
yum install nginx
systemctl start nginx
vim /etc/nginx/nginx.conf
server_name 192.168.0.140;
location ~ /ngxstatus$ {
stub_status on; ##状态检测打开
}
nginx -s reload
vim /usr/bin/ngxstatus.sh
#!/bin/bash
#
host='192.168.0.140'
port='80'
statusurl='/ngxstatus'
active() {
curl -s http://${host}:${port}${statusurl}|awk '/^Active/{print $3}'
}
accepts() {
curl -s http://${host}:${port}${statusurl}|awk 'NR==3{print $1}'
}
handled() {
curl -s http://${host}:${port}${statusurl}|awk 'NR==3{print $2}'
}
requests() {
curl -s http://${host}:${port}${statusurl}|awk 'NR==3{print $3}'
}
Reading() {
curl -s http://${host}:${port}${statusurl}|awk 'NR==4{print $2}'
}
Writing() {
curl -s http://${host}:${port}${statusurl}|awk 'NR==4{print $4}'
}
Waiting() {
curl -s http://${host}:${port}${statusurl}|awk 'NR==4{print $6}'
}
$1
chmod +x /usr/bin/ngxstatus.sh
yum install zabbix-agent.x86_64
vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.0.138 ##指向服务器IP
ServerActive=192.168.0.138 ##指向服务器IP
UnsafeUserParameters=1
UserParameter=nginx.status[*],/usr/bin/ngxstatus.sh $1 ##定义nginx状态脚本
visudo
zabbix ALL=(ALL) NOPASSWD: ALL
systemctl start zabbix-server.service
另外一台为zabbix服务器,基础环境借用上题:
[root@localhost ~]# zabbix_get -s 192.168.0.140 -k 'nginx.status[accepts]' ##先测试脚本能否正常执行
10919
进入web界面进行配置:
先创建一个模板,在模板上创建监控项,再创建一个主机调用此模板,最后生成图形: