前一阵子刚刚带了一下公司的监控,使用zabbix轻松实现了需求,并且也很好用,闲言少叙,我们言归正传;
1、首先找一台虚拟机,纯净的,至少没有yum安装过Apache、zabbix、mysql、php
2、再找一台虚拟机,这台不要求什么
vi /etc/sysconfig/network
linux-node1. aishenghuo.com
linux-node2. aishenghuo.com
vi /etc/hosts
192.168.204.171 linux-node1.aishenghuo.com linux-node1
192.168.204.164 linux-node2. aishenghuo.com linux-node2
[root@linux-node1 ~]# /etc/init.d/iptables status
iptables:未运行防火墙。
[root@linux-node1 ~]# getenforce
Disabled
[root@linux-node1 ~]# rpm -qlzabbix-release
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
/etc/yum.repos.d/zabbix.repo
/usr/share/doc/zabbix-release-2.4
/usr/share/doc/zabbix-release-2.4/GPL
[root@linux-node1 ~]# yum list zabbix*
rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install zabbix-server-mysql zabbix-web-mysql mysql-server mysql wqy-microhei-fonts zabbix-get zabbix-agent
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install zabbix-server-mysql zabbix-web-mysql
rpm -ql zabbix
rpm -ql zabbix-server
rpm -ql zabbix-server-mysql
rpm -ql zabbix-web
rpm -ql zabbix-web-mysql
yum -y install mysql-server mysql
\cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
增加字符集
vim /etc/my.cnf
[mysqld] # 在[mysqld]标签下增加如下三行后保存
character-set-server = utf8
init-connect = 'SET NAMES utf8'
collation-server = utf8_general_ci
/etc/init.d/mysqld start
mysql �Curoot �Cp 默认密码为空
create database zabbix character set utf8 collate utf8_bin;
grant all on zabbix.* to zabbix@'localhost'identified by 'zabbix';
flush privileges;
[root@linux-node1 doc]# cd/usr/share/doc/zabbix-server-mysql-2.4.7/create
[root@linux-node1create]# vim /etc/httpd/conf.d/zabbix.conf
19 # php_value date.timezone Europe/Riga
20 php_valuedate.timezone Asia/Shanghai
mysql -uroot zabbix<schema.sql
mysql -uroot zabbix<images.sql
mysql -uroot zabbix<data.sql
vim /etc/zabbix/zabbix_server.conf
DBPassword=zabbix
/etc/init.d/zabbix-server start
/etc/init.d/httpd start
第二步
在两台服务器上安装
yum install zabbix-agent �Cy
两台机器都要更改服务器地址
vim /etc/zabbix/zabbix_agentd.conf
第85行,85gg
Server=192.168.204.164 不管多少台服务器,都只填写服务器的ip地址
[root@linux-node2 ~]#/etc/init.d/zabbix-agent start
Starting Zabbix agent: [确定]
[root@linux-node2 ~]# netstat -lntup|grep10050
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 7046/zabbix_agentd
tcp 0 0 :::10050 :::* LISTEN 7046/zabbix_agentd
http://192.168.204.171/zabbix
账号:Admin
密码:zabbix
一直下一步就按照成功了
如果连接显示的是红的,有以下几种可能
1、/zabbix_agentd.conf 的配置文件没有改成自己主机的ip
vim /etc/zabbix/zabbix_agentd.conf
第85行,85gg
Server=192.168.204.171 不管多少台服务器,都只填写服务器的ip地址
2、服务端里是否开启zabbix-agent
[root@linux-node2 ~]#/etc/init.d/zabbix-agent start
Starting Zabbix agent: [确定]
[root@linux-node2 ~]# netstat -lntup|grep10050
3. Zabbix自定义监控
[root@linux-node1 ~]# zabbix_get -s192.168.204.164 -p 10050 -k "system.cpu.load[all,avg1]"
0.000000
客户端
[root@linux-node2 ~]# vim/etc/zabbix/zabbix_agentd.conf
280行
# UserParameter=
UserParameter=login-user,uptime |awk '{print $6}'
提示:uptime |awk '{print $6}'这个命令是取出的是uptime执行的结果中,user前面的值
[root@linux-node2 ~]# uptime
14:46:58 up 4 days, 11:25, 3 users, load average:0.00, 0.00, 0.00
重启服务
[root@linux-node2 ~]# /etc/init.d/zabbix-agentrestart
服务端执行
[root@linux-node1 ~]# zabbix_get -s192.168.204.164 -p 10050 -k "login-user"
3
服务端里下载下面的软件,可避免zabbix的web端乱码
yum -y install wqy-microhei-fonts
rpm -ql wqy-microhei-fonts
ll /etc/alternatives/zabbix-web-font