zabbix3.0安裝【server】

關於zabbix的介紹,就很少說了,功能強大,架構前衛,本身直接去官網研究php

 

在這裏,仍是秉承研究一個應用或者技術,都要本身動手安裝部署,實戰操做,才能深刻掌握,基於這個精神,zabbix從安裝部署開始。html

 

我這裏介紹的是基於Linux(CentOS6.8)+MySQL+Zabbix+Nginx的方案。java

 

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

2. 解壓並配置數據庫linux

   前提是,數據庫已經安裝。本操做案例中,數據庫MySQL5.6的安裝過程,請參照以前的博客CentOS 6.8下安裝MySQL 5.6.33nginx

   登陸MySQL,並建立zabbix數據庫。web

1 mysql> create database zabbix character set utf8; 

   建立zabbix用戶並受權sql

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

導入完畢後,能夠看到有以下的表:express

  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的版本差異很大,對,沒錯,我這裏的頁面加載,樣式都丟了,圖片也顯示不出來,這個問題,下一個博文再介紹吧。

這個安裝介紹,就到此,如須要,請轉載,轉載請標記出處。

相關文章
相關標籤/搜索