#一、认识zabbix
- zabbix(音同 za:bix)是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
##zabbix的功能与特性
##Zabbix的系统组成
zabbix_agentd
、zabbix_get
、zabbix_proxy
、zabbix_sender
、zabbix_server
,另外一个zabbix_java_gateway
是可选,这个需要另外安装。下面来分别介绍下他们各自的作用。
- zabbix_agentd 客户端守护进程,此进程收集客户端数据,例如cpu负载、内存、硬盘使用情况等。
各进程对应的zabbix/3.4/rhel/7/x86_64/安装包下载(地址http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/)
#二、部署zabbix
##实验环境
##搭建zabbix平台
####server1所需安装包
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
php-bcmath-5.4.16-42.el7.x86_64.rpm
php-mbstring-5.4.16-42.el7.x86_64.rpm
zabbix-agent-3.4.2-1.el7.x86_64.rpm
####server1
[root@server1 ~]# ls
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
php-bcmath-5.4.16-42.el7.x86_64.rpm
php-mbstring-5.4.16-42.el7.x86_64.rpm
zabbix-agent-3.4.2-1.el7.x86_64.rpm
[root@server1 ~]# yum install -y *.rpm
//安装数据库mariadb并进行初始化
[root@server1 z~]# yum install -y mariadb-server
[root@server1 ~]# systemctl start mariadb
[root@server1 ~]# mysql_secure_installation
Set root password? [Y/n] y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
[root@server1 ~]# systemctl restart mariadb
[root@server1 ~]# mysql -p
Enter password: //直接回车
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
//创建数据库
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'redhat';
//进行授权
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> Bye
[root@server1 ~]# cd /usr/share/doc/zabbix-server-mysql-3.4.6/
[root@server1 zabbix-server-mysql-3.4.6]# ls
AUTHORS ChangeLog COPYING create.sql.gz NEWS README
[root@server1 zabbix-server-mysql-3.4.6]# zcat create.sql.gz | mysql -u zabbix -p zabbix
Enter password: //导入数据,输入授权用户zabbix的密码
[root@server1 zabbix-server-mysql-3.4.6]# mysql -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
............略................
| valuemaps |
| widget |
| widget_field |
+----------------------------+
140 rows in set (0.00 sec)
MariaDB [zabbix]> Bye
[root@server1 zabbix-server-mysql-3.4.6]# cd /etc/zabbix/
[root@server1 zabbix]# vim zabbix_server.conf
125 DBPassword=redhat
132 DBSocket=/var/lib/mysql/mysql.sock
[root@server1 zabbix]# ll /var/lib/mysql/mysql.sock
srwxrwxrwx 1 mysql mysql 0 Aug 14 15:28 /var/lib/mysql/mysql.sock
[root@server1 zabbix]# vim /etc/httpd/conf.d/zabbix.conf
19 php_value date.timezone Asia/Shanghai //修改时区
[root@server1 zabbix]# systemctl start zabbix-server
[root@server1 zabbix]# systemctl start httpd
[root@server1 zabbix]# systemctl start zabbix-agent
####浏览器操作
#####修改密码后退出重新登陆
####server2
[root@serevr2 ~]# ls
zabbix-agent-3.4.6-1.el6.x86_64.rpm
[root@serevr2 ~]# rpm -ivh zabbix-agent-3.4.6-1.el6.x86_64.rpm
[root@serevr2 ~]# vim /etc/zabbix/zabbix_agentd.conf
97 Server=172.25.54.1
138 ServerActive=172.25.54.1
149 Hostname=server2
[root@serevr2 ~]# /etc/init.d/zabbix-agent start
[root@serevr2 ~]# netstat -antpl
[root@server1 ~]# vim zabbix-api.sh
[root@server1 ~]# chmod +x zabbix-api.sh
[root@server1 ~]# cat zabbix-api.sh
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "Admin",
"password": "redhat"
},
"id": 1,
"auth": null
}' http://172.25.54.1/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# ./zabbix-api.sh
{
"id": 1,
"jsonrpc": "2.0",
"result": "2cb16ddca9d07e50b68cf736eaf3f283"
}
[root@server1 ~]# vim zabbix-api.sh
[root@server1 ~]# cat zabbix-api.sh
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": [
"hostid",
"host"
],
"selectInterfaces": [
"interfaceid",
"ip"
]
},
"auth": "2cb16ddca9d07e50b68cf736eaf3f283",
"id": 2
}' http://172.25.54.1/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# ./zabbix-api.sh
{
"id": 2,
"jsonrpc": "2.0",
"result": [
{
"host": "Zabbix server",
"hostid": "10084",
"interfaces": [
{
"interfaceid": "1",
"ip": "127.0.0.1"
}
]
},
{
"host": "server2",
"hostid": "10259",
"interfaces": [
{
"interfaceid": "7",
"ip": "172.25.54.11"
}
]
}
]
}[root@server1 ~]#
//删除主机
[root@server1 ~]# vim zabbix-api.sh
[root@server1 ~]# cat zabbix-api.sh
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.delete",
"params": [
"10259"
],
"auth": "2cb16ddca9d07e50b68cf736eaf3f283",
"id": 2
}' http://172.25.54.1/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# ./zabbix-api1.sh
//创建主机
[root@server1 ~]# cat zabbix-api.sh
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "server2",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "172.25.54.2",
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "2"
}
],
"templates": [
{
"templateid": "10001"
}
],
},
"auth": "2cb16ddca9d07e50b68cf736eaf3f283",
"id": 2,
}' http://172.25.54.1/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# ./zabbix-api1.sh