zabbix是一个基于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等平台上。
zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。zabbix agent可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD, OS X, Tru64/OSF1, Windows NT4.0, Windows 2000/2003/XP/Vista)等系统之上。
zabbix server可以单独监视远程服务器的服务状态;同时也可以与zabbix agent配合,可以轮询zabbix agent主动接收监视数据(trapping方式),同时还可被动接收zabbix agent发送的数据(trapping方式)。
另外zabbix server还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用
实验环境
centos6.8_x64
Liux_server 192.168.1.102
linux_slave 192.168.1.104
windows_slave 192.168.1.106
实验软件
epel-release-6-8.noarch.rpm
latest.rpm
zabbix-3.2.6.tar.gz
zabbix-agent-3.2.6-1.el6.x86_64.rpm
zabbix_agents_3.2.0.win.zip
heirloom-mailx_12.5.orig.tar.gz
软件安装
yum clean all
yum makecache -y
rpm -ivh epel-release-6-8.noarch.rpm
rpm -ivn latest.rpm
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
sed -i 's/^mirrorlist=https/mirrorlist=http/' /etc/yum.repos.d/epel.repo
sed -i 's/^mirrorlist=https/mirrorlist=http/' /etc/yum.repos.d/webtatic.repo
yum install -y ssh* libssh2-devel* openldap openldap-devel openssl openssl-devel unixODBC-devel ld-linux.so.2
yum install -y OpenIPMI OpenIPMI-devel ipmitool freeipmi
yum install -y httpd* mysql mysql-devel mysql-server gcc* net-snmp* curl-devel*
yum install -y php55w php55w-bcmath php55w-cli php55w-common php55w-devel php55w-fpm php55w-gd php55w-imap php55w-ldap php55w-mbstring php55w-mcrypt php55w-mysql php55w-odbc php55w-pdo php55w-pear php55w-pecl-igbinary php55w-xml php55w-xmlrpc php55w-opcache php55w-intl php55w-pecl-memcache
groupadd zabbix
useradd -g zabbix zabbix
zabbix3的版本需要php5.4以上版本兼容,6.8_x64默认php是6.3
php -version
PHP 5.5.38 (cli) (built: Jul 21 2016 12:51:12)
Copyright (c) 1997-2015 The PHP Group
sed -i 's/#ServerName www.example.com:80/ServerName *:80/g' /etc/httpd/conf/httpd.conf
vim /etc/httpd/conf/httpd.conf
#AddType application/x-tar .tgz 找到
AddType application/x-tar .tgz 改为
AddType application/x-httpd-php .php
tar zxvf zabbix-3.2.6.tar.gz
cd zabbix-3.2.6
./configure --prefix=/usr/local/zabbix --with-mysql --with-net-snmp --with-libcurl
--enable-server --enable-agent --with-openipmi --with-unixodbc --with-ldap --with-ssh2 --with-openssl
--enable-proxy --enable-ipv6 --with-libxml2
make && make install
mysqladmin -uroot password 数据库密码
mysql -uroot -p数据库密码 -p数据库密码没有空格
mysql> create database zabbix;
mysql> grant all privileges on zabbix.*to zabbix@localhost identified by 'zabbix'; 开放权限
mysql> select host,user from mysql.user;
mysql> drop user 'test'@'%'; 删除用户
mysql> flush privileges;
mysql> quit;
mysql -uroot -p数据库密码 zabbix < zabbix-3.2.6/database/mysql/schema.sql
mysql -uroot -p数据库密码 zabbix < zabbix-3.2.6/database/mysql/images.sql
mysql -uroot -p数据库密码 zabbix < zabbix-3.2.6/database/mysql/data.sql
less /usr/local/zabbix/etc/zabbix_server.conf | grep DBName
### Option: DBName
# DBName=
DBName=zabbix 没有# zabbix为正确配置 无需修改
less /usr/local/zabbix/etc/zabbix_server.conf | grep DBUser
# For SQLite3 path to database file must be provided. DBUser and DBPassword are ignored.
### Option: DBUser
# DBUser=
DBUser=zabbix 没有# zabbix为正确配置 无需修改
sed -i 's/# DBPassword=/DBPassword=zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf
cat >>/etc/services <<EOF
>zabbix-agent 10050/tcp
>zabbix-agent 10050/udp
>zabbix-trapper 10051/tcp
>zabbix-trapper 10051/udp
>EOF
less /etc/services | grep 1005
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper
zabbix-agent 10050/tcp
zabbix-agent 10050/udp
zabbix-trapper 10051/tcp
zabbix-trapper 10051/udp
mkdir /var/www/html/zabbix
cp -rv zabbix-3.0.2/frontends/php/* /var/www/html/zabbix/
chown -R apache:apache /var/www/html/zabbix/
touch /var/www/html/test.php
echo "<?php phpinfo(); ?>" > /var/www/html/test.php
more /var/www/html/test.php
<?php phpinfo(); ?>
vim /etc/php.ini
date.timezone = "Asia/Chongqing"
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
service httpd restart
service mysqld restart 实验环境默认使用yum安装,源代码安装此步可忽略
chkconfig --level 35 httpd on
chkconfig --level 35 mysqld on
cp /usr/local/zabbix/sbin/zabbix_agentd /etc/init.d
cp /usr/local/zabbix/sbin/zabbix_server /etc/init.d
/etc/init.d/zabbix_server
/etc/init.d/zabbix_agentd 第一种启动服务方法
/usr/local/zabbix/sbin/zabbix_server restart 第二种启动服务方法
/usr/local/zabbix/sbin/zabbix_agentd restart
tail -f /var/log/mysqld.log
170729 18:31:58 [Note] /usr/libexec/mysqld: Shutdown complete
170729 18:31:58 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
170729 18:31:59 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
170729 18:31:59 InnoDB: Initializing buffer pool, size = 8.0M
170729 18:31:59 InnoDB: Completed initialization of buffer pool
170729 18:31:59 InnoDB: Started; log sequence number 0 5621536
170729 18:31:59 [Note] Event Scheduler: Loaded 0 events
170729 18:31:59 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.73' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock 如果出现这个报错请使用这条命令解决问题
netstat -tuplna | grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 16473/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 16405/zabbix_server
netstat -tuplna | grep 80
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1804/master
tcp 0 0 :::80 :::* LISTEN 2419/httpd
netstat -tuplna | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:*
LISTEN 1712/mysqld
http://192.168.1.102/zabbix/setup.php
password 为数据库授权用户密码
默认用户名 admin 密码 zabbix
zabbix显示中文
vim /var/www/html/zabbix/include/locales.inc.php
'zh_CN' => array('name' => _('Chinese (zh_CN)'), 'display' => false),
'zh_CN' => array('name' => _('Chinese (zh_CN)'), 'display' => ture), false关闭 ture开
启
问题发生原因
Zabbix默认英文,没有正文字库添加中文字库
解决办法
Windows系统中 c:\windows\fonts 目录中有一个 msyh.ttf(雅黑),复制到zabbix配置文件里
cd /var/www/html/zabbix/fonts/
cp -p DejaVuSans.ttf /var/www/html/zabbix/fonts/DejaVuSans.ttf.bak
mv msyh.ttf /var/www/html/zabbix/fonts/DejaVuSans.ttf
mv: overwrite `/var/www/html/zabbix/fonts/DejaVuSans.ttf'? y
客户端安装(Linux centos6)
zabbix-agent-3.2.6-1.el6.x86_64.rpm
yum install zabbix-sender zabbix-agent zabbix
ll /etc/yum.repos.d/
total 32
-rw-r--r--. 1 root root 2006 Dec 1 2016 CentOS6-Base-163.repo
-rw-r--r--. 1 root root 1926 Nov 27 2013 CentOS-Base.repo
-rw-r--r--. 1 root root 638 Nov 27 2013 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 630 Nov 27 2013 CentOS-Media.repo
-rw-r--r--. 1 root root 3664 Nov 27 2013 CentOS-Vault.repo
-rw-r--r--. 1 root root 954 Sep 2 13:28 epel.repo
-rw-r--r--. 1 root root 1056 Nov 5 2012 epel-testing.repo
-rw-r--r-- 1 root root 401 Sep 11 2014 zabbix.repo
groupadd zabbix
useradd zabbix -g zabbix
sed -i 's/Server=127.0.0.1/Server=192.168.1.102/g' /etc/zabbix/zabbix_agentd.conf 127.0.0.1为配置文件默认配置 192.168.1.102为服务端ip
sed -i 's/ServerActive=127.0.0.1/ServerActive=192.168.1.102/g' /etc/zabbix/zabbix_agentd.conf
sed -i 's/# UnsafeUserParameters=0/UnsafeUserParameters=1/g' /etc/zabbix/zabbix_agentd.conf
/etc/rc.d/init.d/zabbix-agent restart
netstat -tuplna | grep 10050
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 5845/zabbix_agentd
tcp 0 0 :::10050 :::* LISTEN 5845/zabbix_agentd
zabbix 服务端执行命令
/usr/local/zabbix/bin/zabbix_get -s 192.168.1.104 -p 10050 -k"system.uptime"
8463
/usr/local/zabbix/bin/zabbix_get -s 192.168.1.104 -p 10050 -k"net.if.in[eth0]" 192.168.1.104(linux_agent客户端)
34793097
/usr/local/zabbix/bin/zabbix_get -s 192.168.1.106 -p 10050 -k"system.uptime" 192.168.1.106(windows_agent客户端)
308
/usr/local/zabbix/bin/zabbix_get -s 192.168.1.106 -p 10050 -k"system.hostname"
WIN-RP67B9L0QKH
windows客户端安装(windows 2008)
修改 c:\zabbix\conf\zabbix_agentd.win.conf
Server=127.0.0.1
ServerActive=127.0.0.1
改为 Server/ServerActive=192.168.1.102 zabbix_server服务端ip (Server两项配置相同)
# UnsafeUserParameters=0 找到
UnsafeUserParameters=1 改为
C:\Users\Administrator>cd C:\zabbix_agents_3.2.0\bin\win64
C:\zabbix_agents_3.2.0\bin\win64>zabbix_agentd.exe -i -c C:\zabbix_agents_3.2.0\
conf\zabbix_agentd.win.conf
开始-cmd-services.msc
cmd-services.msc-zabbix agent-属性-从新启动
默认windows2003 2008防火墙会阻拦 zabbix_agentd zabbix_get的数据包,所以必须清空防火墙规则(不关闭防火墙情况下)
服务端添加主机
设置邮件报警
tar zxvf heirloom-mailx_12.5.orig.tar.gz
cd heirloom-mailx-12.5/
make && make install UCBINSTALL=/usr/bin/install
cp /etc/nail.rc /etc/nail.rc.bak
vim /etc/nail.rc
set from=xxx@126.com 发送邮箱
set smtp=smtp.126.com 发送邮箱smtp地址
set smtp-auth-user=xxx@126.com 接收邮箱
set smtp-auth-password=xxx 邮箱密码
set smtp-auth=login
echo 123 | mailx -v -s "zabbix test mail" xxx@126.com
com
-bash: echp: command not found
Resolving host smtp.126.com . . . done.
Connecting to 220.181.15.111:25 . . . connected.
220 126.com Anti-spam GT for Coremail System (126com[20140526])
>>> EHLO vm172-18-0-18.ksc.com
250-mail
250-PIPELINING
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFhQBZHUCa0xDrUUUUj
250-STARTTLS
250 8BITMIME
>>> AUTH LOGIN
334 dXNlcm5hbWU6
>>> d3loMTk4NzI1QDEyNi5jb20=
334 UGFzc3dvcmQ6
>>> V1lIMTk4NzI1IUAj
235 Authentication successful
>>> MAIL FROM:<wyh198725@126.com>
250 Mail OK
>>> RCPT TO:<wyh198725@126.com>
250 Mail OK
>>> DATA
354 End data with <CR><LF>.<CR><LF>
>>> .
250 Mail OK queued as smtp1,C8mowABnDOoAivZZ4IC0AQ--.8734S2 1509329409
>>> QUIT
221 Bye
本文转自 mailfile 51CTO博客,原文链接:http://blog.51cto.com/mailfile/1205196,如需转载请自行联系原作者