zabbix(音同 za:bix)是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
zabbix由2部分构成,zabbix server与可选组件zabbix agent。
zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。
yum install zabbix-server-mysql-3.4.6-1.el7.x86_64.rpm zabbix-web-3.4.6-1.el7.noarch.rpm zabbix-server-mysql-3.4.6-1.el7.x86_64.rpm fping-3.10-1.el7.x86_64.rpm iksemel-1.4-2.el7.centos.x86_64.rpm php-* php-bcmath-5.4.16-42.el7.x86_64.rpm zabbix-web-mysql-3.4.6-1.el7.noarch.rpm
yum install mariadb-server -y
systemctl start mariadb
mysql_secure_installation
mysql -p #创建zabbix用户
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 'westos';
Query OK, 0 rows affected (0.00 sec)
cd /usr/share/doc/zabbix-server-mysql-3.4.6/
ls
zcat create.sql.gz | mysql -u zabbix -p zabbix #导入zabbix数据库过程会有点长有140个表格
mysql -pwestos #查看zabbix数据库
cd /etc/zabbix/
vim zabbix_server.conf #编辑zabbix配置文件
ll /var/lib/mysql/mysql.sock #查看脚本位置
vim zabbix_server.conf #zabbix用户密码;socket
cd /etc/httpd/conf.d/
vim zabbix.conf
php_value date.timezone Asia/Shanghai #修改时区
systemctl start zabbix-server
systemctl start httpd
yum install zabbix-agent-3.4.6-1.el7.x86_64.rpm
systemctl start zabbix-agent
登陆zabbix监控:
Zabbix======passwd(westos)
安装zabbix-agent
rpm -ivh zabbix-agent-3.4.6-1.el6.x86_64.rpm
cd /etc/zabbix/
ls
vim zabbix_agentd.conf #编辑Serveractive
/etc/init.d/zabbix-agent start
netstat -antlp|grep 10050 #zabbix-agent_port=10050
事件源—–>自动发现通过给定域名和网段自动发现
执行动作
执行动作规则:
自动发现结果:这个因为是自动发现会有一定的随机性可能要等待一段时间系统会在一定的时间段执行自动发现动作所以大家如果想要立即看到效果可以用手动添加下一种方法
自动注册—->通过触发器触发条件自动注册
1.添加主机
2.添加主集群组
3.链接到模版
脚本添加:
获取zabbix_agent的认证key
[root@server1 ~]# vim zabbix-api.sh
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.30.1/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# ./zabbix-api.sh
{
"id": 1,
"jsonrpc": "2.0",
"result": "672c0a8a88fb9179a92dd894a05a3610"
}
2.[root@server1 ~]# vim 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"
]
},
"id": 1,
"auth": "50f7409eb4b464b01af085c5b992ead6"
}' http://172.25.30.1/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# ./zabbix-api.sh
{
"id": 1,
"jsonrpc": "2.0",
"result": [
{
"host": "Zabbix server",
"hostid": "10084",
"interfaces": [
{
"interfaceid": "1",
"ip": "127.0.0.1"
}
]
}
]
}
删除监控事件
[root@server1 ~]# vim zabbix-api.sh
curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.delete",
"params": [
"10084"
],
"id": 1,
"auth": "50f7409eb4b464b01af085c5b992ead6"
}' http://172.25.30.1/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# ./zabbix-api.sh
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"hostids": [
"10084"
]
}
}
创建即添加监控事件
[root@server1 ~]# vim ./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.30.2",
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "2"
}
],
"templates": [
{
"templateid": "10001"
}
]
},
"id": 1,
"auth": "50f7409eb4b464b01af085c5b992ead6"
}' http://172.25.30.1/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# ./zabbix-api.sh
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"hostids": [
"10260"
]
}
}
yum install httpd
hostname
/etc/init.d/httpd start
cd /var/www/html/
vim index.html
cd /etc/zabbix/zabbix_agentd.d/
vim userparameter_mysql.conf #家目录在/var/lib/zabbix
发现没有该目录我们需要自己建立一个:
mkdir /var/lib/zabbix
cd /var/lib/zabbix/ 建立隐藏配置文件
vim .my.cnf
[mysql]
user=root
password=redhat 数据库登录密码
socket=/var/lib/mysql/mysql.sock
[mysqladmin]
user=root
password=redhat
socket=/var/lib/mysql/mysql.sock
systemctl restart zabbix-agent