1、环境:
解析:每个主机都有对方的解析
server1:172.25.17.101 | zabbix监控部署主机 |
server2:172.25.17.102 | agent客户端 |
server4:172.25.17.104 | agent客户端 |
2、server1部署
1、安装软件
yum install \
zabbix-server-mysql-4.0.5-1.el7.x86_64.rpm \
mariadb-server \
zabbix-web-mysql-4.0.5-1.el7.noarch.rpm \
zabbix-web-4.0.5-1.el7.noarch.rpm \
php-mbstring-5.4.16-42.el7.x86_64.rpm \
php-bcmath-5.4.16-42.el7.x86_64.rpm -y
前三个必须安装,后三个解决依赖性关系
收集信息用的
yum install zabbix-agent-4.0.5-1.el7.x86_64.rpm -y
图形化管理:
yum install httpd -y
2、数据库配置
数据库初始化:
systemctl start mysqld
systemctl enable mysqld
mysql_secure_installation
建库zabbix
create database zabbix character set utf8 collate utf8_bin;
创建zabbix用户并授权
grant all privileges on zabbix.* to zabbix@localhost identified by 'westos';
导入zabbix数据
zcat /usr/share/doc/zabbix-server-mysql-4.0.5/creat.sql.gz | mysql zabbix -p
输入密码,开始导入,需要较长时间,耐心等待
登陆数据库,查看数据是否同步
mysql -uroot -p
show databases;
use zabbix;
show tables; 可以看到很多表
3、zabbix-server配置
vim /etc/zabbix/zabbix_server.conf
#和数据库配置时设置的参数保持一致
DBName=zabbix
DNUser=zabbix
DBPassword=westos
systemctl start zabbix-server
systemctl enable zabbix-server
ps ax | grep zabbix 查看进程是否开启
vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai 时区改为这个,去掉注释,否则图形化监控的时候会出错
systemctl start httpd
systemctl enable httpd
3、server2部署
下载agent,收集信息
yum install -y zabbix-agent-4.0.5-1.el7.x86_64.rpm
配置agent:
vim /etc/zabbix/zabbix_agentd.conf
Server=172.25.17.101 监控ip
ServerActive=172.25.17.101
Hostname=server2
systemctl start zabbix-agent
systemctl enable zabbix-agent
4、浏览器部署
访问:http://172.25.17.101/zabbix,按照流程走,默认登陆用户为Admin,密码为zabbix
登陆成功的界面
5、图形化管理zabbix-server
zabbix信息采集方式:(agent,jmx,ipmi,snmp)
agent(收集信息)->pollers(触发器)->items(监控项)->thigger(触发器)->events(事件)->action(动作)->alert(报警)->media(传送媒介)
一般情况下items里边的内容会很多,会直接导入template
template里边包含:graph,thrigger,items...
host可以加入hostgroup,可以直接链接template,也可以设置为维护状态,不报警
1)、添加主机
配置-->主机(右上选择创建主机)-->输入主机名称,选择群组或者直接链接模版,在最下边选择添加
2)、自动发现
配置-->动作-->启用Auto discovery
配置-->自动发现-->进去local network-->更改ip范围,更新时间-->启用local network
server4配置
安装agent:
yum install zabbix-agent-4.0.5-1.el7.x86_64.rpm -y
修改配置:
vim /etc/zabbix/zabbix_agentd.conf
Server=172.25.17.101
ServerActive=172.25.17.101
Hostname=server4
systemctl start zabbix-agent
报错如下:
2482:20190802:030312.897 cannot set resource limit: [13] Permission denied
2482:20190802:030312.897 cannot disable core dump, exiting...
2485:20190802:030323.147 Starting Zabbix Agent [server4]. Zabbix 4.0.5 (revisi
解决方法:
将selinux设置为disabled模式
/etc/sysconfig/selinux
启动服务
systemctl start zabbix-agent
systemctl enable zabbix-agent
在浏览器(配置-->主机)刷新,等待出结果
3)、自动注册
删除自动发现的节点server4,停用local network和Auto discorvery
动作选择自动注册,并创建动作
6、API借口管理zabbix-server
获取token
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "Admin",
"password": "zabbix"
},
"id": 1,
"auth": null
}' http://172.25.17.101/zabbix/api_jsonrpc.php | python -m json.tool
执行结果:
{
"id": 1,
"jsonrpc": "2.0",
"result": "5e1a8acbb1460f92a33659eca1ebe3cb"
}
获取zabbix监控的主机和主机id
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["host"]
},
"auth": "5e1a8acbb1460f92a33659eca1ebe3cb",
"id": 1
}' http://172.25.17.101/zabbix/api_jsonrpc.php | python -m json.tool 格式化输出
运行结果:
{
"id": 1,
"jsonrpc": "2.0",
"result": [
{
"host": "server2",
"hostid": "10265"
},
{
"host": "Zabbix server",
"hostid": "10266"
}
]
}
创建主机
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "server6.example.com",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "172.25.17.103",
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "2" 在浏览器选择(配置->主机群组->选择要加入的群组,url中会有组id)
}
],
"templates": [
{
"templateid": "10110" 在浏览器中选择(配置->模版->选择要用的模版,url中会有模版)
}
]
},
"auth": "9c9e60d2752e9b70e96a3a3c6adaba94", 执行获取token的脚本,会获取到token
"id": 1
}' http://172.25.17.101/zabbix/api_jsonrpc.php | python -m json.tool
删除主机
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.delete",
"params": [
"10112" hostid号
],
"auth": "9c9e60d2752e9b70e96a3a3c6adaba94", token数值
"id": 1
}' http://172.25.27.101/zabbix/api_jsonrpc.php | python -m json.tool