zabbix3.0安装【server】

关于zabbix的介绍,就不多说了,功能强大,架构前卫,自己直接去官网研究

在这里,还是秉承研究一个应用或者技术,都要自己动手安装部署,实战操作,才能深入掌握,基于这个精神,zabbix从安装部署开始。

我这里介绍的是基于Linux(CentOS6.8)+MySQL+Zabbix+Nginx的方案。

1. 下载源码,地址 http://pkgs.fedoraproject.org/repo/pkgs/zabbix/zabbix-3.0.1.tar.gz/890d9eec69304ad552959fabe0a5d122/zabbix-3.0.1.tar.gz

2. 解压并配置数据库

   前提是,数据库已经安装。本操作案例中,数据库MySQL5.6的安装过程,请参照之前的博客CentOS 6.8下安装MySQL 5.6.33

   登录MySQL,并创建zabbix数据库。

1 mysql> create database zabbix character set utf8; 

   创建zabbix用户并授权

1  mysql> create user 'zabbix'@'%' identified by 'zabbix';
2  mysql> grant all on zabbix.* to 'zabbix'@'%' identified by 'zabbix';

  将zabbix的数据库导入mysql (schema.sql, images.sql, data.sql,注意一定要按照这个顺序进行,否则可能会出现错误)

1 mysql> source /home/water/Downloads/zabbix-3.0.1/database/mysql/schema.sql
2 mysql> source /home/water/Downloads/zabbix-3.0.1/database/mysql/images.sql
3 mysql> source /home/water/Downloads/zabbix-3.0.1/database/mysql/data.sql

导入完毕后,可以看到有如下的表:

  1 mysql> show tables;
  2 +----------------------------+
  3 | Tables_in_zabbix           |
  4 +----------------------------+
  5 | acknowledges               |
  6 | actions                    |
  7 | alerts                     |
  8 | application_discovery      |
  9 | application_prototype      |
 10 | application_template       |
 11 | applications               |
 12 | auditlog                   |
 13 | auditlog_details           |
 14 | autoreg_host               |
 15 | conditions                 |
 16 | config                     |
 17 | dbversion                  |
 18 | dchecks                    |
 19 | dhosts                     |
 20 | drules                     |
 21 | dservices                  |
 22 | escalations                |
 23 | events                     |
 24 | expressions                |
 25 | functions                  |
 26 | globalmacro                |
 27 | globalvars                 |
 28 | graph_discovery            |
 29 | graph_theme                |
 30 | graphs                     |
 31 | graphs_items               |
 32 | group_discovery            |
 33 | group_prototype            |
 34 | groups                     |
 35 | history                    |
 36 | history_log                |
 37 | history_str                |
 38 | history_text               |
 39 | history_uint               |
 40 | host_discovery             |
 41 | host_inventory             |
 42 | hostmacro                  |
 43 | hosts                      |
 44 | hosts_groups               |
 45 | hosts_templates            |
 46 | housekeeper                |
 47 | httpstep                   |
 48 | httpstepitem               |
 49 | httptest                   |
 50 | httptestitem               |
 51 | icon_map                   |
 52 | icon_mapping               |
 53 | ids                        |
 54 | images                     |
 55 | interface                  |
 56 | interface_discovery        |
 57 | item_application_prototype |
 58 | item_condition             |
 59 | item_discovery             |
 60 | items                      |
 61 | items_applications         |
 62 | maintenances               |
 63 | maintenances_groups        |
 64 | maintenances_hosts         |
 65 | maintenances_windows       |
 66 | mappings                   |
 67 | media                      |
 68 | media_type                 |
 69 | opcommand                  |
 70 | opcommand_grp              |
 71 | opcommand_hst              |
 72 | opconditions               |
 73 | operations                 |
 74 | opgroup                    |
 75 | opinventory                |
 76 | opmessage                  |
 77 | opmessage_grp              |
 78 | opmessage_usr              |
 79 | optemplate                 |
 80 | profiles                   |
 81 | proxy_autoreg_host         |
 82 | proxy_dhistory             |
 83 | proxy_history              |
 84 | regexps                    |
 85 | rights                     |
 86 | screen_user                |
 87 | screen_usrgrp              |
 88 | screens                    |
 89 | screens_items              |
 90 | scripts                    |
 91 | service_alarms             |
 92 | services                   |
 93 | services_links             |
 94 | services_times             |
 95 | sessions                   |
 96 | slides                     |
 97 | slideshow_user             |
 98 | slideshow_usrgrp           |
 99 | slideshows                 |
100 | sysmap_element_url         |
101 | sysmap_url                 |
102 | sysmap_user                |
103 | sysmap_usrgrp              |
104 | sysmaps                    |
105 | sysmaps_elements           |
106 | sysmaps_link_triggers      |
107 | sysmaps_links              |
108 | timeperiods                |
109 | trends                     |
110 | trends_uint                |
111 | trigger_depends            |
112 | trigger_discovery          |
113 | triggers                   |
114 | users                      |
115 | users_groups               |
116 | usrgrp                     |
117 | valuemaps                  |
118 +----------------------------+
119 113 rows in set (0.01 sec)
View Code

3. 创建linux的用户zabbix

1 [root@CloudGame zabbix-3.0.1]# groupadd zabbix
2 [root@CloudGame zabbix-3.0.1]# useradd zabbix -g zabbix -s /bin/false

4. 安装依赖包

1 [root@CloudGame zabbix-3.0.1]# yum install net-snmp-devel -y
2 [root@CloudGame zabbix-3.0.1]# yum install curl curl-devel -y
3 
4 [root@CloudGame MySQL-5.6.33]# rpm -ivh MySQL-devel-5.6.33-1.linux_glibc2.5.x86_64.rpm
5 warning: MySQL-devel-5.6.33-1.linux_glibc2.5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
6 Preparing...                ########################################### [100%]
7    1:MySQL-devel            ########################################### [100%]

注意,只有MySQL-devel的包安装了,系统才会有mysql_config命令,这个命令在/usr/bin/mysql_config下。

5. 配置zabbix,并安装

1 [root@CloudGame zabbix-3.0.1]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-net-snmp --with-libcurl --enable-proxy --with-mysql=/usr/bin/mysql_config

遗憾的是,执行这个爆出了错误:

 1 ...........
 2 checking for -rdynamic linking option... yes
 3 checking for libperfstat 5.2.0.40 fileset... no
 4 checking for libperfstat 5.3.0.60 fileset... no
 5 checking for architecture... linux (linux-gnu)
 6 checking for the linux kernel version... 2.6 family (2.6.32-642.6.1.el6.x86_64)
 7 checking size of void *... 8
 8 checking for mysql_config... /usr/bin/mysql_config
 9 checking for main in -lmysqlclient... no
10 configure: error: Not found mysqlclient library

什么错误?
查看安装的mysql相关的包:

1 [root@CloudGame MySQL-5.6.33]# /usr/bin/mysql_config --libs
2 -L/usr/lib64 -lmysqlclient -lpthread -lm -lrt -ldl

这个显示这个mysqlclient的包在啊。。
国外的网站上看到一个类似的问题,说是要将mysql-shared的rpm包装上,即可解决问题。于是:

1 [root@CloudGame MySQL-5.6.33]# rpm -ivh MySQL-shared-5.6.33-1.linux_glibc2.5.x86_64.rpm
2 warning: MySQL-shared-5.6.33-1.linux_glibc2.5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
3 Preparing...                ########################################### [100%]
4    1:MySQL-shared           ########################################### [100%]

再次configure命令,问题解决了:

 1 config.status: creating src/zabbix_proxy/heart/Makefile
 2 config.status: creating src/zabbix_proxy/housekeeper/Makefile
 3 config.status: creating src/zabbix_proxy/proxyconfig/Makefile
 4 config.status: creating src/zabbix_proxy/datasender/Makefile
 5 config.status: creating src/zabbix_java/Makefile
 6 config.status: creating upgrades/Makefile
 7 config.status: creating man/Makefile
 8 config.status: creating include/config.h
 9 config.status: executing depfiles commands
10 
11 
12 Configuration:
13 
14   Detected OS:           linux-gnu
15   Install path:          /usr/local/zabbix
16   Compilation arch:      linux
17 
18   Compiler:              gcc
19   Compiler flags:        -g -O2     -I/usr/include/rpm -I/usr/local/include -I/usr/lib64/perl5/CORE -I. -I/usr/include      
20 
21   Enable server:         yes
22   Server details:
23     With database:         MySQL
24     WEB Monitoring:        cURL
25     Native Jabber:         no
26     SNMP:                  yes
27     IPMI:                  no
28     SSH:                   no
29     TLS:                   no
30     ODBC:                  no
31     Linker flags:          -rdynamic      -L/usr/lib64        -L/usr/lib64     
32     Libraries:             -lm -ldl -lrt  -lresolv -liconv   -lmysqlclient         -lnetsnmp      -lcurl
33 
34   Enable proxy:          yes
35   Proxy details:
36     With database:         MySQL
37     WEB Monitoring:        cURL
38     SNMP:                  yes
39     IPMI:                  no
40     SSH:                   no
41     TLS:                   no
42     ODBC:                  no
43     Linker flags:          -rdynamic      -L/usr/lib64       -L/usr/lib64     
44     Libraries:             -lm -ldl -lrt  -lresolv -liconv   -lmysqlclient        -lnetsnmp      -lcurl
45 
46   Enable agent:          yes
47   Agent details:
48     TLS:                   no
49     Linker flags:          -rdynamic      
50     Libraries:             -lm -ldl -lrt  -lresolv -liconv     -lcurl
51 
52   Enable Java gateway:   no
53 
54   LDAP support:          no
55   IPv6 support:          no
56 
57 ***********************************************************
58 *            Now run 'make install'                       *
59 *                                                         *
60 *            Thank you for using Zabbix!                  *
61 *              <http://www.zabbix.com>                    *
62 ***********************************************************

接着执行make install,这步没有问题,直接ok。

6. 配置网络服务信息/etc/services,在文件最末尾添加下面的内容:

1 iqobject        48619/tcp               # iqobject
2 iqobject        48619/udp               # iqobject
3 
4 #zabbix added by shihuc 2016-11-17
5 zabbix-agent    10050/tcp               # zabbix agent
6 zabbix-agent    10050/udp               # zabbix agent
7 zabbix-trapper  10051/tcp               # zabbix trapper
8 zabbix-trapper  10051/udp               # zabbix trapper

7. 配置/usr/local/zabbix/etc/zabbix_server.conf

1 DBName=zabbix #数据库名称
2 
3 DBUser=zabbix #数据库用户名
4 
5 DBPassword=zabbix #数据库密码
6 
7 ListenIP=127.0.0.1 #数据库ip地址
8 
9 AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts #zabbix运行脚本存放目录

上面的红色部分,要小心,若是配置成了localhost,将会遇到下面的错误,在启动zabbix_server的时候,起不来。

 1   5948:20161118:111435.238 Starting Zabbix Server. Zabbix 3.0.1 (revision 58734).
 2   5948:20161118:111435.238 ****** Enabled features ******
 3   5948:20161118:111435.238 SNMP monitoring:           YES
 4   5948:20161118:111435.238 IPMI monitoring:            NO
 5   5948:20161118:111435.238 Web monitoring:            YES
 6   5948:20161118:111435.238 VMware monitoring:          NO
 7   5948:20161118:111435.238 SMTP authentication:        NO
 8   5948:20161118:111435.238 Jabber notifications:       NO
 9   5948:20161118:111435.238 Ez Texting notifications:  YES
10   5948:20161118:111435.238 ODBC:                       NO
11   5948:20161118:111435.238 SSH2 support:               NO
12   5948:20161118:111435.239 IPv6 support:               NO
13   5948:20161118:111435.239 TLS support:                NO
14   5948:20161118:111435.239 ******************************
15   5948:20161118:111435.239 using configuration file: /usr/local/zabbix/etc/zabbix_server.conf
16   5948:20161118:111435.251 current database version (mandatory/optional): 03000000/03000000
17   5948:20161118:111435.251 required mandatory version: 03000000
18   5948:20161118:111435.254 listener failed: incorrect IPv4 address [localhost]

8. 配置agentd, /usr/local/zabbix/etc/zabbix_agentd.conf

1 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
2 
3 UnsafeUserParameters=1 #启用自定义key

9. 配置zabbix_server, zabbix_agentd的开机启动项

1 [root@CloudGame init.d]# pwd
2 /home/water/Downloads/zabbix-3.0.1/misc/init.d
3 [root@CloudGame init.d]# cp fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server
4 [root@CloudGame init.d]# cp fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd

到此,还有一点需要注意,就是zabbix_server以及zabbix_agentd的BASEDIR路径。修改zabbix_server启动脚本参数,主要是zabbix的安装路径信息,默认是下面的样子:

1 [root@CloudGame init.d]# vim /etc/rc.d/init.d/zabbix_server
2 # Variables
3 # Edit these to match your system settings
4 
5         # Zabbix-Directory
6         BASEDIR=/usr/local

根据自己zabbix的安装路径,修改BASEDIR,我的是在/usr/local/zabbix,所以修改后是这个样子:BASEDIR修改为BASEDIR=/usr/local/zabbix

同理,zabbix_agentd一样的修改这个地址。

10. 配置web,我这里是基于nginx,并非官方描述的Apache。(nginx的安装也非常简单,我这里的版本是1.10.2,这里不介绍)

1 [root@CloudGame frontends]# pwd
2 /home/water/Downloads/zabbix-3.0.1/frontends
3 [root@CloudGame frontends]# cp -rf php /usr/local/nginx/html/zabbix
4 [root@CloudGame frontends]# chown www.www -R /usr/local/nginx/html/zabbix
5 chown: invalid user: `www.www'
6 [root@CloudGame frontends]# groupadd www
7 [root@CloudGame frontends]# useradd www -g www -s /bin/false
8 [root@CloudGame frontends]# 
9 [root@CloudGame frontends]# chown www.www -R /usr/local/nginx/html/zabbix

11. 启动服务

1 [root@CloudGame sbin]# service zabbix_server start
2 Starting zabbix_server:                                    [  OK  ]
3 [root@CloudGame sbin]# 
4 [root@CloudGame sbin]# service zabbix_agentd start
5 Starting zabbix_agentd:  zabbix_agentd [5291]: /usr/local/etc/zabbix_agentd.conf.d: [2] No such file or directory
6                                                            [FAILED]

这个是什么意思?居然还报错了。。。检测配置文件/usr/local/zabbix/etc/zabbix_agentd.conf以及zabbix_agentd_conf.d所在的路径,发现路径不对,少了以及zabbix,正确的应该是:/usr/local/zabbix/etc/zabbix_agentd.conf.d/ 再次启动:

1 [root@CloudGame zabbix_agentd.conf.d]# service zabbix_agentd start
2 Starting zabbix_agentd:                                    [  OK  ]

12. 配置php环境。

因为zabbix的web部分是php实现的,需要php运行环境,我这里没有用Apache,而是nginx,所以,需要php-fpm这个FastCGI。

1 [root@CloudGame ~]# yum install php-fpm

这里,我的系统默认安装的是php5.3.3,这个为后面埋下了雷,后面会说到!

修改/etc/php.ini

1 post_max_size =16M
2 
3 max_execution_time =300
4 
5 max_input_time =300

启动php-fpm:

1 [root@CloudGame ~]# service php-fpm start
2 Starting php-fpm:                                          [  OK  ]

13. 检查安装效果

在浏览器输入http://localhost/setup.php,浏览器一直显示“File not found

鬼的很啊,什么问题,我对php一点经验没有,在国外的站上看到相关说法,很可能是我的php安装有点问题,前面我只是安装了php-fpm,我再安装一下php,以及php-fpm。

1 [root@CloudGame etc]# yum install php
2 [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 30

有这么一个警告,修改比较简单,在/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.10-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
    file /usr/bin/phar.phar from install of php55-cli-5.5.10-1.el6.x86_64 conflicts with file from package php-cli-5.3.3-48.el6_8.x86_64
    file /usr/bin/php from install of php55-cli-5.5.10-1.el6.x86_64 conflicts with file from package php-cli-5.3.3-48.el6_8.x86_64
    file /usr/bin/php-cgi from install of php55-cli-5.5.10-1.el6.x86_64 conflicts with file from package php-cli-5.3.3-48.el6_8.x86_64
    file /usr/share/man/man1/php.1.gz from install of php55-cli-5.5.10-1.el6.x86_64 conflicts with file from package php-cli-5.3.3-48.el6_8.x86_64
[root@CloudGame Downloads]# rpm -ivh php55-cli-5.5.10-1.el6.x86_64.rpm --replacefiles
Preparing...                ########################################### [100%]
   1:php55-cli              ########################################### [100%]
[root@CloudGame Downloads]# 
[root@CloudGame Downloads]# rpm -ivh php55-5.5.10-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:php55                  ########################################### [100%]
[root@CloudGame Downloads]# rpm -ivh php55-devel-5.5.10-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:php55-devel            ########################################### [100%]
[root@CloudGame Downloads]# rpm -ivh php55-mysql-5.5.10-1.el6.x86_64.rpm
error: Failed dependencies:
    php55-pdo(x86-64) is needed by php55-mysql-5.5.10-1.el6.x86_64
[root@CloudGame Downloads]# rpm -ivh php55-pdo-5.5.10-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:php55-pdo              ########################################### [100%]
[root@CloudGame Downloads]# rpm -ivh php55-mysql-5.5.10-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:php55-mysql            ########################################### [100%]
[root@CloudGame Downloads]# rpm -ivh php55-xmlrpc-5.5.10-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:php55-xmlrpc           ########################################### [100%]
[root@CloudGame Downloads]# rpm -ivh php55-fpm-5.5.10-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:php55-fpm              ########################################### [100%]
[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.10-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:php55-bcmath           ########################################### [100%]
[root@CloudGame Downloads]# rpm -ivh php55-mbstring-5.5.10-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:php55-mbstring         ########################################### [100%]
[root@CloudGame Downloads]# rpm -ivh php55-gd-5.5.10-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:php55-gd               ########################################### [100%]
[root@CloudGame Downloads]# rpm -ivh php55-xml-5.5.10-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:php55-xml              ########################################### [100%]
[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,网上好多修改下面内容的地址说的有问题或者不详细,根本找不到文件。。。

1 user=www
2 group=www
3 request_terminate_timeout = 300

然后,在数据库验证的地方,将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的版本差别很大,对,没错,我这里的页面加载,样式都丢了,图片也显示不出来,这个问题,下一个博文再介绍吧。

这个安装介绍,就到此,如需要,请转载,转载请标记出处。

原文地址:https://www.cnblogs.com/shihuc/p/6078285.html