下载

wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.3.tar.gz
tar xvf zabbix-5.0.3.tar.gz
cd zabbix-5.0.3/

创建帐号

必须使用zabbix用户, 即使root帐号运行,也会自动切换至zabbix用户

For all of the Zabbix daemon processes, an unprivileged user is required. If a Zabbix daemon is started from an unprivileged user account, it will run as that user.

However, if a daemon is started from a 'root' account, it will switch to a 'zabbix' user account, which must be present. To create such a user account (in its own group, “zabbix”),

on a RedHat-based system, run:

groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix

on a Debian-based system, run:

addgroup --system --quiet zabbix
adduser --quiet --system --disabled-login --ingroup zabbix --home /var/lib/zabbix --no-create-home zabbix

简单粗暴的方式是:

groupadd zabbix
useradd -g zabbix zabbix
为什么不给帐号分配文件夹?

Zabbix processes do not need a home directory, which is why we do not recommend creating it. However, if you are using some functionality that requires it (e. g. store MySQL credentials in $HOME/.my.cnf) you are free to create it using the following commands.

zabbix进程不需要home文件夹,如果个别功能需要,比如mysql登录认证配置, 你可以用以下命令创建:

On RedHat-based systems, run:

mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
chown zabbix:zabbix /usr/lib/zabbix

On Debian-based systems, run:

mkdir -m u=rwx,g=rwx,o= -p /var/lib/zabbix
chown zabbix:zabbix /var/lib/zabbix

创建服务端的MySQL数据库

注意编码,必须这个

mysql -uroot -p
create database zabbix character set utf8 collate utf8_bin;
quit;
mysql --database=zabbix -uroot -p < database/mysql/schema.sql
mysql --database=zabbix -uroot -p < database/mysql/images.sql
mysql --database=zabbix -uroot -p < database/mysql/data.sql

# 配置源码项目

分为 server服务,proxy代理,agent客户, 三部分

服务端必须指定唯一一种数据库类型(MySQL, PostgreSQL), 而代理端是否数据库数据库,则视服务端的情况而定

帮助
    ./configure --help

该系统同时是服务端和代理端, 则执行:

To configure the sources for a Zabbix server and agent, you may run something like:

    ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2

该系统是服务端且PostgreSQL数据库, 则执行:

To configure the sources for a Zabbix server (with PostgreSQL etc.), you may run:

    ./configure --enable-server --with-postgresql --with-net-snmp

该系统是代理端且SQLite数据库, 则执行:

To configure the sources for a Zabbix proxy (with SQLite etc.), you may run:

    ./configure --prefix=/usr --enable-proxy --with-net-snmp --with-sqlite3 --with-ssh2

该系统是客户端, 则执行:

To configure the sources for a Zabbix agent, you may run:

    ./configure --enable-agent 

该系统是新版Go语言实现的客户端, 则执行: or, Zabbix agent 2:

    ./configure --enable-agent2

其他注意点:

 - Command-line utilities zabbix_get and zabbix_sender are compiled if --enable-agent option is used.
 - 编译参数 --enable-agent 启用命令行工具 zabbix_get 和 zabbix_sender

 - --with-libcurl and --with-libxml2 configuration options are required for virtual machine monitoring; --with-libcurl is also required for SMTP authentication and web.page.* Zabbix agent items. Note that cURL 7.20.0 or higher is required with the --with-libcurl configuration option.
 - 虚拟机监控, 需要编译参数 --with-libcurl 和--with-libxml2
 - SMTP服务认证, 需要编译参数 --with-libcurl 且cURL版本至少7.20.0
 

 -  Zabbix always compiles with the PCRE library (since version 3.4.0); installing it is not optional. --with-libpcre=[DIR] only allows pointing to a specific base install directory, instead of searching through a number of common places for the libpcre files.
 - 编译时总是依赖PCRE正则表达函数库, 默认使用公共的动态库, 可手动配置目录, 编译参数 --with-libpcre=[DIR]

 - You may use the --enable-static flag to statically link libraries. If you plan to distribute compiled binaries among different servers, you must use this flag to make these binaries work without required libraries. Note that --enable-static does not work in Solaris.
 - 编译参数 --enable-static 启用静态编译, 不依赖动态库, 方便克隆部署至其他机器

 - Using --enable-static option is not recommended when building server. In order to build the server statically you must have a static version of every external library needed. There is no strict check for that in configure script.
 - 编译参数 --enable-static 启用静态编译, 不推荐用于编译服务端, 因为依赖检查脚本还不完善

 - Add optional path to the MySQL configuration file --with-mysql=/<path_to_the_file>/mysql_config to select the desired MySQL client library when there is a need to use one that is not located in the default location. It is useful when there are several versions of MySQL installed or MariaDB installed alongside MySQL on the same system.
 - 如果系统安装不同的数据库版本,比如MySQL和MariaDB共存, 编译参数 --with-mysql=/<path_to_the_file>/mysql_config 手动指定mysql客户端程序的目录

 - Use --with-oracle flag to specify location of the OCI API.
 - 编译参数 --with-oracle 启用OCI接口

 - Go version 1.13 or later is required for compiling Zabbix agent 2. See golang.org for installation instructions.
 - 新版Go语言实现的客户端, Go版本至少1.13

如果./configure命令因为缺少动态库或其他原因而失败, 请查看错误日志config.log;比如缺少libssl, 则错误信息会是:

If ./configure fails due to missing libraries or some other circumstance, please see the config.log file for more details on the error. For example, if libssl is missing, the immediate error message may be misleading:

checking for main in -lmysqlclient... no
configure: error: Not found mysqlclient library
While config.log has a more detailed description:

/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto

./configure --help
`configure' configures Zabbix 5.0.3 to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
-h, --help display this help and exit

  --help=short        display options specific to this package
  --help=recursive    display the short help of all the included packages

-V, --version display version information and exit
-q, --quiet, --silent do not print `checking ...' messages

  --cache-file=FILE   cache test results in FILE [disabled]

-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files

  --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX

                      [/usr/local]

--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX

                      [PREFIX]

By default, `make install' will install all the files in
/usr/local/bin', /usr/local/lib' etc. You can specify
an installation prefix other than /usr/local' using --prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/zabbix]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]

Program names:
--program-prefix=PREFIX prepend PREFIX to installed program names
--program-suffix=SUFFIX append SUFFIX to installed program names
--program-transform-name=PROGRAM run sed PROGRAM on installed program names

System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]

Optional Features:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--enable-silent-rules less verbose build output (undo: "make V=1")
--disable-silent-rules verbose build output (undo: "make V=0")
--enable-dependency-tracking

                      do not reject slow dependency extractors

--disable-dependency-tracking

                      speeds up one-time build

--disable-largefile omit support for large files
--enable-static Build statically linked binaries
--enable-static-libs Build statically linked binaries with selected libs from default folders
--enable-server Turn on build of Zabbix server
--enable-proxy Turn on build of Zabbix proxy
--enable-agent Turn on build of Zabbix agent and client utilities
--enable-agent2 Turn on build of Zabbix agent 2
--enable-java Turn on build of Zabbix Java gateway
--enable-ipv6 Turn on support of IPv6

Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-mysql[=ARG] use MySQL client library [default=no], optionally

                      specify path to mysql_config

--with-oracle[=ARG] use Oracle OCI API from given Oracle home

                      (ARG=path); use existing ORACLE_HOME (ARG=yes);
                      disable Oracle OCI support (ARG=no)

--with-oracle-include[=DIR]

                      use Oracle OCI API headers from given path

--with-oracle-lib[=DIR] use Oracle OCI API libraries from given path
--with-postgresql[=ARG] use PostgreSQL library [default=no], optionally

                      specify path to pg_config

--with-sqlite3[=ARG] use SQLite 3 library [default=no], optionally

                      specify the prefix for sqlite3 library

If you want to use XML library:
--with-libxml2[=ARG] use libxml2 client library [default=no], see

                      PKG_CONFIG_PATH environment variable to specify .pc
                      file location

If you want to use unixODBC library:
--with-unixodbc[=ARG] use ODBC driver against unixODBC package

                      [default=no], optionally specify full path to
                      odbc_config binary.

If you want to use Net-SNMP library:
--with-net-snmp[=ARG] use Net-SNMP package [default=no], optionally

                      specify path to net-snmp-config

If you want to use SSH2 based checks:
--with-ssh2[=DIR] use SSH2 package [default=no], DIR is the SSH2

                      library install directory.

If you want to use SSH based checks:
--with-ssh[=DIR] use SSH package [default=no], DIR is the SSH library

                      install directory.

If you want to check IPMI devices:
--with-openipmi[=DIR] Include OPENIPMI support [default=no]. DIR is the

                      OPENIPMI base install directory, default is to
                      search through a number of common places for the
                      OPENIPMI files.

If you want to specify zlib installation directories:
--with-zlib[=DIR] use zlib from given base install directory (DIR),

                      default is to search through a number of common
                      places for the zlib files.

--with-zlib-include=DIR use zlib include headers from given path.
--with-zlib-lib=DIR use zlib libraries from given path.

If you want to specify pthread installation directories:
--with-libpthread[=DIR] use libpthread from given base install directory

                      (DIR), default is to search through a number of
                      common places for the libpthread files.

--with-libpthread-include[=DIR]

                      use libpthread include headers from given path.

--with-libpthread-lib[=DIR]

                      use libpthread libraries from given path.

If you want to specify libevent installation directories:
--with-libevent[=DIR] use libevent from given base install directory

                      (DIR), default is to search through a number of
                      common places for the libevent files.

--with-libevent-include[=DIR]

                      use libevent include headers from given path.

--with-libevent-lib[=DIR]

                      use libevent libraries from given path.

If you want to use encryption provided by GnuTLS library:
--with-gnutls[=DIR] use GnuTLS package [default=no], DIR is the

                      libgnutls install directory.

If you want to use encryption provided by OpenSSL library:
--with-openssl[=DIR] use OpenSSL package [default=no], DIR is the libssl

                      and libcrypto install directory.

If you want to check LDAP servers:
--with-ldap[=DIR] Include LDAP support [default=no]. DIR is the LDAP

                      base install directory, default is to search through
                      a number of common places for the LDAP files.

If you want to use cURL library:
--with-libcurl[=DIR] use cURL package [default=no], optionally specify

                      path to curl-config

If you want to specify libpcre installation directories:
--with-libpcre[=DIR] use libpcre from given base install directory (DIR),

                      default is to search through a number of common
                      places for the libpcre files.

--with-libpcre-include[=DIR]

                      use libpcre include headers from given path.

--with-libpcre-lib[=DIR]

                      use libpcre libraries from given path.

If you want to specify iconv installation directories:
--with-iconv[=DIR] use iconv from given base install directory (DIR),

                      default is to search through a number of common
                      places for the iconv files.

--with-iconv-include[=DIR]

                      use iconv include headers from given path.

--with-iconv-lib[=DIR] use iconv libraries from given path.

Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a

          nonstandard directory <lib dir>

LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if

          you have headers in a nonstandard directory <include dir>

CPP C preprocessor
PKG_CONFIG path to pkg-config utility
PKG_CONFIG_PATH

          directories to add to pkg-config's search path

PKG_CONFIG_LIBDIR

          path overriding pkg-config's built-in search path

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.


这里, 我们的服务端配置参数是:

此处不使用SNMP, 且注意mysql_config程序的目录,

./configure --prefix=/usr/local/zabbix5 --enable-server --enable-agent --with-mysql=/usr/local/mariadb/bin/mysql_config --enable-ipv6 --with-libcurl --with-libxml2 --with-libpcre --with-zlib --with-iconv

./configure --prefix=/usr/local/zabbix5 --enable-agent


# 编译

如果源码来自Git仓库, 需要执行命令`make dbschema`

make install


后台二进制程序的默认安装目录:

    服务端(zabbix_server, zabbix_agentd, zabbix_proxy) 在 /usr/local/sbin

    客户端(zabbix_get, zabbix_sender) 在 /usr/local/bin.

编译参数 --prefix=/usr/local/zabbix5 可以指定编译目录, 此时后台程序位于相对目录 <prefix>/sbin, 工具程序位于 <prefix>/bin. 而man页面位于 <prefix>/share

# 编辑配置文件

服务端 /usr/local/etc/zabbix_server.conf
    主要是数据库名和密码

代理端服务 /usr/local/etc/zabbix_agentd.conf
    主要是IP地址白名单, 非白名单IP会被拒绝连接

代理端 /usr/local/etc/zabbix_proxy.conf
    指定代理端服务进程的IP地址和主机名; 如果用到数据库,也要配置数据库名和密码;SQLite只要文件完整路径,不需要账号密码

# 启动程序

分别至少占用共享内存36MB,2MB

10051端口

zabbix_server

10050端口

zabbix_agentd

代理客户端

zabbix_proxy


如果源码来自Git仓库, 需要执行命令`make dbschema`

# 安装web端(报表)

假设网站根目录htdocs位于 /home/wwwroot/

mkdir <htdocs>/zabbix
cd zabbix-5.0.3/ui
cp -a . <htdocs>/zabbix

##### 多语言

如果代码来自Git仓库, 且需要安装英语以外的语言包, 执行命令`locale/make_mo.sh`, 这依赖于gettext包的msgfmt工具

##### 初始化web端

- 给目录 conf/ 写入权限

 - 访问地址 http://<server_ip_or_name>/zabbix 安装网页引导操作即可;

 - 默认帐号Admin 密码是zabbix

依赖:

PHP环境 7.2.0
配置项:
memory_limit = 128M
post_max_size = 16MB
upload_max_filesize = 2MB
max_execution_time = 300
max_input_time = 300
session.auto_start = 0
mbstring.func_overload = 0
其余PHP扩展:
bcmath,mbstring,sockets,libxml,xmlwriter,xmlreader,ctype,session,gettext

gd: PNG images (--with-png-dir), JPEG (--with-jpeg-dir) images and FreeType 2 (--with-freetype-dir).

MySQL, Oracle, PostgreSQL.所需扩展三选一:mysql, oci8, pgsql


# 安装Java Gateway网关

JavaGateway用来监控JMX applications, 代理客户端 不需要安装数据库


`./configure --enable-java --prefix=自定义目录/usr/local/javaGateway`

To compile and package Java gateway into a JAR file, run make. Note that for this step you will need `javac` and `jar` executables in your path.

`make`

此时目录 src/zabbix_java/bin 有一个文件 zabbix-java-gateway-$VERSION.jar

确保有权限执行命令`make install`

`make install`

标签: none

添加新评论