Zabbix安装
资源要求
依赖关系
环境准备
https://github.com/findsec-cn/zabbix
阿里云镜像 和zabbix镜像
#http://mirrors.aliyun.com/repo/Centos-7.repo
#https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum install -y wget
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#更新镜像源
#清除缓存:
yum clean all
#生成缓存:
yum makecache
#备份CentOS 7系统自带yum源配置文件/etc/yum.repos.d/CentOS-Base.repo命令
#找到yum源的配置路径
cd /etc/yum.repos.d
#打开CentOS-Base.repo文件:
vim CentOS-Base.repo
#将文件中的所有http开头的地址更改为https
#更新yum
yum update
#安装epel-release
yum install epel-release
#安装Develop tools工具组
yum groups install "Development Tools"
#yum groups info "Development Tools"
#安装zabbix镜像源
rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
#关闭主机selinux脚本
---------------------------------------------
#!/bin/bash
sed -i "s/^SELINUX=.*$/SELINUX=disabled/g" /etc/selinux/config
#修改selinux配置文件,关闭selinux
systemctl disable firewalld
#设置开机禁用防火墙
systemctl disable NetworkManager
---------------------------------------------
1、二进制包安装
#安装zabbix server
yum install zabbix-server-mysql
#yum search搜索
#安装zabbix front
yum install zabbix-web-mysql
#安装mysql
yum install mariadb-server
#启动mysql
systemctl start mariadb.service
systemctl status mariadb.service
#查看mysql服务及密码
ps aux|grep mysql
#运行mysql初始化命令
mysql_secure_installation
#创建zabbix数据
mysql -uroot -p
> create database zabbix character set utf8 collate utf8_bin;
#创建用户
grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix@findsec123' with grant option;
flush privileges;
#导入zabbix数据库
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pzabbix@findsec123 zabbix
#配置zabbix服务的配置项
vi /etc/zabbix/zabbix_server.conf
-------------------------
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix@findsec123
#配置php.ini参数
max_execution_time=300
#内存设置
#post设置
post_max_size=16m
file_uploads=On
upload_max_filesize=2m
max_file_uploads=2m
#启动zabbix server
systemctl start zabbix-server.service
#查看启动状态
systemctl status zabbix-server.service
#打开时区
vim /etc/httpd/conf.d/zabbix.conf
#启动httpd
systemctl restart httpd.service
#修改完
vi php./etc/php.ini
#启动apache服务
#默认用户密码:Admin@zabbix
2、源码包安装
zabbix安装的步骤:
1、zabbix服务安装
2、zabbix前端安装php,web server的安装
3、zabbix数据安装
4、zabbix agent安装
1、zabbix服务端源码安装
#下载zabbix源码
wget -O zabbix-4.0.27.tar.gz https://cdn.zabbix.com/zabbix/sources/stable/4.0/zabbix-4.0.27.tar.gz
#安装相关依赖
yum install wget telnet net-tools python-paramiko gcc gcc-c++ dejava-sans-fonts python-setuptools python-devel sendmail mailx net-snmp net-snmp-devel net-snmp-utils freetype-devel libpng-devel perl unbound libtasn1-devel pll-kit-devel OpenIPMI unixODBC libevent-devel mysql-devel libxml2-devel libssh2-devel OpenIPMI-devel java-1.8.0-openjdk-devel openldap-devel curl-devel unixODBC-devel
#定义zabbix安装目录 如下:
mkdir -p /opt/zabbix
#解压相关源码包
tar -zxvf /home/zabbix/zabbix-4.0.27.tar.gz
mv /home/zabbix/zabbix-4.0.27 /home/zabbix/zabbix4
#配置
cd /home/zabbix/zabbix4
#查看编译想
./configure -help
./configure
################################################################################
`configure' configures Zabbix 4.0.27 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-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-ibm-db2[=ARG] use IBM DB2 CLI from given sqllib directory
(ARG=path); use /home/db2inst1/sqllib (ARG=yes);
disable IBM DB2 support (ARG=no)
--with-ibm-db2-include[=DIR]
use IBM DB2 CLI headers from given path
--with-ibm-db2-lib[=DIR]
use IBM DB2 CLI libraries from given path
--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 Jabber protocol for messaging:
--with-jabber[=DIR] Include Jabber support [default=no]. DIR is the
iksemel library install directory.
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 mbed TLS (PolarSSL) library:
--with-mbedtls[=DIR] use mbed TLS (PolarSSL) package [default=no], DIR is
the libpolarssl install directory.
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
IKSEMEL_CFLAGS
C compiler flags for IKSEMEL, overriding pkg-config
IKSEMEL_LIBS
linker flags for IKSEMEL, overriding pkg-config
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
Report bugs to the package provider.
################################################################################
#制定安装enable-server
./configure --prefix=/opt/zabbix --enable-server --enable-agent --enable-java --with-mysql --with-libxml2 --with-unixodbc --with-net-snmp --with-ssh2 --with-openipmi --with-ldap --with-libcurl
#编译并安装
make && make install
###########################
#Zabbix编译参数说明
#--prefix 指定安装的目录
#--enable-server 安装zabbix-server
#--enable-agent 安装zabbix-agent
#--with-mysql 用mysql来进行存储
###########################
/opt/zabbix/sbin/zabbix_server -V
#安装mysql数据库(略过)
#安装mysql
yum install mariadb-server
#启动mysql
systemctl start mariadb.service
systemctl status mariadb.service
#查看mysql服务及密码
ps aux|grep mysql
#运行mysql初始化命令
mysql_secure_installation
#配置zabbix server
#配置文件的路径:/usr/local/zabbix/etc/zabbix_server.conf
LogFile=/usr/local/zabbix/zabbix_server.log
DBHost=127.0.0.1
DBName=zabbix
DBUser=zabbix
DBPassword=123456
DBPort=3306
Timeout=30
AlertScriptsPath=/usr/local/zabbix/alertscripts
ExternalScripts=/usr/local/zabbix/externalscripts
LogSlowQueries=3000
#启动zabbix server
chown zabbix:zabbix -R /usr/local/zabbix/
zabbix_server -c /zabbix_server.conf
#zabbix-agent配置
#/opt/zabbix/etc/zabbix_agentd.conf
#cat过滤注释行和空白行
cat zabbix_agentd.conf | grep -Ev '^$|#'
#启动zabbix-agent
zabbix-agent -c /zabbix_agent.conf
2、zabbix前端安装
Zabbix Web的安装
# 在nginx的html下建立zabbix的web文件夹
mkdir /usr/local/nginx/html/zabbix
# 从zabbix目录拷贝web页面到nginx下
cp -a /usr/local/src/zabbix-4.0.x/frontends/php/* /usr/local/nginx/html/zabbix/
## 配置文件的路径:vi /usr/local/php/etc/php.ini
post_max_size = 32M
max_execution_time = 350
max_input_time = 350
date.timezone = Asia/Shanghai
always_populate_raw_post_data = -1
#修改php.ini配置文件后,重启php-fpm.service
默认用户名和密码:Admin zabbix
禁用Zabbix server主机的监控
3、容器安装
docker安装zabbix
yum install -y docker #按doker服务
systemctl start docker #启动docker
systemctl enable docker #开机自启动
systemctl status docker #检查docker启动状态
########################################
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
]
}
####################################
#安装zabbix相关组件
docker run --name mysql-server -t -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="zabbix@163.com" -e MYSQL_ROOT_PASSWORD="zabbix@163.com" -d mysql:5.7 --character-set-server=utf8 --collation-server=utf8_bin
#docker logs
#安装zabbix java-gateway
docker run --name zabbix-java-gateway -t -d zabbix/zabbix-java-gateway:latest
#docker logs
#安装zabbix-server
docker run --name zabbix-server-mysql -t -e DB_SERVER_HOST="mysql-server" -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="zabbix@163.com" -e ZBX_JAVAGATEWAY="zabbix-java-gateway" --link mysql-server:mysql --link zabbix-java-gateway:zabbix-java-gateway -p 10051:10051 -d zabbix/zabbix-server-mysql:latest
#安装zabbix前端
docker run --name zabbix-web-nginx-mysql -t -e DB_SERVER_HOST="mysql-server" -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_ROOT_PASSWORD="zabbix@163.com" -e MYSQL_PASSWORD="zabbix@163.com" --link zabbix-server-mysql:zabbix-server-mysql --link mysql-server:mysql -p 80:8080 -d zabbix/zabbix-web-nginx-mysql:latest
#异常可以echo "DOCKER_OPTS=\"\$DOCKER_OPTS --registry-mirror=http://f2d6cb40.m.daocloud.io\"" | sudo tee -a /etc/default/docker
docker run --name zabbix-agent -e ZBX_HOSTNAME="Zabbix server" -e ZBX_SERVER_PORT=10051 -e ZBX_SERVER_HOST="zabbix-server-mysql" --link zabbix-server-mysql:zabbix-server-mysql -p 10050:10050 -d zabbix/zabbix-agent:latest
4、访问
http://ip:port/zabbix 用户及密码:Admin/zabbix