在localhost添加解析(企业7的虚拟机):
[root@localhost ~]# hostname
server1
[root@localhost ~]# vim /etc/hosts
[root@localhost ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.38.11 server1
172.25.38.12 test2
172.25.38.13 test3
172.25.38.14 test4
172.25.38.15 test5
172.25.38.16 test6
172.25.38.3 server3
在agent端(server3)添加解析(企业6虚拟机):
[root@server3 ~]# hostname
server3
[root@server3 ~]# vim /etc/hosts
[root@server3 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.38.11 server1
172.25.38.2 server2
172.25.38.3 server3
172.25.38.4 server4
172.25.38.5 server5
172.25.38.6 server6
[root@server3 ~]#
在server3安装zabbix代理:
[root@server3 ~]# ls
mysql-proxy-0.8.5-linux-el6-x86-64bit.tar.gz
zabbix-agent-3.4.6-1.el6.x86_64.rpm
[root@server3 ~]# rpm -ivh zabbix-agent-3.4.6-1.el6.x86_64.rpm
warning: zabbix-agent-3.4.6-1.el6.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ########################################### [100%]
1:zabbix-agent ########################################### [100%]
[root@server3 ~]# cd /etc/zabbix/
[root@server3 zabbix]# ls
zabbix_agentd.conf zabbix_agentd.d
[root@server3 zabbix]# vim zabbix_agentd.conf 写入agent-server的IP,也就是localhost的IP
[root@server3 zabbix]# /etc/init.d/zabbix-agent start 开启服务
Starting Zabbix agent: [ OK ]
[root@server3 zabbix]# netstat -antlp 可以看到10050端口
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 915/redis-server 0.
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 908/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 993/master
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 1118/zabbix_agentd
tcp 0 0 172.25.38.3:22 172.25.38.250:38770 ESTABLISHED 1042/sshd
tcp 0 0 :::22 :::* LISTEN 908/sshd
tcp 0 0 ::1:25 :::* LISTEN 993/master
tcp 0 0 :::10050 :::* LISTEN 1118/zabbix_agentd
在网页测试,之后的几个实验使用172.25.254.0/24网段进行实验:
1.手动创建主机:
2.自动注册:
3.自动发现:
1、获取Token:
[root@localhost ~]# vim zabbix-api.sh
[root@localhost ~]# chmod +x zabbix-api.sh 加入权限
[root@localhost ~]# ./zabbix-api.sh 调用脚本
{
"id": 1,
"jsonrpc": "2.0",
"result": "03a36ed5f6882ca93a201983ddb9830f"
}
[root@localhost ~]# cat zabbix-api.sh
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "Admin",
"password": "westos"
},
"id": 1,
"auth": null
}' http://172.25.254.11/zabbix/api_jsonrpc.php | python -m json.tool
get主机:
[root@localhost ~]# vim zabbix-api.sh
[root@localhost ~]# chmod +x zabbix-api.sh
[root@localhost ~]# ./zabbix-api.sh
{
"id": 1,
"jsonrpc": "2.0",
"result": [
{
"host": "Zabbix server",
"hostid": "10084"
},
{
"host": "server3",
"hostid": "10255"
}
]
}
[root@localhost ~]# cat zabbix-api.sh
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["host"]
},
"auth": "03a36ed5f6882ca93a201983ddb9830f",
"id": 1
}' http://172.25.254.11/zabbix/api_jsonrpc.php | python -m json.tool
删除主机:
[root@localhost ~]# vim zabbix-api.sh 删除server3
[root@localhost ~]# chmod +x zabbix-api.sh
[root@localhost ~]# ./zabbix-api.sh
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"hostids": [
"10255"
]
}
}
[root@localhost ~]# cat zabbix-api.sh
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.delete",
"params": [
"10255"
],
"auth": "03a36ed5f6882ca93a201983ddb9830f",
"id": 1
}' http://172.25.254.11/zabbix/api_jsonrpc.php | python -m json.tool
在网页查看server3虚拟机已经被删除: