首先要阅读requirement, 结合你的环境, 满足日后的使用, 需要合理的选择硬件, 以及需要的依赖组件或库.
需要注意一下数据库大小的估算.
数据库里存放的数据包括, 配置信息, 历史数据, 报告数据(趋势数据), 事件数据.
这些数据量的评估, 首先和每秒server接收到的数据量有关, 例如我们配置了3000个监控条目, 每60秒监控一次, 那么每秒将受到3000/60=50条监控数据,
监控数据和监控配置有关, 可能存储的是数字, 或者字符串, 或者其他的值, 假设平均50个字节一条.
那么存放1年的历史数据需要50*24*60*60*365*50 bytes=73GB.
统计数据是指统计每小时的最大, 最小, 平均, COUNT值. 假设一个条目每小时需要128字节来存储统计信息.
同样假设有3000个监控条目, 那么存储1年的统计数据需要3000*24*365*128=16.8GB
最后是事件的存储, 事件指触发的事件, 这个比较难估算, 最坏来算每秒产生1个事件, 一个事件存储消耗130个字节, 那么保存3年的事件需要空间3*24*60*60*365*130=12.3GB
安装过程 :
下载稳定版本源码包
zabbix-2.2.6.tar.gz
阅读安装说明
1. 创建用户和组, 所有的zabbix daemon必须以普通用户运行来避免风险. 如果以root用于运行, 会自动切换到zabbix下运行. 如果以普通用户运行, 则
以运行daemon的普通用户运行. 除了不要以root来运行, 同时不要以有特权的任何普通用户运行daemon.
注意1: Running Zabbix as root, bin, or any other account with special rights is a security risk.
注意2: 如果server和agent在同一台机器的话, 务必使用不同的用户启动两个daemon, 因为如果使用同一个用户启动的话, agent很容易获取到server的配置文件, 所以建议使用不同的用户运行agent和server, 来分离权限.
如果同主机还需要运行agent, 建议再创建一个用户.
选择要安装的组件, (例如server, proxy, agent全部安装)编译安装 :
cnofigure时, 可能会因为缺少lib库报错,
解决
例如
解决
配置/etc/profile
配置并启动nginx
5. 配置WEB
同时, 如果要使用新版本的lib, 需要重新编译.
6. 创建数据库
7. 创建schema
[问题]
[参考]
[root@150 zabbix-2.2.6]# useradd zabbix
[root@150 zabbix-2.2.6]# id zabbix
uid=501(zabbix) gid=502(zabbix) groups=502(zabbix)
如果同主机还需要运行agent, 建议再创建一个用户.
[root@150 soft_bak]# useradd zagent
[root@150 soft_bak]# id zagent
uid=502(zagent) gid=503(zagent) groups=503(zagent)
2. 创建数据库, zabbix server, proxy, WEB需要l连接数据库, agent不需要连接数据库.
同时zabbix server需要在数据库中生成一些数据, 而proxy只需要结构.
我们这里选用PostgreSQL 9.3.5, 编译安装一个, 安装过程和初始化数据库的过程略.
useradd postgres
tar -jxvf postgresql-9.3.5.tar.bz2
cd postgresql-9.3.5
./configure --prefix=/opt/pgsql9.3.5 --with-pgport=5432 --with-perl --with-tcl --with-python --with-openssl --with-pam --with-ldap --with-libxml --with-libxslt --enable-thread-safety
gmake world && gmake install-world
ln -s /opt/pgsql9.3.5 /opt/pgsql
vi /etc/profile
export PATH=/opt/pgsql/bin:$PATH
export MANPATH=/opt/pgsql/share/man:$MANPATH
export LD_LIBRARY_PATH=/opt/pgsql/lib:$LD_LIBRARY_PATH
mkdir -p /data03/pgdata/pg_root
chown postgres:postgres /data03/pgdata/pg_root
su - postgres
vi .bash_profile
export PS1="$USER@`/bin/hostname -s`-> "
export PGPORT=5432
export PGDATA=/data03/pgdata/pg_root
export LANG=en_US.utf8
export PGHOME=/opt/pgsql
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export DATE=`date +"%Y%m%d%H%M"`
export PATH=$PGHOME/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH
export PGUSER=postgres
export PGHOST=$PGDATA
alias rm='rm -i'
alias ll='ls -lh'
export PGDATABASE=postgres
initdb -D $PGDATA -E UTF8 --locale=C -U postgres -W
cd $PGDATA
vi postgresql.conf
listen_addresses = '0.0.0.0' # what IP address(es) to listen on;
port = 5432 # (change requires restart)
max_connections = 500 # (change requires restart)
superuser_reserved_connections = 13 # (change requires restart)
unix_socket_directories = '.' # comma-separated list of directories
unix_socket_permissions = 0700 # begin with 0 to use octal notation
tcp_keepalives_idle = 60 # TCP_KEEPIDLE, in seconds;
tcp_keepalives_interval = 10 # TCP_KEEPINTVL, in seconds;
tcp_keepalives_count = 10 # TCP_KEEPCNT;
shared_buffers = 2048MB # min 128kB
maintenance_work_mem = 512MB # min 1MB
shared_preload_libraries = 'pg_stat_statements' # (change requires restart)
vacuum_cost_delay = 10 # 0-100 milliseconds
vacuum_cost_limit = 10000 # 1-10000 credits
bgwriter_delay = 10ms # 10-10000ms between rounds
wal_level = hot_standby # minimal, archive, or hot_standby
synchronous_commit = off # synchronization level;
wal_buffers = 16384kB # min 32kB, -1 sets based on shared_buffers
wal_writer_delay = 10ms # 1-10000 milliseconds
checkpoint_segments = 128 # in logfile segments, min 1, 16MB each
archive_mode = on # allows archiving to be done
archive_command = '/bin/date' # command to use to archive a logfile segment
max_wal_senders = 32 # max number of walsender processes
wal_keep_segments = 256 # in logfile segments, 16MB each; 0 disables
hot_standby = on # "on" allows queries during recovery
max_standby_archive_delay = 300s # max delay before canceling queries
max_standby_streaming_delay = 300s # max delay before canceling queries
wal_receiver_status_interval = 1s # send replies at least this often
hot_standby_feedback = on # send info from standby to prevent
effective_cache_size = 8192MB
log_destination = 'csvlog' # Valid values are combinations of
logging_collector = on # Enable capturing of stderr and csvlog
log_directory = 'pg_log' # directory where log files are written,
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,
log_file_mode = 0600 # creation mode for log files,
log_truncate_on_rotation = on # If on, an existing log file with the
log_rotation_age = 1d # Automatic rotation of logfiles will
log_rotation_size = 10MB # Automatic rotation of logfiles will
log_min_duration_statement = 1s # -1 is disabled, 0 logs all statements
log_checkpoints = on
log_connections = on
log_disconnections = on
log_error_verbosity = verbose # terse, default, or verbose messages
log_statement = 'ddl' # none, ddl, mod, all
log_timezone = 'PRC'
log_autovacuum_min_duration = 0 # -1 disables, 0 logs all actions and
autovacuum_vacuum_threshold = 50 # min number of row updates before
autovacuum_analyze_threshold = 50 # min number of row updates before
autovacuum_vacuum_scale_factor = 0.2 # fraction of table size before vacuum
autovacuum_analyze_scale_factor = 0.1 # fraction of table size before analyze
autovacuum_vacuum_cost_delay = 10ms # default vacuum cost delay for
datestyle = 'iso, mdy'
timezone = 'PRC'
lc_messages = 'C' # locale for system error message
lc_monetary = 'C' # locale for monetary formatting
lc_numeric = 'C' # locale for number formatting
lc_time = 'C' # locale for time formatting
default_text_search_config = 'pg_catalog.english'
pg_stat_statements.max=1000
pg_stat_statements.track=all
pg_stat_statements.save=on
3. 编译安装zabbix
查看详细的编译参数, 只有编译安装proxy和server时, 需要选择数据库类型.
[root@150 zabbix-2.2.6]# ./configure --help
选择要安装的组件, (例如server, proxy, agent全部安装)编译安装 :
[root@150 zabbix-2.2.6]# ./configure --prefix=/opt/zabbix2.2.6 --enable-server --enable-proxy --enable-agent --enable-java --enable-ipv6 --with-postgresql=/opt/pgsql/bin/pg_config --with-net-snmp --with-ssh2 --with-openipmi --with-ldap --with-libcurl --with-iconv
cnofigure时, 可能会因为缺少lib库报错,
例如
checking for SSH2 support... no
configure: error: SSH2 library not found
解决
[root@150 zabbix-2.2.6]# yum install -y libssh2-devel
例如
checking for OPENIPMI support... no
configure: error: Invalid OPENIPMI directory - unable to find ipmiif.h
解决
[root@150 zabbix-2.2.6]# yum install -y OpenIPMI-devel
# make && make install
[root@150 zabbix-2.2.6]# ln -s /opt/zabbix2.2.6 /opt/zabbix
[root@150 zabbix-2.2.6]# cd /opt/zabbix
[root@150 zabbix]# ll
total 20
drwxr-xr-x 2 root root 4096 Aug 31 12:10 bin
drwxr-xr-x 6 root root 4096 Aug 31 12:10 etc
drwxr-xr-x 2 root root 4096 Aug 31 12:10 lib
drwxr-xr-x 3 root root 4096 Aug 31 12:10 sbin
drwxr-xr-x 4 root root 4096 Aug 31 12:10 share
配置/etc/profile
vi /etc/profile
export PATH=/opt/zabbix/bin:/opt/zabbix/sbin:$PATH
export MANPATH=/opt/zabbix/share/man:$MANPATH
export LD_LIBRARY_PATH=/opt/zabbix/lib:$LD_LIBRARY_PATH
其他,
1. 如果你要分发你编译好的binary, 那么可以使用静态链接库把依赖的动态库编辑进来, 那么就可以直接分发给其他OS使用了.
选项 --enable-static .
2. 如果添加了--enable-proxy, 那么会生成get和sender两条命令. 如下, 用于接收agent发生过来的信息, 同时发送给server.
[root@150 zabbix]# ll bin/
total 560
-rwxr-xr-x 1 root root 256830 Aug 31 12:10 zabbix_get
-rwxr-xr-x 1 root root 314325 Aug 31 12:10 zabbix_sender
4. 安装nginx, php, php-fpm
参考
配置并启动php-fpm
# vi /etc/profile
export PATH=/opt/php5.5.14/bin:/opt/php5.5.14/sbin:$PATH
export MANPATH=/opt/php5.5.14/php/man:$MANPATH
[root@150 ~]# php --ini
Configuration File (php.ini) Path: /opt/php5.5.14/lib
Loaded Configuration File: (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
# . /etc/profile
注意拷贝到对应的配置目录
# cp php-5.5.14/php.ini-production /opt/php5.5.14/lib/php.ini
# cp /opt/php5.5.14/etc/php-fpm.conf.default /opt/php5.5.14/etc/php-fpm.conf
[root@150 zabbix]# which php-fpm
/opt/php5.5.14/sbin/php-fpm
[root@150 zabbix]# php-fpm -R -c /opt/php5.5.14/etc
[root@150 zabbix]# netstat -anp|grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 26627/php-fpm
配置并启动nginx
[root@150 conf]# pwd
/opt/nginx1.6.0/conf
[root@150 conf]# ll
total 60
-rw-r--r-- 1 root root 1034 Aug 31 15:08 fastcgi.conf
-rw-r--r-- 1 root root 1034 Aug 31 15:08 fastcgi.conf.default
-rw-r--r-- 1 root root 964 Aug 31 15:08 fastcgi_params
-rw-r--r-- 1 root root 964 Aug 31 15:08 fastcgi_params.default
-rw-r--r-- 1 root root 2837 Aug 31 15:08 koi-utf
-rw-r--r-- 1 root root 2223 Aug 31 15:08 koi-win
-rw-r--r-- 1 root root 3957 Aug 31 15:08 mime.types
-rw-r--r-- 1 root root 3957 Aug 31 15:08 mime.types.default
-rw-r--r-- 1 root root 2639 Aug 31 15:12 nginx.conf
-rw-r--r-- 1 root root 2656 Aug 31 15:08 nginx.conf.default
-rw-r--r-- 1 root root 596 Aug 31 15:08 scgi_params
-rw-r--r-- 1 root root 596 Aug 31 15:08 scgi_params.default
-rw-r--r-- 1 root root 623 Aug 31 15:08 uwsgi_params
-rw-r--r-- 1 root root 623 Aug 31 15:08 uwsgi_params.default
-rw-r--r-- 1 root root 3610 Aug 31 15:08 win-utf
[root@150 conf]# pwd
/opt/nginx1.6.0/conf
[root@150 conf]# cat nginx.conf
user nobody;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8080;
server_name digoal;
root /opt/www/zabbix;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
index index.html index.htm index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
启动
[root@150 conf]# /opt/nginx1.6.0/sbin/nginx -c /opt/nginx1.6.0/conf/nginx.conf
5. 配置WEB
[root@150 php]# pwd
/opt/soft_bak/zabbix-2.2.6/frontends/php
将php目录中的所有文件拷贝到/opt/www/zabbix
[root@150 frontends]# mkdir -p /opt/www/zabbix
[root@150 php]# cp -a . /opt/www/zabbix/
搞定所有的检查未通过问题.
有一些默认配置要修改.
# vi /opt/php5.5.14/lib/php.ini
post_max_size = 16M
date.timezone = Asia/Shanghai
max_execution_time = 300
max_input_time = 300
[root@150 etc]# ps -ewf|grep php
root 14100 1 0 09:25 ? 00:00:00 php-fpm: master process (/opt/php5.5.14/etc/php-fpm.conf)
nobody 14101 14100 0 09:25 ? 00:00:00 php-fpm: pool www
nobody 14102 14100 0 09:25 ? 00:00:00 php-fpm: pool www
root 14604 504 0 09:32 pts/0 00:00:00 grep php
[root@150 etc]# kill -9 14100
[root@150 etc]# kill -9 14101
[root@150 etc]# kill -9 14102
[root@150 etc]# php-fpm -R
同时, 如果要使用新版本的lib, 需要重新编译.
# wget http://download.savannah.gnu.org/releases/freetype/freetype-2.5.3.tar.bz2
# tar -jxvf freetype-2.5.3.tar.bz2
# cd freetype-2.5.3
# ./configure --prefix=/opt/freetype2.5.3
# make && make install
# ./configure --prefix=/opt/php5.5.14 --with-pcre-regex=/usr/lib64 --enable-fpm --enable-opcache --with-pdo-pgsql=/opt/pgsql/bin --with-pgsql=/opt/pgsql/bin --enable-bcmath --enable-mbstring --enable-sockets --with-gd --with-gettext --with-libdir=lib64 --with-jpeg-dir --with-png-dir --with-freetype-dir=/opt/freetype2.5.3
# make && make install
注意php 5.5.14的gd库是随php源码包绑定的, 所以就是2.1的版本.
# 重启php-fpm
# php-fpm -R -c /usr/local/etc
6. 创建数据库
[root@150 etc]# su - postgres
postgres@150-> psql
psql (9.3.5)
Type "help" for help.
postgres=# create role zabbix nosuperuser login encrypted password 'digoal';
CREATE ROLE
postgres=# create database zabbix with template template0 encoding 'UTF8' ;
CREATE DATABASE
postgres=# grant all on database zabbix to zabbix;
GRANT
7. 创建schema
shell> psql -U <username>
psql> create database zabbix;
psql> \q
shell> cd database/postgresql
shell> psql -U <username> zabbix < schema.sql
# stop here if you are creating database for Zabbix proxy , 如果是代理的话, 只需要创建schema.
shell> psql -U <username> zabbix < images.sql
shell> psql -U <username> zabbix < data.sql
[root@150 postgresql]# pwd
/opt/soft_bak/zabbix-2.2.6/database/postgresql
[root@150 postgresql]# ll
total 2896
-rw-rw-r-- 1 1000 1000 873252 Aug 27 21:08 data.sql
-rw-rw-r-- 1 1000 1000 1979089 Aug 27 21:07 images.sql
-rw-rw-r-- 1 1000 1000 102928 Aug 27 21:08 schema.sql
[root@150 postgresql]# su - postgres
postgres@150-> cd /opt/soft_bak/zabbix-2.2.6/database/postgresql/
postgres@150-> psql -h 127.0.0.1 -U zabbix zabbix -f ./schema.sql
postgres@150-> psql -h 127.0.0.1 -U zabbix zabbix -f ./images.sql
postgres@150-> psql -h 127.0.0.1 -U zabbix zabbix -f ./data.sql
确保没有任何报错, 注意我们这里使用了public schema, 因为不了解zabbix是否写了schema name, 所以就用public吧.
8. 继续web配置
这里需要配置zabbix server的主机名IP, 以及zabbix server的监听端口, 后面还可以通过配置文件来修改.
这里需要
下载配置文件到/opt/www/zabbix/conf
配置文件里可以修改zabbix server的连接IP, 端口.
[root@150 conf]# cat zabbix.conf.php
<?php
// Zabbix GUI configuration file
global $DB;
$DB['TYPE'] = 'POSTGRESQL';
$DB['SERVER'] = '127.0.0.1';
$DB['PORT'] = '5432';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = 'digoal';
// SCHEMA is relevant only for IBM_DB2 database
$DB['SCHEMA'] = '';
$ZBX_SERVER = '0.0.0.0';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'digoal';
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
?>
用户密码存在数据库里面, 密码已经加密了.
用户Admin默认密码zabbix
zabbix=> select * from users;
-[ RECORD 1 ]--+---------------------------------
userid | 1
alias | Admin
name | Zabbix
surname | Administrator
passwd | 5fce1b3e34b520afeffb37ce08c7cd66
url |
autologin | 1
autologout | 0
lang | en_GB
refresh | 30
type | 3
theme | default
attempt_failed | 0
attempt_ip |
attempt_clock | 0
rows_per_page | 50
-[ RECORD 2 ]--+---------------------------------
userid | 2
alias | guest
name |
surname |
passwd | d41d8cd98f00b204e9800998ecf8427e
url |
autologin | 0
autologout | 900
lang | en_GB
refresh | 30
type | 1
theme | default
attempt_failed | 0
attempt_ip |
attempt_clock | 0
rows_per_page | 50
[问题]
1. gd jpeg, freetype的支持问题,
在zabbix WEB配置时一直显示不通过,
检测代码如下 :
/opt/www/zabbix/include/classes/class.frontendsetup.php
/**
* Checks for PHP GD JPEG support.
*
* @return array
*/
public function checkPhpGdJpeg() {
if (is_callable('gd_info')) {
$gdInfo = gd_info();
// check for PHP prior 5.3.0, it returns 'JPG Support' key.
$current = isset($gdInfo['JPG Support']) ? $gdInfo['JPG Support'] : $gdInfo['JPEG Support'];
}
else {
$current = false;
}
return array(
'name' => _('PHP gd JPEG support'),
'current' => $current ? _('on') : _('off'),
'required' => null,
'result' => $current ? self::CHECK_OK : self::CHECK_FATAL,
'error' => _('PHP gd JPEG image support missing.')
);
}
/**
* Checks for PHP GD FreeType support.
*
* @return array
*/
public function checkPhpGdFreeType() {
if (is_callable('gd_info')) {
$gdInfo = gd_info();
$current = $gdInfo['FreeType Support'];
}
else {
$current = false;
}
return array(
'name' => _('PHP gd FreeType support'),
'current' => $current ? _('on') : _('off'),
'required' => null,
'result' => $current ? self::CHECK_OK : self::CHECK_FATAL,
'error' => _('PHP gd FreeType support missing.')
);
}
配置代码如下 :
php-5.5.14/configure
if test "$PHP_JPEG_DIR" != "no"; then
for i in $PHP_JPEG_DIR /usr/local /usr; do
test -f $i/include/jpeglib.h && GD_JPEG_DIR=$i && break
done
if test -z "$GD_JPEG_DIR"; then
as_fn_error $? "jpeglib.h not found." "$LINENO" 5
fi
....
if test "$PHP_FREETYPE_DIR" != "no"; then
for i in $PHP_FREETYPE_DIR /usr/local /usr; do
if test -f "$i/bin/freetype-config"; then
FREETYPE2_DIR=$i
FREETYPE2_CONFIG="$i/bin/freetype-config"
break
fi
done
if test -z "$FREETYPE2_DIR"; then
as_fn_error $? "freetype-config not found." "$LINENO" 5
fi
解决办法, 把源码包删掉重新编译.
可能是原来的configure遗留的问题. 一直在此基础上做编译安装导致的.