Zabbix部署篇-Zabbix4.4基于TimescaleDB环境搭建

释放双眼,带上耳机,听听看~!

介绍

2019.10 ZABBIX 4.4.0 正式发布,发布全新的基于Go语言编写全新agent2和众多新功能特性,接下来介绍最重要的新功能,TimescaleDB数据库,ZABBIX除了支持MySQL、PostgreSQL、Oracle和DB2之外,ZABBIX 官方正式宣布支持TimescaleDB。与传统的关系数据库相比,TimescaleDB有诸多优点:近乎线性的性能水平,支持自动即时删除旧的历史数据,更容易维护等等。

TimescaleDB简介及部署

具体TimescaleDB介绍与部署见:https://abcops.cn/archives/1162

环境介绍

IP 应用 版本 端口 描述
172.26.3.106 Nginx 1.17.5 80 Web代理
172.26.3.106 PHP 7.3.11 9000 处理zabbix php页面
172.26.3.106 TimescaleDB 11.6 5432 存储zabbix数据
172.26.3.106 Redis 5.0.5 6379 缓存php到mysql的数据
172.26.3.106 JDK 1.8.0_232 为zabbix_java提供jdk环境
172.26.3.106 Golang 1.13.5 为zabbix_agent2提供go环境
172.26.3.106 Zabbix_Server 4.4.4 10050 监控服务器
172.26.3.106 Zabbix_agent2 4.4.4 10051 二代监控客户端 golang编写
172.26.3.106 Zabbix_java 4.4.4 10052 通过jmx监控java应用

Nginx部署

安装Nginx依赖

[root@zbxsrv01 /]# yum install zlib.x86_64 zlib-devel.x86_64 pcre.x86_64 pcre-devel.x86_64 openssl.x86_64 openssl-devel.x86_64 -y

下载解压

[root@zbxsrv01 /]# wget -P /usr/local/src http://nginx.org/download/nginx-1.17.5.tar.gz
[root@zbxsrv01 /]# tar xf /usr/local/src/nginx-1.17.5.tar.gz -C /usr/local/src/

创建用户组并编译安装

[root@zbxsrv01 /]# useradd -M -s /bin/false -U nginx
[root@zbxsrv01 /]# cd /usr/local/src/nginx-1.17.5
[root@zbxsrv01 nginx-1.17.5]# ./configure --prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/run/nginx.pid \
--error-log-path=/usr/local/nginx/logs/error.log \
--http-log-path=/usr/local/nginx/logs/access.log \
--with-pcre \
--user=nginx \
--group=nginx \
--with-file-aio \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_v2_module \
--with-threads \
--with-http_realip_module \
--with-http_ssl_module
[root@zbxsrv01 nginx-1.17.5]# make && make install
[root@zbxsrv01 nginx-1.17.5]# echo $?
0

启动并测试Nginx

[root@zbxsrv01 nginx-1.17.5]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@zbxsrv01 nginx-1.17.5]# /usr/local/nginx/sbin/nginx

浏览器测试访问

安装部署PHP

安装PHP依赖

[root@zbxsrv01 /]# yum install libxml2-devel bzip2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libxslt-devel libzip-devel -y

下载并创建用户组

[root@zbxsrv01 /]# wget -P /usr/local/src https://www.php.net/distributions/php-7.3.11.tar.gz
[root@zbxsrv01 /]# tar xf /usr/local/src/php-7.3.11.tar.gz -C /usr/local/src/ 
[root@zbxsrv01 /]# useradd -M -s /bin/false -U php

安装libzip1.x版本

在php7.3版本中,要求libzip版本要大于等于0.11,否则配置出错,所以我们先把yum安装的libzip卸载掉

[root@zbxsrv01 /]# yum remove -y libzip.x86_64 libzip-devel.x86_64
[root@zbxsrv01 /]# wget -P /usr/local/src https://libzip.org/download/libzip-1.2.0.tar.gz
[root@zbxsrv01 /]# tar xf /usr/local/src/libzip-1.2.0.tar.gz -C /usr/local/src/
[root@zbxsrv01 /]# cd /usr/local/src/libzip-1.2.0
[root@zbxsrv01 libzip-1.2.0]# ./configure && make && make install
[root@zbxsrv01 libzip-1.2.0]# echo $?
0

添加libzip库路径到ld.so.conf中使其去加载

cat >> /etc/ld.so.conf << EOF
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
EOF

[root@zbxsrv01 /]# ldconfig -v
[root@zbxsrv01 /]# cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

编译安装php

[root@zbxsrv01 /]# cd /usr/local/src/php-7.3.11
[root@zbxsrv01 php-7.3.11]# ./configure --prefix=/usr/local/php \
--with-fpm-user=php \
--with-fpm-group=php \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysqli \
--with-pgsql \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pdo-pgsql \
--with-pear \
--with-png-dir \
--with-jpeg-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--with-bz2 \
--with-mhash \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-xml \
--enable-zip \
--enable-fpm
[root@zbxsrv01 php-7.3.11]# make && make install

建立PHP配置文件

[root@zbxsrv01 /]# cp /usr/local/src/php-7.3.11/php.ini-production /usr/local/php/lib/php.ini
[root@zbxsrv01 /]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@zbxsrv01 /]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
[root@zbxsrv01 /]# cp /usr/local/src/php-7.3.11/sapi/fpm/php-fpm.service /usr/lib/systemd/system
[root@zbxsrv01 /]# ln -s /usr/local/php/sbin/php-fpm /usr/local/bin/
[root@zbxsrv01 /]# /usr/local/src/php-7.3.11/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin

优化PHP配置

php-fpm.conf

[root@zbxsrv01 /]# grep -Ev ";|^$" /usr/local/php/etc/php-fpm.conf
[global]
pid = run/php-fpm.pid                                   #pid文件位置
error_log = log/php-fpm.log                             #日志路径
log_level = notice                                      #日志级别   {alert警报, error错误, warning警告, notice注意, debug详细}
log_limit = 65536                                       #单行字符数的日志限制(日志条目)
include=/usr/local/php/etc/php-fpm.d/*.conf             #关联文件

www.conf

[root@zbxsrv01 /]# grep -Ev ";|^$" /usr/local/php/etc/php-fpm.d/www.conf
[www]
user = php
group = php
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 30
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 30
pm.max_requests = 5000
slowlog = log/$pool.log.slow
rlimit_files = 65536

参赛解释:
pm = dynamic
php-fpm分为两种模式,静态和动态,当pm = static是为静态模式,pm = dynamic时为动态模式。
php-fpm可以根据所处于的模式对进程数量进行减少或增加,在静态模式下,无法增加或减少进程,在动态模式下可以根据配置的参数进行自动调整进程数量,在繁忙的时候可以多打开几个进程数,在请求少时使用较少的进程数量,从而合理的使用资源。

pm.max_children
静态方式下开启的php-fpm进程数量,此参数指定了php-fpm的进程数量,只有在 pm = static的状态下生效

pm.start_servers
动态方式下的起始php-fpm进程数量,在pm = dynamic下,刚开始启动的php-fpm进程数量,只有在 pm = dynamic的状态下生效

pm.min_spare_servers
动态方式下的最小php-fpm进程数量,随机调整到最小的php-fpm进程数量,只有在 pm = dynamic的状态下生效

pm.max_spare_servers
动态方式下的最大php-fpm进程数量,随机调整到最大的php-fpm进程数量,只有在 pm = dynamic的状态下生效
注:pm.max_spare_servers指定的进程数量必须等于或小于pm.max_children进程数量,否则启动失败

pm.max_requests
设置每个子进程重生之前服务的请求数。对于可能存在内存泄漏的第三方模块来说是非常有用的。如果设置为 ‘0’ 则一直接受请求,等同于 PHP_FCGI_MAX_REQUESTS 环境变量。默认值:0

rlimit_files
php-fpm进程的文件打开数,此数量需要php-fpm运行用户php具备这个打开数

php.ini
需要修改的参数如下,其它参数保持默认,以下参数是Zabbix官方文档指明需要修改的地方,详情见:https://www.zabbix.com/documentation/4.4/manual/installation/install

[root@zbxsrv01 /]# vim /usr/local/php/lib/php.ini
date.timezone = Asia/Shanghai                   #指定时区
memory_limit = 512M                             #脚本消耗的内存量,
post_max_size = 100M                            #PHP最大能接受POST请求的大小
upload_max_filesize = 100M                      #PHP最大能接受上传请求的大小,在我们把模版或清单通过导入Zabbix时就是这里来限制上传大小
max_execution_time = 300                        #每个脚本最大的执行时间,以秒为单位
max_input_time = 300                            #脚本在解析请求数据花费的最大时间,以秒为单位
session.auto_start = 0                          #在请求启动时初始化时间,如果是0则为禁用
mbstring.func_overload = 0                      #用mstring函数替换单字节函数,mail()、ereg()等被mb_send_mail()、mb_ereg()等重载,0为没有超载

启动PHP

[root@zbxsrv01 php-7.3.11]# vim /usr/local/php/lib/php.ini
[root@zbxsrv01 php-7.3.11]# systemctl start php-fpm
[root@zbxsrv01 php-7.3.11]# systemctl enable php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[root@zbxsrv01 php-7.3.11]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2020-01-03 10:50:23 CST; 9s ago
 Main PID: 29729 (php-fpm)
   CGroup: /system.slice/php-fpm.service
           ├─29729 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
           ├─29730 php-fpm: pool www
           ├─29731 php-fpm: pool www
           ├─29732 php-fpm: pool www
           ├─29733 php-fpm: pool www
           └─29734 php-fpm: pool www

Jan 03 10:50:23 zbxsrv01 systemd[1]: Started The PHP FastCGI Process Manager.

Nginx代理PHP进行访问

nginx.conf

[root@zbxsrv01 /]# cat /usr/local/nginx/conf/nginx.conf
user  nginx nginx;
worker_processes  auto;
error_log logs/error.log info;
pid run/nginx.pid;
worker_rlimit_nofile 65535;

events {
    use epoll;
    worker_connections  65535;
    multi_accept on;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    charset utf-8;
    server_tokens off;

    client_header_buffer_size 4096;
    large_client_header_buffers 4 128k;
    client_header_timeout 15;
    client_body_timeout 15;
    send_timeout 65;
    client_max_body_size 1024m;
    open_file_cache max=65535 inactive=60s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 1;
    open_file_cache_errors on;
    server_names_hash_bucket_size 128;

   log_format  main  '$remote_addr" "$remote_user" "[$time_local]" "$request"'
                     ' "$status" "$body_bytes_sent" "$http_referer"'
                     ' "$http_user_agent" "$http_x_forwarded_for" "$gzip_ratio"'
                     ' "$upstream_addr" "$request_time" "$upstream_response_time" "$http_host"';
    access_log  logs/access.log  main;

    sendfile        on;
    autoindex       on;
    tcp_nopush      on;
    tcp_nodelay     on;
    keepalive_timeout  65;
    types_hash_max_size 2048;
    reset_timedout_connection on;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers 16 64K;
    gzip_http_version 1.1;
    gzip_comp_level 6;
    gzip_types text/plain application/x-javascript text/css application/xml application/javascript;
    gzip_vary on;
    gzip_proxied any;
    underscores_in_headers on;
    proxy_ignore_client_abort on;

    include /usr/local/nginx/conf/conf.d/*.conf;
}

创建目录

[root@zbxsrv01 /]# mkdir /usr/local/nginx/conf/conf.d

写入代理配置

[root@zbxsrv01 /]# vim /usr/local/nginx/conf/conf.d/vhost.conf
server {
        listen 80;
        access_log /usr/local/nginx/logs/access.log main;

        location / {
            root /usr/local/nginx/html;
            index index.php index.html index.htm;
        }
        location ~* \.php$ {
            root /usr/local/nginx/html;
            fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
} 

创建index.php文件

cat >> /usr/local/nginx/html/index.php << EOF
<?php
phpinfo();
?>
EOF

重启Nginx

[root@zbxsrv01 /]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@zbxsrv01 /]# /usr/local/nginx/sbin/nginx -s reload 

访问测试
http://172.26.3.106/index.php

安装部署Redis

下载解压编译安装

[root@zbxsrv01 /]# wget -P /usr/local/src http://download.redis.io/releases/redis-5.0.5.tar.gz
[root@zbxsrv01 /]# tar xf /usr/local/src/redis-5.0.5.tar.gz -C /usr/local/src/
[root@zbxsrv01 /]# cd /usr/local/src/redis-5.0.5
[root@zbxsrv01 redis-5.0.5]# make
[root@zbxsrv01 redis-5.0.5]# make install PREFIX=/usr/local/redis

创建配置目录

[root@zbxsrv01 /]# mkdir /usr/local/redis/{etc,data,logs,run} -p 
[root@zbxsrv01 /]# mkdir /usr/local/redis/data/rdb
[root@zbxsrv01 /]# cp /usr/local/src/redis-5.0.5/redis.conf /usr/local/redis/etc/

修改redis配置文件

cat > /usr/local/redis/etc/redis.conf << EOF
daemonize yes
port 6379
bind 0.0.0.0
protected-mode yes
pidfile "/usr/local/redis/run/redis.pid"
loglevel verbose
logfile "/usr/local/redis/logs/redis.log"
databases 16
save 900 1
save 300 10
save 60  10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum  yes
dbfilename dump.rdb
dir "/usr/local/redis/data/rdb/"
timeout 300
tcp-keepalive 300
requirepass aRqcOyx40oxG
EOF

启动并连接redis

[root@zbxsrv01 /]# /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
[root@zbxsrv01 /]# /usr/local/redis/bin/redis-cli -a "aRqcOyx40oxG"
127.0.0.1:6379> SELECT 1
OK

加入开机自启

[root@zbxsrv01 ~]# cat >> /etc/rc.local << EOF
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
EOF

PHP安装Redis扩展

PHP官网下载redis并进行安装

[root@zbxsrv01 ~]# wget -P /usr/local/src http://pecl.php.net/get/redis-5.1.0.tgz
[root@zbxsrv01 ~]# tar xf /usr/local/src/redis-5.1.0.tgz -C /usr/local/src/
[root@zbxsrv01 ~]# cd /usr/local/src/redis-5.1.0
[root@zbxsrv01 redis-5.1.0]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

报错如上,“请检查您的autoconf安装和$PHP_AUTOCONF环境变量。然后,重新运行此脚本。”
解决如下:

[root@zbxsrv01 redis-5.1.0]# yum install m4.x86_64 autoconf.noarch -y 
[root@zbxsrv01 redis-5.1.0]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
[root@zbxsrv01 redis-5.1.0]# ./configure --with-php-config=/usr/local/php/bin/php-config
[root@zbxsrv01 redis-5.1.0]# make && make install

修改php配置文件以载入redis模块

[root@zbxsrv01 /]# echo 'extension=redis.so' >> /usr/local/php/lib/php.ini
[root@zbxsrv01 /]# systemctl restart php-fpm
[root@zbxsrv01 /]# php-fpm -m | grep redis

再次通过phpinfo页面来搜索redis

PHP连接Redis

[root@zbxsrv01 /]# cat /usr/local/nginx/html/php-redis.php
<?php
   $redis = new Redis();
   $redis->connect('127.0.0.1', 6379);
   $redis->auth('aRqcOyx40oxG');
   $redis->select(1);
   $redis->set( "testKey" , "Hello Redis");
   echo $redis->get("testKey");
?> 

访问验证PHP连接Redis

安装部署Zabbix

安装Zabbix依赖包及环境

Zabbix Server依赖包
[root@zbxsrv01 ~]# yum install net-snmp.x86_64 net-snmp-devel.x86_64 curl.x86_64 libxml2.x86_64 libxml2-devel.x86_64 libcurl.x86_64 libcurl-devel.x86_64 fping.x86_64 OpenIPMI.x86_64 OpenIPMI-devel.x86_64 -y

Zabbix_Java依赖包
[root@zbxsrv01 ~]# yum install java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64 -y 

Zabbix_agent2代采用go开发所以要部署Golang环境
[root@zbxsrv01 ~]# wget -P /usr/local/src https://studygolang.com/dl/golang/go1.13.5.linux-amd64.tar.gz
[root@zbxsrv01 ~]# tar xf /usr/local/src/go1.13.5.linux-amd64.tar.gz -C /usr/local
cat > /etc/profile.d/go.sh << EOF
export GOROOT=/usr/local/go
export PATH=\$PATH:\$GOROOT/bin
EOF
[root@zbxsrv01 ~]# source /etc/profile 

下载解压并创建zabbix用户

[root@zbxsrv01 /]# wget -P /usr/local/src https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.4.4/zabbix-4.4.4.tar.gz
[root@zbxsrv01 /]# tar xf /usr/local/src/zabbix-4.4.4.tar.gz -C /usr/local/src/
[root@zbxsrv01 /]# groupadd --system zabbix
[root@zbxsrv01 /]# useradd --system -g zabbix -d /usr/lib/zabbix -s /bin/false -c "Zabbix Monitoring System" zabbix

TimescaleDB创建Zabbix数据库并导入SQL

关于PostgreDB创建数据库及以下操作请参照Zabbix官网:https://www.zabbix.com/documentation/4.4/manual/appendix/install/db_scripts#postgresql
1) 创建数据库及zabbix授权

[root@zbxsrv01 /]# psql  -Upostgres -h 172.26.3.106
Password for user postgres:

postgres=# create user zabbix with password 'Zabbix@2020!';
CREATE ROLE
postgres=# create database zabbix owner zabbix;
CREATE DATABASE
postgres=# grant all privileges on database zabbix to zabbix;
GRANT

2) 数据库创建

[root@zbxsrv01 zabbix-4.4.4]# echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | sudo -u postgres psql zabbix

3) 导入Zabbix数据库

[root@zbxsrv01 ~]# cd /usr/local/src/zabbix-4.4.4/database/postgresql/
[root@zbxsrv01 postgresql]# ls
data.sql  images.sql  Makefile.am  Makefile.in  schema.sql  timescaledb.sql
[root@zbxsrv01 postgresql]# cat schema.sql | sudo -u zabbix psql zabbix
[root@zbxsrv01 postgresql]# cat images.sql | sudo -u zabbix psql zabbix
[root@zbxsrv01 postgresql]# cat data.sql | sudo -u zabbix psql zabbix
[root@zbxsrv01 postgresql]# cat timescaledb.sql | sudo -u zabbix psql zabbix

编译安装Zabbix

以下编译安装需要指定 –with-postgresql 来对postgresql的支持

[root@zbxsrv01 /]# cd /usr/local/src/zabbix-4.4.4/
[root@zbxsrv01 zabbix-4.4.4]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent2 --enable-ipv6 --enable-java --with-postgresql --with-net-snmp --with-libcurl --with-libxml2 --with-zlib --with-libevent --with-libpcre --with-iconv --with-openipmi
[root@zbxsrv01 zabbix-4.4.4]# make install
[root@zbxsrv01 zabbix-4.4.4]# echo $?
0

复制并修改启动脚本文件

agent2代不能使用传统的启动脚本来启动,所以下面没有复制agent的启动文件

[root@zbxsrv01 zabbix-4.4.4]# cp -rf /usr/local/src/zabbix-4.4.4/misc/init.d/fedora/core5/zabbix_server /etc/init.d/ 
[root@zbxsrv01 zabbix-4.4.4]# chmod u+x /etc/init.d/zabbix_server
[root@zbxsrv01 zabbix-4.4.4]# sed -i 's@\/usr\/local\/sbin@\/usr\/local\/zabbix\/sbin@g' /etc/init.d/zabbix_server

修改Zabbix_Server配置

[root@zbxsrv01 /]# grep -Ev "#|^$" /usr/local/zabbix/etc/zabbix_server.conf
ListenPort=10051
LogType=file
LogFile=/tmp/zabbix_server.log
LogFileSize=100
DebugLevel=3
PidFile=/tmp/zabbix_server.pid
SocketDir=/tmp
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=Zabbix@2020!
DBPort=5432
HistoryStorageDateIndex=1
StartPollers=15
StartIPMIPollers=3
StartPreprocessors=10
StartPollersUnreachable=5
StartTrappers=5
StartPingers=10
StartDiscoverers=5
StartHTTPPollers=15
StartTimers=3
StartEscalators=3
StartAlerters=10
JavaGateway=192.168.31.242
JavaGatewayPort=10052
StartJavaPollers=10
StartVMwareCollectors=3
VMwareFrequency=60
VMwarePerfFrequency=60
VMwareCacheSize=64M
VMwareTimeout=10
SNMPTrapperFile=/tmp/zabbix_traps.tmp
StartSNMPTrapper=1
ListenIP=0.0.0.0
HousekeepingFrequency=12
MaxHousekeeperDelete=10000
CacheSize=1024M
CacheUpdateFrequency=60
StartDBSyncers=5
HistoryCacheSize=256M
HistoryIndexCacheSize=256M
TrendCacheSize=256M
ValueCacheSize=256M
Timeout=15
TrapperTimeout=60
UnreachablePeriod=60
UnavailableDelay=60
UnreachableDelay=45
AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts
ExternalScripts=/usr/local/zabbix/share/zabbix/externalscripts
FpingLocation=/sbin/fping
SSHKeyLocation=
LogSlowQueries=3000
TmpDir=/tmp
StartProxyPollers=5
ProxyConfigFrequency=60
ProxyDataFrequency=60
StartLLDProcessors=5
AllowRoot=0
User=zabbix
Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf
StatsAllowedIP=127.0.0.1

创建临时文件

[root@zbxsrv01 ~]# touch /tmp/zabbix_traps.tmp
[root@zbxsrv01 ~]# chown -Rf zabbix.zabbix /tmp/zabbix_traps.tmp

将Zabbix的前端页面文件复制到Nginx网页目录中

[root@zbxsrv01 /]# mkdir /usr/local/nginx/html/zabbix
[root@zbxsrv01 /]# cp -rf /usr/local/src/zabbix-4.4.4/frontends/php/* /usr/local/nginx/html/zabbix/
[root@zbxsrv01 /]# cp -rf /usr/local/nginx/html/zabbix/conf/zabbix.conf.php.example /usr/local/nginx/html/zabbix/conf/zabbix.conf.php 

修改Zabbix前端页面

[root@zbxsrv01 /]# grep -Ev "//|^$" /usr/local/nginx/html/zabbix/conf/zabbix.conf.php
<?php
global $DB, $HISTORY;
$DB['TYPE']                             = 'POSTGRESQL';
$DB['SERVER']                   = 'localhost';
$DB['PORT']                             = '5432';
$DB['DATABASE']                 = 'zabbix';
$DB['USER']                             = 'zabbix';
$DB['PASSWORD']                 = 'Zabbix@2020!';
$DB['SCHEMA']                   = '';
$ZBX_SERVER                             = 'localhost';
$ZBX_SERVER_PORT                = '10051';
$ZBX_SERVER_NAME                = '';
$IMAGE_FORMAT_DEFAULT   = IMAGE_FORMAT_PNG;

修改Nginx配置文件以代理Zabbix

[root@zbxsrv01 /]# vim /usr/local/nginx/conf/conf.d/vhost.conf
server {
        listen 80;
        access_log /usr/local/nginx/logs/access.log main;

        location / {
            root /usr/local/nginx/html/zabbix;                                  #指定我们复制的zabbix前端页面位置
            index index.php index.html index.htm;
        }
        location ~* \.php$ {
            root /usr/local/nginx/html/zabbix;                                  #指定我们复制的zabbix前端页面位置
            fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
}

重启Nginx

[root@zbxsrv01 /]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@zbxsrv01 /]# /usr/local/nginx/sbin/nginx -s reload  

启动zabbix并访问

[root@zbxsrv01 /]# service zabbix_server start
[root@zbxsrv01 /]# chkconfig --add zabbix_server
[root@zbxsrv01 /]# chkconfig zabbix_server on

访问地址:http://172.26.3.106

配置Zabbix Agent2

修改zabbix agent2配置文件

[root@zbxsrv01 /]# grep -Ev "#|^$" /usr/local/zabbix/etc/zabbix_agent2.conf
PidFile=/tmp/zabbix_agent2.pid
LogType=file
LogFile=/tmp/zabbix_agent2.log
LogFileSize=100
DebugLevel=3
Server=127.0.0.1,192.168.31.242
ListenPort=10050
ServerActive=127.0.0.1,192.168.31.242
Hostname=192.168.31.242
Timeout=10
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
ControlSocket=/tmp/agent.sock

启动zabbix agent2

agent2不能以传统的agent使用管理脚本来启动,默认启动需放置前台

#启动agent2
[root@zbxsrv01 /]# /usr/local/zabbix/sbin/zabbix_agent2
Starting Zabbix Agent 2 [172.26.3.102]. (4.4.4)
Press Ctrl+C to exit.

#或者是用nohup来放置后台或是用Supervidord来管理
[root@zbxsrv01 /]# nohup /usr/local/zabbix/sbin/zabbix_agent2 & 
[root@zbxsrv01 /]# echo 'nohup /usr/local/zabbix/sbin/zabbix_agent2 &' >> /etc/rc.local

修改Zabbix Web页面的监控Hostname

将如下Hostname与zabbix_agent2.conf中的hostname配置一致,Visible name为可见名称

配置Zabbix_Java

修改Zabbix_java配置文件

[root@zbxsrv01 /]# grep -Ev "#|^$" /usr/local/zabbix/sbin/zabbix_java/settings.sh
LISTEN_IP="0.0.0.0"
LISTEN_PORT=10052
PID_FILE="/tmp/zabbix_java.pid"
START_POLLERS=10
TIMEOUT=15 

启动Zabbix_java

[root@zbxsrv01 /]# /usr/local/zabbix/sbin/zabbix_java/startup.sh
[root@zbxsrv01 /]# echo '/usr/local/zabbix/sbin/zabbix_java/startup.sh' >> /etc/rc.local 

人已赞赏
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索