关于zabbix的介绍,就不多说了,功能强大,架构前卫,自己直接去官网研究
在这里,还是秉承研究一个应用或者技术,都要自己动手安装部署,实战操作,才能深入掌握,基于这个精神,zabbix从安装部署开始。
我这里介绍的是基于Linux(CentOS6.8)+MySQL+Zabbix+Nginx的方案。
2. 解压并配置数据库
前提是,数据库已经安装。本操作案例中,数据库MySQL5.6的安装过程,请参照之前的博客CentOS 6.8下安装MySQL 5.6.33。
登录MySQL,并创建zabbix数据库。
mysql> create database zabbix character set utf8;
创建zabbix用户并授权
mysql> create user 'zabbix'@'%' identified by 'zabbix';
mysql> grant all on zabbix.* to 'zabbix'@'%' identified by 'zabbix';
将zabbix的数据库导入mysql (schema.sql, images.sql, data.sql,注意一定要按照这个顺序进行,否则可能会出现错误)
mysql> source /home/water/Downloads/zabbix-3.0./database/mysql/schema.sql
mysql> source /home/water/Downloads/zabbix-3.0./database/mysql/images.sql
mysql> source /home/water/Downloads/zabbix-3.0./database/mysql/data.sql
导入完毕后,可以看到有如下的表:
mysql> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
| conditions |
| config |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| events |
| expressions |
| functions |
| globalmacro |
| globalvars |
| graph_discovery |
| graph_theme |
| graphs |
| graphs_items |
| group_discovery |
| group_prototype |
| groups |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| httpstep |
| httpstepitem |
| httptest |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| item_application_prototype |
| item_condition |
| item_discovery |
| items |
| items_applications |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows |
| mappings |
| media |
| media_type |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opinventory |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| profiles |
| proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| rights |
| screen_user |
| screen_usrgrp |
| screens |
| screens_items |
| scripts |
| service_alarms |
| services |
| services_links |
| services_times |
| sessions |
| slides |
| slideshow_user |
| slideshow_usrgrp |
| slideshows |
| sysmap_element_url |
| sysmap_url |
| sysmap_user |
| sysmap_usrgrp |
| sysmaps |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| timeperiods |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemaps |
+----------------------------+
rows in set (0.01 sec)
3. 创建linux的用户zabbix
[root@CloudGame zabbix-3.0.]# groupadd zabbix
[root@CloudGame zabbix-3.0.]# useradd zabbix -g zabbix -s /bin/false
4. 安装依赖包
[root@CloudGame zabbix-3.0.]# yum install net-snmp-devel -y
[root@CloudGame zabbix-3.0.]# yum install curl curl-devel -y [root@CloudGame MySQL-5.6.]# rpm -ivh MySQL-devel-5.6.-.linux_glibc2..x86_64.rpm
warning: MySQL-devel-5.6.-.linux_glibc2..x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [%]
:MySQL-devel ########################################### [%]
注意,只有MySQL-devel的包安装了,系统才会有mysql_config命令,这个命令在/usr/bin/mysql_config下。
5. 配置zabbix,并安装
[root@CloudGame zabbix-3.0.]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-net-snmp --with-libcurl --enable-proxy --with-mysql=/usr/bin/mysql_config
遗憾的是,执行这个爆出了错误:
...........
checking for -rdynamic linking option... yes
checking for libperfstat 5.2.0.40 fileset... no
checking for libperfstat 5.3.0.60 fileset... no
checking for architecture... linux (linux-gnu)
checking for the linux kernel version... 2.6 family (2.6.-642.6..el6.x86_64)
checking size of void *...
checking for mysql_config... /usr/bin/mysql_config
checking for main in -lmysqlclient... no
configure: error: Not found mysqlclient library
什么错误?
查看安装的mysql相关的包:
[root@CloudGame MySQL-5.6.]# /usr/bin/mysql_config --libs
-L/usr/lib64 -lmysqlclient -lpthread -lm -lrt -ldl
这个显示这个mysqlclient的包在啊。。
在国外的网站上看到一个类似的问题,说是要将mysql-shared的rpm包装上,即可解决问题。于是:
[root@CloudGame MySQL-5.6.]# rpm -ivh MySQL-shared-5.6.-.linux_glibc2..x86_64.rpm
warning: MySQL-shared-5.6.-.linux_glibc2..x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [%]
:MySQL-shared ########################################### [%]
再次configure命令,问题解决了:
config.status: creating src/zabbix_proxy/heart/Makefile
config.status: creating src/zabbix_proxy/housekeeper/Makefile
config.status: creating src/zabbix_proxy/proxyconfig/Makefile
config.status: creating src/zabbix_proxy/datasender/Makefile
config.status: creating src/zabbix_java/Makefile
config.status: creating upgrades/Makefile
config.status: creating man/Makefile
config.status: creating include/config.h
config.status: executing depfiles commands Configuration: Detected OS: linux-gnu
Install path: /usr/local/zabbix
Compilation arch: linux Compiler: gcc
Compiler flags: -g -O2 -I/usr/include/rpm -I/usr/local/include -I/usr/lib64/perl5/CORE -I. -I/usr/include Enable server: yes
Server details:
With database: MySQL
WEB Monitoring: cURL
Native Jabber: no
SNMP: yes
IPMI: no
SSH: no
TLS: no
ODBC: no
Linker flags: -rdynamic -L/usr/lib64 -L/usr/lib64
Libraries: -lm -ldl -lrt -lresolv -liconv -lmysqlclient -lnetsnmp -lcurl Enable proxy: yes
Proxy details:
With database: MySQL
WEB Monitoring: cURL
SNMP: yes
IPMI: no
SSH: no
TLS: no
ODBC: no
Linker flags: -rdynamic -L/usr/lib64 -L/usr/lib64
Libraries: -lm -ldl -lrt -lresolv -liconv -lmysqlclient -lnetsnmp -lcurl Enable agent: yes
Agent details:
TLS: no
Linker flags: -rdynamic
Libraries: -lm -ldl -lrt -lresolv -liconv -lcurl Enable Java gateway: no LDAP support: no
IPv6 support: no ***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
接着执行make install,这步没有问题,直接ok。
6. 配置网络服务信息/etc/services,在文件最末尾添加下面的内容:
iqobject /tcp # iqobject
iqobject /udp # iqobject #zabbix added by shihuc --
zabbix-agent 10050/tcp # zabbix agent
zabbix-agent 10050/udp # zabbix agent
zabbix-trapper 10051/tcp # zabbix trapper
zabbix-trapper 10051/udp # zabbix trapper
7. 配置/usr/local/zabbix/etc/zabbix_server.conf
DBName=zabbix #数据库名称 DBUser=zabbix #数据库用户名 DBPassword=zabbix #数据库密码 ListenIP=127.0.0.1 #数据库ip地址
AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts #zabbix运行脚本存放目录
上面的红色部分,要小心,若是配置成了localhost,将会遇到下面的错误,在启动zabbix_server的时候,起不来。
::111435.238 Starting Zabbix Server. Zabbix 3.0. (revision ).
::111435.238 ****** Enabled features ******
::111435.238 SNMP monitoring: YES
::111435.238 IPMI monitoring: NO
::111435.238 Web monitoring: YES
::111435.238 VMware monitoring: NO
::111435.238 SMTP authentication: NO
::111435.238 Jabber notifications: NO
::111435.238 Ez Texting notifications: YES
::111435.238 ODBC: NO
::111435.238 SSH2 support: NO
::111435.239 IPv6 support: NO
::111435.239 TLS support: NO
::111435.239 ******************************
::111435.239 using configuration file: /usr/local/zabbix/etc/zabbix_server.conf
::111435.251 current database version (mandatory/optional): /
::111435.251 required mandatory version:
::111435.254 listener failed: incorrect IPv4 address [localhost]
8. 配置agentd, /usr/local/zabbix/etc/zabbix_agentd.conf
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/ UnsafeUserParameters= #启用自定义key
9. 配置zabbix_server, zabbix_agentd的开机启动项
[root@CloudGame init.d]# pwd
/home/water/Downloads/zabbix-3.0./misc/init.d
[root@CloudGame init.d]# cp fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server
[root@CloudGame init.d]# cp fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
到此,还有一点需要注意,就是zabbix_server以及zabbix_agentd的BASEDIR路径。修改zabbix_server启动脚本参数,主要是zabbix的安装路径信息,默认是下面的样子:
[root@CloudGame init.d]# vim /etc/rc.d/init.d/zabbix_server
# Variables
# Edit these to match your system settings # Zabbix-Directory
BASEDIR=/usr/local
根据自己zabbix的安装路径,修改BASEDIR,我的是在/usr/local/zabbix,所以修改后是这个样子:BASEDIR修改为BASEDIR=/usr/local/zabbix
同理,zabbix_agentd一样的修改这个地址。
10. 配置web,我这里是基于nginx,并非官方描述的Apache。(nginx的安装也非常简单,我这里的版本是1.10.2,这里不介绍)
[root@CloudGame frontends]# pwd
/home/water/Downloads/zabbix-3.0./frontends
[root@CloudGame frontends]# cp -rf php /usr/local/nginx/html/zabbix
[root@CloudGame frontends]# chown www.www -R /usr/local/nginx/html/zabbix
chown: invalid user: `www.www'
[root@CloudGame frontends]# groupadd www
[root@CloudGame frontends]# useradd www -g www -s /bin/false
[root@CloudGame frontends]#
[root@CloudGame frontends]# chown www.www -R /usr/local/nginx/html/zabbix
11. 启动服务
[root@CloudGame sbin]# service zabbix_server start
Starting zabbix_server: [ OK ]
[root@CloudGame sbin]#
[root@CloudGame sbin]# service zabbix_agentd start
Starting zabbix_agentd: zabbix_agentd []: /usr/local/etc/zabbix_agentd.conf.d: [] No such file or directory
[FAILED]
这个是什么意思?居然还报错了。。。检测配置文件/usr/local/zabbix/etc/zabbix_agentd.conf以及zabbix_agentd_conf.d所在的路径,发现路径不对,少了以及zabbix,正确的应该是:/usr/local/zabbix/etc/zabbix_agentd.conf.d/ 再次启动:
[root@CloudGame zabbix_agentd.conf.d]# service zabbix_agentd start
Starting zabbix_agentd: [ OK ]
12. 配置php环境。
因为zabbix的web部分是php实现的,需要php运行环境,我这里没有用Apache,而是nginx,所以,需要php-fpm这个FastCGI。
[root@CloudGame ~]# yum install php-fpm
这里,我的系统默认安装的是php5.3.3,这个为后面埋下了雷,后面会说到!
修改/etc/php.ini
post_max_size =16M max_execution_time = max_input_time =
启动php-fpm:
[root@CloudGame ~]# service php-fpm start
Starting php-fpm: [ OK ]
13. 检查安装效果
在浏览器输入http://localhost/setup.php,浏览器一直显示“File not found”
鬼的很啊,什么问题,我对php一点经验没有,在国外的站上看到相关说法,很可能是我的php安装有点问题,前面我只是安装了php-fpm,我再安装一下php,以及php-fpm。
[root@CloudGame etc]# yum install php
[root@CloudGame etc]# yum install php-fpm
再次刷新页面http://localhost/setup.php,有内容了,不再出现“File not found”.
启动可以了,基于nginx启动php页面可以了,php脚本文件通过php-fpm这个FastCGI进行解析。
Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Hong_Kong' for 'HKT/8.0/no DST' instead in /usr/local/nginx/html/zabbix/index.php on line 29 Parse error: syntax error, unexpected '[' in /usr/local/nginx/html/zabbix/setup.php on line
有这么一个警告,修改比较简单,在/etc/php.ini下修改时区。
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = PRC
再次打开页面,发现还是有错误
Parse error: syntax error, unexpected '[' in /usr/local/nginx/html/zabbix/setup.php on line 30
纠结半天,原来是说php的版本太低了,必须大于5.4。。。
于是安装php高于5.3的版本,下载一个5.5的rpm包
在这里下载https://oss.oracle.com/projects/php/files/EL6/x86_64/
为了测试zabbix的安装流程,主要安装下面几个:
[root@CloudGame Downloads]# rpm -ivh php55-cli-5.5.-.el6.x86_64.rpm
Preparing... ########################################### [%]
file /usr/bin/phar.phar from install of php55-cli-5.5.-.el6.x86_64 conflicts with file from package php-cli-5.3.-.el6_8.x86_64
file /usr/bin/php from install of php55-cli-5.5.-.el6.x86_64 conflicts with file from package php-cli-5.3.-.el6_8.x86_64
file /usr/bin/php-cgi from install of php55-cli-5.5.-.el6.x86_64 conflicts with file from package php-cli-5.3.-.el6_8.x86_64
file /usr/share/man/man1/php..gz from install of php55-cli-5.5.-.el6.x86_64 conflicts with file from package php-cli-5.3.-.el6_8.x86_64
[root@CloudGame Downloads]# rpm -ivh php55-cli-5.5.-.el6.x86_64.rpm --replacefiles
Preparing... ########################################### [%]
:php55-cli ########################################### [%]
[root@CloudGame Downloads]#
[root@CloudGame Downloads]# rpm -ivh php55-5.5.-.el6.x86_64.rpm
Preparing... ########################################### [%]
:php55 ########################################### [%]
[root@CloudGame Downloads]# rpm -ivh php55-devel-5.5.-.el6.x86_64.rpm
Preparing... ########################################### [%]
:php55-devel ########################################### [%]
[root@CloudGame Downloads]# rpm -ivh php55-mysql-5.5.-.el6.x86_64.rpm
error: Failed dependencies:
php55-pdo(x86-) is needed by php55-mysql-5.5.-.el6.x86_64
[root@CloudGame Downloads]# rpm -ivh php55-pdo-5.5.-.el6.x86_64.rpm
Preparing... ########################################### [%]
:php55-pdo ########################################### [%]
[root@CloudGame Downloads]# rpm -ivh php55-mysql-5.5.-.el6.x86_64.rpm
Preparing... ########################################### [%]
:php55-mysql ########################################### [%]
[root@CloudGame Downloads]# rpm -ivh php55-xmlrpc-5.5.-.el6.x86_64.rpm
Preparing... ########################################### [%]
:php55-xmlrpc ########################################### [%]
[root@CloudGame Downloads]# rpm -ivh php55-fpm-5.5.-.el6.x86_64.rpm
Preparing... ########################################### [%]
:php55-fpm ########################################### [%]
[root@CloudGame etc]# service php-fpm start
Starting php-fpm: [ OK ]
注意,这里我没有修改php.ini以及php-fpm.conf的内容,还是沿用前面5.3安装配置的信息。
再次在浏览器输入http://localhost/setup.php
现在终于解决了前面提到‘[’语法错误了。
点击next step的时候,发现,还有好多是fail的:
按照提示信息,修改/etc/php.ini的配置文件,重启php-fpm后,刷新浏览器得到下图:
剩下的问题呢?这个不是配置参数的问题了,是PHP运行环境,相关插件没有安装,安装标记Fail的内容,去PHP安装路径下找相关的rpm进行安装,都有哪些插件呢:
选择缺少的插件安装吧:
[root@CloudGame Downloads]# rpm -ivh php55-bcmath-5.5.-.el6.x86_64.rpm
Preparing... ########################################### [%]
:php55-bcmath ########################################### [%]
[root@CloudGame Downloads]# rpm -ivh php55-mbstring-5.5.-.el6.x86_64.rpm
Preparing... ########################################### [%]
:php55-mbstring ########################################### [%]
[root@CloudGame Downloads]# rpm -ivh php55-gd-5.5.-.el6.x86_64.rpm
Preparing... ########################################### [%]
:php55-gd ########################################### [%]
[root@CloudGame Downloads]# rpm -ivh php55-xml-5.5.-.el6.x86_64.rpm
Preparing... ########################################### [%]
:php55-xml ########################################### [%]
[root@CloudGame Downloads]# service php-fpm restart
Stopping php-fpm: [ OK ]
Starting php-fpm: [ OK ]
再次刷新页面,嗯,都好了。
14. 在浏览器中,根据setup.php的引导进行配置zabbix
上一步中,所有的选项检查都ok后,可以点击next step,到了数据库配置项,又遇到了问题:Error connecting to database: No such file or directory
查找了很多国外论坛,找到了解决问题的tip:
修改/etc/php.ini
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
; http://php.net/mysql.default-socket
mysql.default_socket = /var/lib/mysql/mysql.sock
同时,修改/etc/php-fpm.d/www.conf,网上好多修改下面内容的地址说的有问题或者不详细,根本找不到文件。。。
user=www
group=www
request_terminate_timeout =
然后,在数据库验证的地方,将Database Host的localhost修改为127.0.0.1后,就可以了。
还有一点很重要,遇到Error connecting to database: Permission denied
这个错误的时候,估计很多人会郁闷很久吧,因为这个错误,在查找zabbix直接相关的配置文件,是解决不了问题的,这个是linux系统selinux的原因。将其关掉就可以了。
[root@CloudGame ~]# vim /etc/selinux/config # This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted ~
~
【在调查这个问题的时候,nginx的配置文件,做了修改,给zabbix应用起了另外的一个端口81,之前采用的是80】
最后,点击Next step按钮,会看到下面的内容:
到此,zabbix server的安装配置过程全部结束。
细心的您,是不是发现,我这个安装的截图,怎么这么丑,和官网的以及网上看到的2.x的版本差别很大,对,没错,我这里的页面加载,样式都丢了,图片也显示不出来,这个问题,下一个博文再介绍吧。
这个安装介绍,就到此,如需要,请转载,转载请标记出处。