[关闭]
@cdmonkey 2015-10-14T05:25:13.000000Z 字数 9343 阅读 1341

Zabbix(1)安装

Zabbix


此处输入图片的描述

一、简介

官方文档:
https://www.zabbix.com/documentation/2.2/manual/installation/install

Zabbix是一个基于WEB页面的提供分布式系统监视,以及网络监视功能的企业级的开源解决方案。它能够监视各种网络参数,保证服务器系统的安全运营。并提供灵活的通知机制以让系统管理员快速定位并解决存在的各种问题。

由两部分构成:Zabbix Server & Zabbix Agent(可选组件)。

二、安装

Official Manual: https://www.zabbix.com/documentation/2.4/

1. Server - Monitoring terminal

Install LNMP

具体的安装过程请参见相关文档。

  1. [root@Zabbix ~]# cat /etc/redhat-release
  2. CentOS release 6.6 (Final)
  3. # Yum install:
  4. yum install -y gcc gcc-c++ autoconf automake
  5. yum install -y zlib zlib-devel openssl openssldevel pcre pcre-devel
  6. yum install -y nginx
  7. yum install -y mysql mysql-server mysql-devel
  8. yum install -y php lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc \
  9. php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap \
  10. php-tidy php-common php-devel php-fpm php-bcmath
  1. # Start MySQL service:
  2. [root@Zabbix ~]# /etc/init.d/mysqld start
  3. [root@Zabbix ~]# /usr/bin/mysqladmin -u root password '123456'
  4. [root@Zabbix ~]# mysql -uroot -p
  5. Enter password:
  6. mysql> drop user ''@localhost;
  7. mysql> flush privileges;
  8. # Configure the Nginx:
  9. [root@Zabbix ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
  10. [root@Zabbix ~]# cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
  11. [root@Zabbix ~]# vim /etc/nginx/nginx.conf
  12. index index.html index.htm index.php;
  13. location ~ \.php$ {
  14. root /usr/share/nginx/html;
  15. fastcgi_pass 127.0.0.1:9000;
  16. fastcgi_index index.php;
  17. fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
  18. include fastcgi_params;
  19. }
  20. # Edit the php.ini:
  21. [root@Zabbix ~]# vim /etc/php.ini
  22. cgi.fix_pathinfo=1 # Remove the comments.
  23. # Start the services:
  24. [root@Zabbix ~]# /etc/init.d/nginx start
  25. [root@Zabbix ~]# /etc/init.d/php-fpm start

上面为通过“yum”进行的简易安装。

Install libmcrypt

  1. wget http://softlayer.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz
  2. [root@Zabbix tools]# tar zxvf libmcrypt-2.5.8.tar.gz
  3. [root@Zabbix tools]# cd libmcrypt-2.5.8
  4. [root@Zabbix libmcrypt-2.5.8]# ./configure --prefix=/usr/local
  5. [root@Zabbix libmcrypt-2.5.8]# make && make install
  1. #编译安装中出现下面的报错信息:
  2. ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
  3. --------------------
  4. #解决方法是制作一个软链接:
  5. ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18

上面的软件必须安装,否则会报错。接下来需要注意PHP的编译参数:

  1. #这里要注意PHP的最后三条编译参数,不然会报错和找不到MySQL的选项。
  2. ./configure \
  3. --prefix=/application/php5.3.27 \
  4. --with-mysql=/application/mysql \
  5. --with-iconv-dir=/usr/local/libiconv \
  6. --with-freetype-dir \
  7. --with-jpeg-dir \
  8. --with-png-dir \
  9. --with-zlib \
  10. --with-libxml-dir=/usr \
  11. --enable-xml \
  12. --disable-rpath \
  13. --enable-safe-mode \
  14. --enable-bcmath \
  15. --enable-shmop \
  16. --enable-sysvsem \
  17. --enable-inline-optimization \
  18. --with-curl \
  19. --with-curlwrappers \
  20. --enable-mbregex \
  21. --enable-fpm \
  22. --enable-mbstring \
  23. --with-mcrypt \
  24. --with-gd \
  25. --enable-gd-native-ttf \
  26. --with-openssl \
  27. --with-mhash \
  28. --enable-pcntl \
  29. --enable-sockets \
  30. --with-xmlrpc \
  31. --enable-zip \
  32. --enable-soap \
  33. --enable-short-tags \
  34. --enable-zend-multibyte \
  35. --enable-static \
  36. --with-xsl \
  37. --with-fpm-user=nginx \
  38. --with-fpm-group=nginx \
  39. --enable-ftp \
  40. --with-mysqli=/application/mysql/bin/mysql_config \
  41. --with-gettext \
  42. --with-openssl

Download Zabbix:
http://www.zabbix.com/download.php

Install Zabbix

首先,要创建、导入zabbix数据库。

  1. # Create Zabbix database:
  2. [root@Zabbix tools]# tar zxvf zabbix-2.4.5.tar.gz
  3. [root@Zabbix tools]# cd zabbix-2.4.5/database/mysql/
  4. [root@Zabbix mysql]# ll
  5. #可以看到有下面三个文件:
  6. total 2988
  7. -rw-r--r-- 1 1000 1000 972946 Apr 22 15:57 data.sql
  8. -rw-r--r-- 1 1000 1000 1978341 Apr 22 15:56 images.sql
  9. -rw-r--r-- 1 1000 1000 104816 Apr 22 15:57 schema.sql
  10. #进入数据库,创建库,并且数据库字符集使用utf8:
  11. mysql> create database zabbix character set utf8;
  12. #创建用户名及密码:
  13. mysql> insert into mysql.user(Host,User,Password) values('localhost','zabbix',password('zabbix'));
  14. mysql> flush privileges;
  15. #进行相应的授权:
  16. mysql> grant all on zabbix.* to zabbix@'localhost' identified by 'zabbix';
  17. mysql> flush privileges;
  18. #导入数据库。注意:请按照以下顺序进行导入,否则会出错。
  19. mysql> use zabbix;
  20. mysql> source /root/tools/zabbix-2.4.5/database/mysql/schema.sql;
  21. mysql> source /root/tools/zabbix-2.4.5/database/mysql/images.sql;
  22. mysql> source /root/tools/zabbix-2.4.5/database/mysql/data.sql;
  23. ------------------
  24. #创建软链接(注意系统版本不同,文件版本可能不同,这里是16.0.0):
  25. [root@Zabbix ~]# cd /usr/lib64/mysql/
  26. [root@Zabbix mysql]# ln -s libmysqlclient.so.16.0.0 libmysqlclient.so
  27. [root@Zabbix mysql]# ln -s libmysqlclient_r.so.16.0.0 libmysqlclient_r.so

接下来可以进行正式的安装了:

  1. # Create user account:
  2. [root@Zabbix ~]# useradd zabbix -s /bin/false
  3. #还要安装一些必要的软件包:
  4. [root@Zabbix ~]# yum install -y net-snmp-devel curl curl-devel libxml2-devel libcurl-devel
  5. [root@Zabbix ~]# ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
  6. #使配置立即生效:
  7. [root@Zabbix ~]# /sbin/ldconfig
  8. ------------------
  9. [root@Zabbix ~]# cd tools/zabbix-2.4.5
  10. ./configure \
  11. --prefix=/usr/local/zabbix --enable-server --enable-agent --with-libxml2 --with-net-snmp \
  12. --with-libcurl --enable-proxy --with-mysql
  13. [root@Zabbix zabbix-2.4.5]# make install
  14. #添加下列的系统软链接:
  15. ln -s /application/zabbix/sbin/* /usr/local/sbin/
  16. ln -s /application/zabbix/bin/* /usr/local/bin/

添加zabbix服务对应的端口:

  1. [root@Zabbix ~]# vim /etc/services
  2. #增加下面的内容,然后保存并退出:
  3. # Zabbix
  4. zabbix-agent 10050/tcp # Zabbix Agent
  5. zabbix-agent 10050/udp # Zabbix Agent
  6. zabbix-trapper 10051/tcp # Zabbix Trapper
  7. zabbix-trapper 10051/udp # Zabbix Trapper

启动服务之前需要分别对服务端及客户端的设置文件进行修改:

  1. # Zabbix Server:
  2. [root@Zabbix ~]# vim /usr/local/zabbix/etc/zabbix_server.conf
  3. #确保是下面的配置信息:
  4. DBName=zabbix
  5. DBUser=zabbix
  6. DBPassword=zabbix
  7. ListenIP=172.16.1.21
  8. AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts #指定运行脚本存放目录。

请注意,共有两个客户端的设置文件,其使用场景不同:

  1. zabbix_agent.conf # For xinetd
  2. zabbix_agentd.conf # For Daemon
  3. --------------------
  4. # Zabbix Agent:
  5. [root@Zabbix ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
  6. Server=172.16.1.21
  7. Include=/usr/local/zabbix/etc/zabbix_agent.conf.d/
  8. UnsafeUserParameters=1

添加开机启动脚本:

  1. cp tools/zabbix-2.4.5/misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server
  2. cp tools/zabbix-2.4.5/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd
  3. [root@Zabbix ~]# chmod +x /etc/init.d/zabbix_server
  4. [root@Zabbix ~]# chmod +x /etc/init.d/zabbix_agentd
  5. [root@Zabbix ~]# chkconfig zabbix_server on
  6. [root@Zabbix ~]# chkconfig zabbix_agentd on

修改开机启动脚本中的安装目录:

  1. [root@Zabbix ~]# vim /etc/rc.d/init.d/zabbix_server
  2. BASEDIR=/usr/local/zabbix
  3. [root@Zabbix ~]# vim /etc/rc.d/init.d/zabbix_agentd
  4. BASEDIR=/usr/local/zabbix

2. Client

服务端的安装推荐使用源码编译安装,而客户端则不建议使用源码安装。

RPM install

  1. [root@Node-A2 tools]# rpm -ivh zabbix-2.4.5-1.el6.x86_64.rpm
  2. [root@Node-A2 tools]# rpm -ivh zabbix-agent-2.4.5-1.el6.x86_64.rpm
  3. ---------------------
  4. [root@Node-A2 ~]# vim /etc/zabbix/zabbix_agentd.conf
  5. Server=172.16.1.21
  6. [root@Node-A2 ~]# /etc/init.d/zabbix-agent start
  7. [root@Node-A2 ~]# chkconfig --add zabbix-agent
  8. [root@Node-A2 ~]# chkconfig zabbix-agent on

Binary install

Compile install

  1. [root@WEB-A2 tools]# useradd zabbix -s /sbin/nologin
  2. [root@WEB-A2 tools]# tar zxvf zabbix-2.2.8.tar.gz
  3. [root@WEB-A2 tools]# cd zabbix-2.2.8
  4. [root@WEB-A2 zabbix-2.2.8]# ./configure \
  5. --prefix=/application/zabbix --sysconfdir=/etc//zabbix --enable-agent
  6. [root@WEB-A2 zabbix-2.2.8]# make && make install
  7. [root@WEB-A2 zabbix-2.2.8]# mkdir /var/log/zabbix
  8. [root@WEB-A2 zabbix-2.2.8]# chown zabbix.zabbix /var/log/zabbix/
  9. [root@WEB-A2 zabbix-2.2.8]# cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
  10. [root@WEB-A2 zabbix-2.2.8]# chmod 755 /etc/init.d/zabbix_agentd
  11. sed -i 's#BASEDIR=/usr/local#BASEDIR=/application/zabbix/#g' /etc/init.d/zabbix_agentd
  12. [root@WEB-A2 zabbix-2.2.8]# vim /etc/services
  13. #增加下面的内容,然后保存并退出:
  14. #Zabbix
  15. zabbix-agent 10050/tcp # Zabbix Agent
  16. zabbix-agent 10050/udp # Zabbix Agent
  17. zabbix-trapper 10051/tcp # Zabbix Trapper
  18. zabbix-trapper 10051/udp # Zabbix Trapper
  19. [root@WEB-A2 zabbix-2.2.8]# vim /etc/zabbix/zabbix_agent.conf
  20. Server=127.0.0.1,172.16.1.33 #将监控服务端的地址加上。
  21. UnsafeUserParameters=1
  22. ------------------
  23. #启动服务:
  24. [root@WEB-A2 ~]# chkconfig zabbix_agentd on
  25. [root@WEB-A2 ~]# /etc/init.d/zabbix_agentd start
  26. Starting zabbix_agentd: [ OK ]

3. Test

Zabbix-Get是监控系统中的一个程序,用于服务端(Zabbix-Server)到客户端(Zabbix-Agent)的数据获取,通常可以用来检测验证客户端的配置是否正确。用法如下:

zabbix_get [-hV] -s <hostname or IP> [-p <port>] [-I <IP Address>] -k <key>
  1. #在监控服务端执行下面的指令:
  2. [root@Zabbix ~]# zabbix_get -s 127.0.0.1 -k system.uname #获取服务端本地的信息。
  3. Linux Zabbix 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64
  4. #获取远程客户端的信息:
  5. [root@Zabbix ~]# zabbix_get -s 172.16.1.12 -k system.uname
  6. #显示空行,目前还未找到原因。

三、配置站点

  1. [root@Zabbix ~]# cp -r tools/zabbix-2.4.5/frontends/php/ /usr/share/nginx/html/zabbix
  2. [root@Zabbix ~]# chown nginx.nginx -R /usr/share/nginx/html/zabbix
  3. #启动服务端及客户端:
  4. [root@Zabbix ~]# /etc/init.d/zabbix_server start
  5. [root@Zabbix ~]# /etc/init.d/zabbix_agentd start
  6. # Check:
  7. [root@Zabbix ~]# netstat -lntp|grep zabbix
  8. tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 16727/zabbix_agentd
  9. tcp 0 0 127.0.0.1:10051 0.0.0.0:* LISTEN 16651/zabbix_server

还需要修改PHP配置文件参数:

  1. [root@Zabbix ~]# vim /etc/php.ini
  2. post_max_size =16M
  3. max_execution_time =300
  4. max_input_time =300
  5. date.timezone = Asia/Shanghai
  6. #[root@Zabbix ~]# vim /etc/php-fpm.conf
  7. #request_terminate_timeout = 300
  8. [root@Zabbix ~]# /etc/init.d/php-fpm restart

最后就是对虚拟主机的配置,请参见相关文档,这里予以省略。

排错

在安装过程中首先是时区的错误:

  1. PHP time zone unknown Fail
  2. -----------------------
  3. #首先如上所述,要确保“php.ini”文件中的时区配置正确。
  4. [root@Zabbix ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  5. #Restart php-fpm:
  6. [root@Zabbix ~]# pkill php-fpm
  7. [root@Zabbix ~]# killall -9 php-fpm
  8. [root@Zabbix ~]# /application/php/sbin/php-fpm

完成安装并登录到监控页面后顶部出现了如下错误提示:
Zabbix server is not running:the information displayed may not be current.

  1. [root@Zabbix ~]# tail -f /tmp/zabbix_server.log
  2. #日志中会出现下面的错误信息:
  3. 30780:20150304:135512.179 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect tolocal MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
  4. 30780:20150304:135512.181 Database is down. Reconnecting in 10 seconds.
  5. -----------------------
  6. [root@Zabbix ~]# mkdir /var/lib/mysql
  7. [root@Zabbix ~]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
  8. #然后重启服务,问题解决。
  9. [root@Zabbix ~]# /etc/init.d/zabbix_agentd restart
  10. [root@Zabbix ~]# /etc/init.d/zabbix_server restart

修改字体:

  1. ######修改字体
  2. ###从windows本地上传字体“微软雅黑”至
  3. /var/www/html/zabbix/fonts
  4. vi /var/www/html/zabbix/include/defines.inc.php
  5. #把默认字体,改成上传的字体
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注