ZABBIX 4.0 LTS 部署 - 图1

1. 环境说明

关于zabbix的详细使用可以参考之前的3.0 版本,该文档仅记录zabbix 4.0 编译安装过程!
ZABBIX 3.0 从入门到精通(zabbix使用详解) : https://www.cnblogs.com/clsn/p/7885990.html
ZABBIX 4.0 中文参考文档 : https://www.zabbix.com/documentation/4.0/zh/manual

1.1 Linux环境说明

zabbix 安装要求 https://www.zabbix.com/documentation/4.0/zh/manual/installation/requirements

  1. [root@clsn.io /root] clsn.io Blog WebSite
  2. #cat /etc/redhat-release
  3. CentOS release 6.8 (Final)
  4. [root@clsn.io /root] clsn.io Blog WebSite
  5. #uname -r
  6. 4.10.5-1.el6.elrepo.x86_64
  7. [root@clsn.io /root] clsn.io Blog WebSite
  8. #sestatus
  9. SELinux status: disabled

1.2 NMP 环境说明

1.2.1. NGINX 配置说明

nginx 编译参数

  1. [root@clsn.io /root] clsn.io Blog WebSite
  2. #nginx -V
  3. nginx version: clsn/41.1
  4. built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)
  5. built with OpenSSL 1.0.2l 25 May 2017
  6. TLS SNI support enabled
  7. configure arguments: --user=www --group=www --prefix=/www/server/nginx --with-openssl=/www/server/nginx/src/openssl
  8. --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module
  9. --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module
  10. --add-module=/www/server/nginx/src/nginx-http-concat --with-http_stub_status_module --with-http_ssl_module
  11. --with-http_v2_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module
  12. --with-stream --with-stream_ssl_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module
  13. --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-pcre=pcre-8.40 --with-ld-opt=-ljemalloc
  14. --add-module=/www/server/nginx/src/ngx_http_google_filter_module
  15. --add-module=/www/server/nginx/src/ngx_http_substitutions_filter_module

nginx zabbix-web 配置

  1. [root@clsn.io /etc/nginx/zclsn] clsn.io Blog WebSite
  2. #cat os.conf
  3. server
  4. {
  5. listen 80;
  6. server_name os.clsn.io;
  7. rewrite ^(.*) https://$host$1 permanent;
  8. }
  9. server
  10. {
  11. listen 443 ssl http2;
  12. server_name os.clsn.io;
  13. index index.php;
  14. root /www/wwwroot/other/os;
  15. include enable-php-56.conf;
  16. #https mode
  17. ssl_certificate /www/cert/clsn.io/fullchain.cer;
  18. ssl_certificate_key /www/cert/clsn.io/clsn.io.key;
  19. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  20. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
  21. ssl_prefer_server_ciphers on;
  22. ssl_session_cache shared:SSL:10m;
  23. ssl_session_timeout 10m;
  24. }

1.2.2 MySql 配置说明

  1. # mysql 可以采用yum 安装 版本在 5.0.3 - 8.0.x 中间均可
  2. # 具体版本要求可以参考: https://www.zabbix.com/documentation/4.0/zh/manual/installation/requirements#%E8%BD%AF%E4%BB%B6
  3. yum install mysql-server -y

创建zabbix 使用的用户

  1. shell> mysql -uroot -p<password>
  2. mysql> create database zabbix character set utf8 collate utf8_bin;
  3. mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '<password>';
  4. mysql> quit;

1.2.3 PHP 配置说明

  1. [root@clsn.io /root] clsn.io Blog WebSite
  2. #php -i |grep configure
  3. Configure Command => './configure' '--prefix=/www/server/php/56' '--with-config-file-path=/www/server/php/56/etc'
  4. '--enable-fpm' '--with-fpm-user=www' '--with-fpm-group=www' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd'
  5. '--with-pdo-mysql=mysqlnd' '--with-iconv-dir' '--with-freetype-dir=/usr/local/freetype' '--with-jpeg-dir'
  6. '--with-png-dir' '--with-zlib' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-bcmath'
  7. '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl=/usr/local/curl' '--enable-mbregex'
  8. '--enable-mbstring' '--with-mcrypt' '--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-openssl=/usr/local/openssl'
  9. '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--with-gettext'
  10. '--disable-fileinfo' '--enable-opcache' '--enable-intl'

2. Zabbix 安装

本次采用源码包安装方式,官方文档参考: https://www.zabbix.com/documentation/4.0/zh/manual/installation/install

2.1 获取软件包

  1. cd /opt
  2. wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz

2.2 部署ZABBIX

  1. cd /opt
  2. # 解压软件包
  3. tar xf zabbix-4.0.3.tar.gz
  4. cd zabbix-4.0.3
  5. # 创建普通用户运行zabbix
  6. groupadd clsn
  7. useradd -g clsn clsn
  8. # 根据自己需求编译 zabbix ,本次编译一次生成zabbix-server 与 zabbix-agentd
  9. ./configure --prefix=/usr/local/zabbix-4.0 --enable-server --enable-agent --with-mysql --enable-ipv6 --with-libcurl --with-libxml2
  10. make
  11. make install
  12. ln -s /usr/local/zabbix-4.0 /usr/local/zabbix

2.3 导入初始化mysql数据

  1. shell> cd /opt/zabbix-4.0.3
  2. shell> cd database/mysql
  3. shell> mysql -uzabbix -p<password> zabbix < schema.sql
  4. # stop here if you are creating database for Zabbix proxy
  5. shell> mysql -uzabbix -p<password> zabbix < images.sql
  6. shell> mysql -uzabbix -p<password> zabbix < data.sql

2.4 复制ZABBIX的WEB文件

  1. cd /opt/zabbix-4.0.3/frontends/
  2. mv php /www/wwwroot/other/os
  3. chown -R clsn.www /www/wwwroot/other/os
  4. chown -R clsn /usr/local/zabbix/

2.5 WEB界面初始化

web界面的配置在这里就不赘述了,与之前的版本相似没有较大的改变,主要要注意权限问题。
浏览器访问 nginx配置的域名 https://os.clsn.io
配置完成后即可登录,初始用户名 Admin 密码 zabbix 。
ZABBIX 4.0 LTS 部署 - 图2

3. zabbix配置

3.1 zabbix-server配置

  1. [root@clsn.io /root] clsn.io Blog WebSite
  2. #cd /usr/local/zabbix/etc/
  3. [root@clsn.io /usr/local/zabbix/etc] clsn.io Blog WebSite
  4. #grep -Ev "^#|^$" zabbix_server.conf
  5. LogFile=/tmp/zabbix_server.log
  6. DBHost=localhost
  7. DBName=zabbix
  8. DBUser=zabbix
  9. DBPassword=password
  10. StartPollers=1
  11. StartPreprocessors=1
  12. StartTrappers=1
  13. StartAlerters=1
  14. ListenIP=127.0.0.1
  15. StartDBSyncers=1
  16. Timeout=4
  17. LogSlowQueries=3000
  18. User=clsn

3.2 zabbix-agentd 配置

  1. [root@clsn.io /usr/local/zabbix/etc] clsn.io Blog WebSite
  2. #grep -Ev "^#|^$" zabbix_agentd.conf
  3. LogFile=/tmp/zabbix_agentd.log
  4. SourceIP=127.0.0.1
  5. Server=127.0.0.1
  6. ListenIP=127.0.0.1
  7. StartAgents=1
  8. ServerActive=127.0.0.1
  9. Hostname=clsn.io
  10. User=clsn
  11. Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf

3.3 复制启动脚本

  1. cd /opt/zabbix-4.0.3/misc/init.d/fedora/core
  2. cp -a zabbix_agentd zabbix_server /etc/init.d/
  3. # 修改脚本中的 BASEDIR
  4. # vim +22 /etc/init.d/zabbix_agentd
  5. BASEDIR=/usr/local/zabbix
  6. # vim +22 /etc/init.d/zabbix_server
  7. BASEDIR=/usr/local/zabbix

4. 安装完成

安装完成后可以使用多种方式添加监控主机,具体操作参考:https://www.cnblogs.com/clsn/p/7885990.html
ZABBIX 4.0 LTS 部署 - 图3

5. 参考文献

https://clsn.io/clsn/lx658.html https://www.zabbix.com/documentation/4.0/zh/manual/installation/install https://www.zabbix.com https://blog.csdn.net/php_thinker/article/details/7241500