linux(centos8):lnmp環境編譯安裝zabbix5.0


一,zabbix的用途:

zabbix是一個基於WEB界面的提供分布式系統監視以及網絡監視功能的企業級的開源解決方案

zabbix能監視各種網絡參數,保證服務器系統的安全運營;

並提供靈活的通知機制以讓系統管理員快速定位/解決存在的各種問題

zabbix由2部分構成:  zabbix server/運行在被監控端的zabbix agent

 

說明:劉宏締的架構森林是一個專注架構的博客,地址:https://www.cnblogs.com/architectforest

         對應的源碼可以訪問這里獲取: https://github.com/liuhongdi/

說明:作者:劉宏締 郵箱: 371125307@qq.com

 

二,准備好lnmp環境:

1,需要的環境文檔:

https://www.zabbix.com/documentation/current/manual/installation/requirements

 

2,需要的軟件環境

php:7.2.0及以上

mysql: 5.5.62及以上

需要的php擴展包括:

gd: 2.0.28及以上
bcmath
ctype
libXML: 2.6.15及以上
session
sockets
mbstring
gettext

 

三,下載zabbix的源碼安裝包

1,官方下載站:

http://repo.zabbix.com/zabbix/

 

清華的國內鏡像站:

https://mirrors.tuna.tsinghua.edu.cn/zabbix/

 

2,創建下載目錄:

[root@blog zabbix]# mkdir /usr/local/source/zabbix

 

3,下載:

[root@blog zabbix]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.0.tar.gz

 

四,安裝zabbix5.0

1,官方的安裝文檔地址:

https://www.zabbix.com/documentation/current/manual/installation/install

 

2,解壓縮:

[root@blog zabbix]# tar -zxvf zabbix-5.0.0.tar.gz 
[root@blog zabbix]# cd zabbix-5.0.0/

 

3,創建zabbix用戶

[root@blog zabbix-5.0.0]# groupadd --system zabbix
[root@blog zabbix-5.0.0]# useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix

 

4,創建zabbix賬號的home目錄

[root@blog zabbix-5.0.0]# mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
[root@blog zabbix-5.0.0]# chown zabbix:zabbix /usr/lib/zabbix

 

5,創建zabbix數據庫

創建數據庫的文檔地址

https://www.zabbix.com/documentation/current/manual/appendix/install/db_scripts

 

sql語句:

創建數據庫

create database zabbix character set utf8 collate utf8_bin

創建zabbix數據庫賬號

create user 'zabbix'@'127.0.0.1' identified by 'zabbixpass';

給zabbix數據庫賬號授權

grant all privileges on zabbix.* to 'zabbix'@'127.0.0.1';

刷新數據庫權限數據

flush PRIVILEGES;

 

6,導入數據:

說明:切換到源碼目錄/database/mysql/目錄下后執行:

[root@blog mysql]$ /usr/local/soft/mysql/bin/mysql -uzabbix -pzabbixpass zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@blog mysql]$
/usr/local/soft/mysql/bin/mysql -uzabbix -pzabbixpass zabbix < images.sql mysql: [Warning] Using a password on the command line interface can be insecure.
[root@blog mysql]$
/usr/local/soft/mysql/bin/mysql -uzabbix -pzabbixpass zabbix < data.sql mysql: [Warning] Using a password on the command line interface can be insecure.

 

7,configure與安裝

在源碼目錄下執行configure

[root@blog zabbix-5.0.0]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2  

安裝

[root@blog zabbix-5.0.0]# make install

 

說明:configure時報錯的解決:

報錯1:

configure: error: MySQL library not found

解決:

[root@blog zabbix-5.0.0]# dnf install mysql-devel

 

報錯2:

configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config

解決:

[root@blog zabbix-5.0.0]# dnf install -y net-snmp-devel

 

報錯3:

configure: error: Unable to use libevent (libevent check failed)

解決:

[root@blog zabbix-5.0.0]# dnf install libevent-devel  -y

 

報錯4:

configure: error: Unable to use libpcre (libpcre check failed)

解決:

[root@blog zabbix-5.0.0]# dnf -y install pcre*

 

8,查看安裝效果:

查看zabbix_server的版本

[root@blog zabbix-5.0.0]# /usr/local/soft/zabbx-5.0.0/sbin/zabbix_server --version
zabbix_server (Zabbix) 5.0.0
Revision 9665d62db0 11 May 2020, compilation time: May 17 2020 09:37:03

Copyright (C) 2020 Zabbix SIA
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.

 

查看zabbix_agentd的版本

[root@blog zabbix-5.0.0]# /usr/local/soft/zabbx-5.0.0/sbin/zabbix_agentd --version
zabbix_agentd (daemon) (Zabbix) 5.0.0
Revision 9665d62db0 11 May 2020, compilation time: May 17 2020 09:37:03

Copyright (C) 2020 Zabbix SIA
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.

 

五,配置zabbix_server

編輯配置文件

[root@blog etc]# vi zabbix_server.conf

主要配置項:

LogFile=/data/zabbix_server/logs/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPort=3306

創建日志目錄

[root@blog etc]# mkdir /data/zabbix_server/logs

 

六,配置zabbix_agentd

編輯配置文件

[root@blog etc]# vi zabbix_agentd.conf

主要配置項:

LogFile=/data/zabbix_agentd/logs/zabbix_agentd.log
Server=127.0.0.1
ServerActive=127.0.0.1 
Hostname=jdweb

 創建日志目錄

[root@blog etc]# mkdir /data/zabbix_agentd/logs

 

七,啟動zabbix_server

[root@blog etc]# /usr/local/soft/zabbx-5.0.0/sbin/zabbix_server

 

八,啟動zabbix_agentd

[root@blog etc]# /usr/local/soft/zabbx-5.0.0/sbin/zabbix_agentd

 

九,為nginx配置zabbix用來做web管理的虛擬主機

創建網站root目錄

[root@blog conf.d]# mkdir /data/dweb/zabbix

配置虛擬主機:

說明:這個文件要放到nginx的配置文件所在目錄下,

我的機器上是:/usr/local/openresty/nginx/conf/conf.d,

大家根據自己機器上nginx的安裝情況創建這個虛擬主機即可

[root@blog conf.d]# vi zabbix.conf 

內容:

server {
    listen       80;
    server_name  zabbix.lhdtest.net;
    root         /data/dweb/zabbix/html;
    index   index.php index.html index.shtml  index.htm;
    access_log      /data/logs/nginxlogs/zabbix.access_log;
    error_log       /data/logs/nginxlogs/zabbix.error_log;

    location / {
            try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_buffer_size 32k;
        fastcgi_buffers 10240 32k;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

配置完成后重啟nginx

九,配置web界面

1,復制ui目錄下的文件到虛擬主機目錄下

[root@blog ui]# pwd
/usr/local/source/zabbix/zabbix-5.0.0/ui
[root@blog ui]# cp -axv ./ /data/dweb/zabbix/html/ 

 

2,訪問url

http://zabbix.lhdtest.net/

會自動跳轉到:

http://zabbix.lhdtest.net/setup.php

 

看截圖,點next step

如果不滿足zabbix配置的需求,更新php后重啟php-fpm

無問題后點next step

 

數據庫配置:輸入數據庫密碼

 此處輸入保持默認即可,點next step按鈕繼續

這個頁面顯示我們配置的一個摘要,繼續點 next step按鈕

看到這個頁面,表示安裝無問題,點finish結束

 

3,如果安裝過程中提示不能保存配置文件,

修改conf目錄的權限:

[root@blog html]# chmod 766 /data/dweb/zabbix/html/conf/*

 

4,跳轉到登錄界面后:

用默認賬號登錄:

The default user name is Admin, password zabbix.

默認賬號:

用戶名:Admin

密碼:zabbix

 

十,登錄后配置中文/解決中文亂碼/修改默認密碼

1,配置中文,解決中文亂碼,參見:

https://www.cnblogs.com/architectforest/p/12911721.html

 

2,web界面修改默認密碼:

用默認密碼登錄后

左側菜單->User settings->點 修改密碼 按鈕

修改為自定義密碼后

點 更新 按鈕即可

 

十一,使用systemd管理zabbix-server的服務

編輯zabbix-server的service文件

[root@blog system]# vi /usr/lib/systemd/system/zabbix-server.service 

內容:

[Unit]
Description=Zabbix Server
After=network.target
After=mysqld.service

[Service]
Environment="CONFFILE=/usr/local/soft/zabbx-5.0.0/etc/zabbix_server.conf"
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/soft/zabbx-5.0.0/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0

[Install]
WantedBy=multi-user.target

重新加載service文件

[root@blog system]# systemctl daemon-reload

啟動命令:

[root@blog system]# systemctl start zabbix-server.service

停止命令:

[root@blog system]# systemctl stop zabbix-server.service

 

十二,查看centos版本:

[root@blog nginxlogs]$ cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM