Zabbix
Zabbix监控环境安装
准备两台VM,server端:192.168.56.144/24(zabbix) agent端:192.168.56.135/24(mysql)
依照官方文档安装zabbix
[root@zabbix zabbix]# yum install -y zabbix-server zabbix-web-2.4.7-1.el6.noarch.rpm zabbix-server-mysql-2.4.7-1.el6.x86_64.rpm zabbix-web-mysql zabbix-agent ^C
[root@zabbix zabbix]# yum install -y mysql-server mysql^C
[root@zabbix zabbix]#
修改MySQL配置文件
[mysqld]
character-set-server = utf8
init-connect = 'SET NAMES utf8'
collation-server = utf8_general_ci
创建MySQL数据库(for zabbix)
shell> mysql -uroot -p<password>
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '<password>';
mysql> quit;
shell> mysql -uzabbix -p<password> zabbix < database/mysql/schema.sql
# stop here if you are creating database for Zabbix proxy
shell> mysql -uzabbix -p<password> zabbix < database/mysql/images.sql
shell> mysql -uzabbix -p<password> zabbix < database/mysql/data.sql
创建表结构
cd /usr/share/doc/zabbix-server-mysql-2.4.7/create/
[root@zabbix create]# mysql -uroot -p zabbix < schema.sql
Enter password:
[root@zabbix create]# mysql -uroot -p zabbix < images.sql
Enter password:
[root@zabbix create]# mysql -uroot -p zabbix < data.sql
Enter password:
默认安装好的zabbix.conf文件
[root@zabbix conf.d]# cat /etc/httpd/conf.d/zabbix.conf
#
# Zabbix monitoring system php web frontend
#
# 前端代码位置
Alias /zabbix /usr/share/zabbix
<Directory "/usr/share/zabbix">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
<IfModule mod_php5.c>
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
# php_value date.timezone Europe/Riga
</IfModule>
</Directory>
<Directory "/usr/share/zabbix/conf">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
<Directory "/usr/share/zabbix/api">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
<Directory "/usr/share/zabbix/include">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
<Directory "/usr/share/zabbix/include/classes">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
启动Apache
连接数据库配置
vim /etc/zabbix/zabbix_server.conf 修改DB
启动zabbix-server /etc/init.d/zabbix-server start
最终创建成功
Configuration file
"/etc/zabbix/web/zabbix.conf.php"
created: OK
Congratulations on successful installation of Zabbix frontend.
When done, press the "Finish" button
默认登录用户名密码Admin/zabbix(修改Admin密码,profile---->User---->change password)
修改zabbix_agent配置文件:(/etc/zabbix/zabbix_agentd.conf)Server地址
启动zabbix-agent /etc/init.d/zabbix-agent start
host指代监控的主机
item指代监控项,如CPU使用率、磁盘使用率等
trigger指代触发器,如CPU使用率超过设定值,即出发相应的操作
agent端(MySQL)设置:
[root@mysql zabbix]# vim /etc/zabbix/zabbix_agentd.conf
[root@mysql zabbix]# /etc/init.d/zabbix-agent start
Starting Zabbix agent: [ OK ]
设置DNS域名解析(/etc/hosts)
192.168.56.144 zabbix-server.liyang.me zabbix-server (linux-node1.example.com)
192.168.56.135 mysql.liyang.me mysql (linux-node2.example.com)
自定义监控和图表
1、修改配置文件,添加自定义的监控项
获取已登录的用户(通过uptime获取)
vim /etc/zabbix/zabbix_agentd.conf
### Option: UserParameter
# User-defined parameter to monitor. There can be several user-defined parameters.
# Format: UserParameter=<key>,<shell command>
# See 'zabbix_agentd' directory for examples.
#
# Mandatory: no
# Default:
UserParameter=login-user,uptime |awk -F ' ' '{print $4}'
[root@mysql ~]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent: [ OK ]
Starting Zabbix agent: [ OK ]
测试:
[root@zabbix ~]# zabbix_get --host mysql --key login-user
3
2、在WEB界面上,添加自定义的监控项
Configuration--->Hosts--->select mysql(linux-node2)--->items--->create items
3、图表
Configuration--->Hosts--->select mysql(linux-node2)--->Graphics--->create graphics
浙公网安备 33010602011771号