server1:(centos7以上)ip=172.25.8.11
在server1中:
yum install -y php-bcmath-5.4.16-42.el7.x86_64.rpm php-mbstring-5.4.16-42.el7.x86_64.rpm zabbix-agent-3.4.6-1.el7.x86_64.rpm zabbix-server-mysql-3.4.6-1.el7.x86_64.rpm zabbix-web-3.4.6-1.el7.noarch.rpm zabbix-web-mysql-3.4.6-1.el7.noarch.rpm fping-3.10-1.el7.x86_64.rpm iksemel-1.4-2.el7.centos.x86_64.rpm
yum install -y mariadb mariadb-server
systemctl start mariadb
mysql
create database zabbix character set utf8 collate utf8_bin; ##创建zabbix库
grant all privileges on zabbix.* to zabbix@localhost identified by 'westos'; ##授权
cd /usr/share/doc/zabbix-server-mysql-3.4.6/
ll create.sql.gz
zcat create.sql.gz | mysql -uzabbix -pwestos Zabbix ##导入库
mysql
use zabbix
show tables;
cd /etc/zabbix/
vim zabbix_server.conf
DBPassword=westos
cd /etc/httpd/conf.d/
ll zabbix.conf
vim zabbix.conf
systemctl start zabbix-server
vim /etc/php.ini
date.timezone = Asia/Shanghai
systemctl start httpd
物理机firefox访问172.25.4.11/zabbix
登陆
ZABBIX
Username Admin
Password zabbix
点击右上角小人头更改为中文
systemctl start zabbix-agent
主机中 zabbix server 启用主机
server2:
[root@test2 ~]# rpm -ivh zabbix-agent-3.4.6-1.el7.x86_64.rpm
[root@test2 ~]# vim /etc/zabbix/zabbix_agentd.conf (需要本地解析)
Server=182.25.8.11
ServerActive=172.25.8.11
HostName=test2
主机的几种添加方式:
[root@test2 ~]# systemctl start zabbix-agent.service
[root@test2 ~]# netstat -antlp
在172.25.4.11/Zabbix
手动添加
添加主机
点击配置—>主机—>创建主机
添加模版
自动发现:
配置–>自动发现–>创建发现规则
自动注册
Api;
通过api查看,删除,添加监控
curl -s -X POST -H 'Content-Type: application/json' -d '
"user":"Admin",
"password": "zabbix"
"auth": null
chmod +x zabbix.api
{
"id": 1,
"jsonrpc": "2.0",
"result": "1309609a9fa442ac3ac560b45da35b01"
}
[root@test1 ~]# vim zabbicG.api ##获取主机信息
[root@test1 ~]# ./zabbicG.api
curl -s -X POST -H 'Content-Type: application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["host"]
},
"id": 1,
"auth": "1309609a9fa442ac3ac560b45da35b01"
}' http://172.25.8.11/zabbix/api_jsonrpc.php | python -m json.tool
[root@test1 ~]# vim zabbixD.zpi ##删除监控
url -s -X POST -H 'Content-Type: application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.delete",
"params": [
10257
],
"id": 1,
"auth": "1309609a9fa442ac3ac560b45da35b01"
}' http://172.25.8.11/zabbix/api_jsonrpc.php | python -m json.tool
[root@test1 ~]# vim zabbix.zpi ##创建监控
curl -s -X POST -H 'Content-Type: application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "test2",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "172.25.8.12",
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "2"
}
],
"templates": [
{
"templateid": "10001"
}
]
},
"id": 1,
"auth": "1309609a9fa442ac3ac560b45da35b01"
}' http://172.25.8.11/zabbix/api_jsonrpc.php | python -m json.tool