1. 程式人生 > 實用技巧 >ZABBIX 4.0 LTS 部署

ZABBIX 4.0 LTS 部署


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

[[email protected] /root] clsn.io Blog WebSite
#cat  /etc/redhat-release
CentOS release 6.8 (Final)

[[email protected] /root] clsn.io Blog WebSite
#uname  -r
4.10.5-1.el6.elrepo.x86_64

[[email protected] /root] clsn.io Blog WebSite
#sestatus
SELinux status:                 disabled

1.2 NMP 環境說明

1.2.1. NGINX 配置說明

nginx 編譯引數

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

nginx zabbix-web 配置

[[email protected] /etc/nginx/zclsn] clsn.io Blog WebSite
#cat  os.conf
server
{
    listen 80;
    server_name os.clsn.io;
    rewrite ^(.*) https://$host$1 permanent;
}
server
{
    listen 443 ssl http2;
    server_name os.clsn.io;
    index index.php;
    root /www/wwwroot/other/os;
    include enable-php-56.conf;
    #https mode
    ssl_certificate /www/cert/clsn.io/fullchain.cer;
    ssl_certificate_key  /www/cert/clsn.io/clsn.io.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    }

1.2.2 MySql 配置說明

# mysql 可以採用yum 安裝 版本在 5.0.3 - 8.0.x	中間均可
# 具體版本要求可以參考: https://www.zabbix.com/documentation/4.0/zh/manual/installation/requirements#%E8%BD%AF%E4%BB%B6
yum install  mysql-server -y

建立zabbix 使用的使用者

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

1.2.3 PHP 配置說明

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

2. Zabbix 安裝

本次採用原始碼包安裝方式,官方文件參考:https://www.zabbix.com/documentation/4.0/zh/manual/installation/install

2.1 獲取軟體包

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

2.2 部署ZABBIX

cd /opt

# 解壓軟體包
tar xf zabbix-4.0.3.tar.gz 
cd zabbix-4.0.3

# 建立普通使用者執行zabbix
groupadd clsn
useradd -g clsn clsn

# 根據自己需求編譯 zabbix ,本次編譯一次生成zabbix-server 與 zabbix-agentd
./configure --prefix=/usr/local/zabbix-4.0 --enable-server --enable-agent --with-mysql --enable-ipv6 --with-libcurl --with-libxml2
make 
make install
ln -s /usr/local/zabbix-4.0 /usr/local/zabbix

2.3 匯入初始化mysql資料

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

2.4 複製ZABBIX的WEB檔案

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

2.5 WEB介面初始化

web介面的配置在這裡就不贅述了,與之前的版本相似沒有較大的改變,主要要注意許可權問題。
瀏覽器訪問 nginx配置的域名https://os.clsn.io
配置完成後即可登入,初始使用者名稱 Admin 密碼 zabbix 。

3. zabbix配置

3.1 zabbix-server配置

[[email protected] /root] clsn.io Blog WebSite
#cd /usr/local/zabbix/etc/

[[email protected] /usr/local/zabbix/etc] clsn.io Blog WebSite
#grep  -Ev "^#|^$" zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=password
StartPollers=1
StartPreprocessors=1
StartTrappers=1
StartAlerters=1
ListenIP=127.0.0.1
StartDBSyncers=1
Timeout=4
LogSlowQueries=3000
User=clsn

3.2 zabbix-agentd 配置

[[email protected] /usr/local/zabbix/etc] clsn.io Blog WebSite
#grep  -Ev "^#|^$" zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
SourceIP=127.0.0.1
Server=127.0.0.1
ListenIP=127.0.0.1
StartAgents=1
ServerActive=127.0.0.1
Hostname=clsn.io
User=clsn
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf

3.3 複製啟動指令碼

cd /opt/zabbix-4.0.3/misc/init.d/fedora/core
cp -a zabbix_agentd  zabbix_server /etc/init.d/
# 修改指令碼中的 BASEDIR
# vim +22 /etc/init.d/zabbix_agentd 
    BASEDIR=/usr/local/zabbix
# vim +22 /etc/init.d/zabbix_server
    BASEDIR=/usr/local/zabbix

4. 安裝完成

安裝完成後可以使用多種方式新增監控主機,具體操作參考:https://www.cnblogs.com/clsn/p/7885990.html

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