NO.A.0003——zabbix_lnmp_zabbix.server/zabbix.agent編譯安裝教程_V2020.1029
阿新 • • 發佈:2020-11-18
ZABBIX監控平臺部署(LNMP+ZABBIX.Server原始碼安裝部署)
Zabbix Server端和Zabbix Agent執行如下程式碼:
Zabbix監控平臺部署,至少需要安裝四個元件,分別是Zabbix_Server、Zabbix_Web、Databases、Zabbix_Agent,如下為Zabbix監控平臺安裝配置詳細步驟:
部署環境:
Server端 ————>192.168.1.59 Agent端 ————>192.168.1.60 CentOS版本 ————>CentOS 7.6.1810 ZABBIX版本 ————>Zabbix 4.0.19
1、下載zabbix版本,各個版本之間安裝方法相差不大,可以根據實際情況選擇安裝版本,本文版本為Zabbix-4.0.25.tar.gz。
2、編譯安裝zabbix-server:// zabbix原始碼下載地址(建議從官網下載): // https://www.zabbix.com/download_sources#tab:40LTS //OR [root@localhost ~]# wget -c https://cdn.zabbix.com/zabbix/sources/stable/4.0/ > zabbix-4.0.25.tar.gz //-c:斷點續傳 [root@localhost ~]# md5sum zabbix-4.0.25.tar.gz //檢視他的md5值 0694c540b1d014cdc5c6a50d361d77f2 zabbix-4.0.25.tar.gz //因為zabbix基於C語言開發;安裝編譯時依賴包、庫檔案: [root@localhost ~]# yum -y install gcc curl curl-devel net-snmp net-snmp-devel perl-DBI > libxml2-devel libevent-devel pcre mysql-devel //建立使用者和使用者組: [root@localhost ~]# groupadd zabbix [root@localhost ~]# useradd -g zabbix zabbix [root@localhost ~]# usermod -s /sbin/nologin zabbix
//解壓zabbix-4.0.25.tar.gz [root@localhost ~]# tar -xzvf zabbix-4.0.25.tar.gz //-x extract解壓,-z gzip壓縮,-v verbose詳細,-f file檔案 //zabbix-server編譯安裝,需要通過原始碼部署三個步驟: //預編譯: [root@localhost zabbix-4.0.25]# ./configure --prefix=/usr/local/zabbix --enable-server --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 [root@localhost zabbix-4.0.25]# ./configure --help |more /檢視每個引數的含義, // --prefix=/usr/local/zabbix :原始碼安裝目錄絕對路徑 // --enable-server : 開啟核心元件server; // --with-mysql=原始碼地址 :若mysql是原始碼安裝的,需把mysql的安裝庫指導原始碼的安裝目錄; // --enable-ipv6 :開啟IPV6,後續支援IPV6監控, // --with-net-snmp:通過snmp監控客戶端 // --with-libcurl:支援curl,去獲取網頁的關鍵詞,做web監控是用到庫檔案 // --with-libxml2:web介面 //編譯 [root@localhost zabbix-4.0.25]# make //安裝: [root@localhost zabbix-4.0.25]# make install //新增軟連結(相當於快捷方式);啟動指令碼要找/usr/local/sbin;不然啟動時會報錯 [root@localhost ~]# ln -s /usr/local/zabbix/sbin/zabbix_* /usr/local/sbin/ // 將/usr/local/zabbix/etc/zabbix_server.conf配置檔案中程式碼設定為如下: [root@localhost ~]#cp /usr/local/zabbix/etc/zabbix_server.conf zabbix-server.conf.bak [root@localhost ~]#vim /usr/local/zabbix/etc/zabbix_server.conf LogFile=/tmp/zabbix_server.log DBHost=localhost //資料庫主機 顯示NO的話DBHost=127.0.0.1 DBName=zabbix //資料庫名稱 DBUser=zabbix //資料庫使用者名稱 DBPassword=123456 //資料庫密碼 #DBSocket=/var/lib/mysql/mysql.sock //資料庫mysql.sock檔案
//同時cp zabbix_server啟動指令碼至/etc/init.d/目錄,
//啟動zabbix_server Zabbix_server預設監聽埠為10051
[root@localhost zabbix-4.0.25]#cp misc/init.d/tru64/zabbix_server /etc/init.d/zabbix_server
[root@localhost ~]# chmod o+x /etc/init.d/zabbix_server
[root@localhost ~]# /etc/init.d/zabbix_server restart
[root@localhost ~]# netstat -tunlp |grep -aw 10051
tcp 0 0 0.0.0.0:10051 LISTEN 6195/zabbix_server
tcp6 0 0 :::10051 LISTEN 6195/zabbix_server
3、部署Zabbix-WEB、LNMP(Linux+Nginx+Mariadb+PHP)//安裝epel-release擴充套件源:
[root@localhost ~]# yum install epel-release -y
[root@localhost ~]# ll /etc/yum.repos.d/|grep -aw epel //檢視有沒有如下兩個檔案
-rw-r--r-- 1 root root 951 Oct 3 2017 epel.repo
-rw-r--r-- 1 root root 1050 Oct 3 2017 epel-testing.repo
#安裝nginx軟體包;
[root@localhost ~]# yum install -y nginx
#安裝Mariadb(資料庫)、PHP、PHP-FPM環境;
//待確定[root@localhost ~]# yum install -y mariadb-server mariadb-devel php php-devel php-fpm
[root@localhost ~]# yum install -y mariadb-server mariadb-devel php php-cli
> php-common php-gd php-ldap php-mbstring php-mcrypt php-mysql php-pdo php-fpm
3.1、配置Mariadb database//安裝Mariadb database
[root@localhost ~]# systemctl start mariadb.service //啟動資料庫
[root@localhost ~]# msyql_secure_installation //設定Mariadbroot初始化密碼
[root@localhost ~]# mysql -uroot -p123456
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
//建立資料庫,名稱為zabbix並且字元為utf8
MariaDB [(none)]> create user 'zabbix'@'localhost' identified by '123456';
//建立zabbix使用者並設定密碼
MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'localhost';
//授權zabbix使用者從localhost訪問,對zabbix資料庫有完全控制權限
MariaDB [(none)]> flush privileges; //重新整理許可權
MariaDB [(none)]> exit // 退出
// 用原始碼安裝的話需手動將Zabbix基礎SQL檔案匯入資料至Zabbix資料庫:
[root@localhost ~]# cd zabbix-4.0.25
[root@localhost ~]# mysql -uzabbix -p123456 zabbix <database/mysql/schema.sql
[root@localhost ~]# mysql -uzabbix -p123456 zabbix <database/mysql/images.sql
[root@localhost ~]# mysql -uzabbix -p123456 zabbix < database/mysql/data.sql
// 切換到zabbix資料庫之下:
[root@localhost ~]# mysql -uroot -p123456
MariaDB [(none)]> use zabbix; //切到zabbix使用者之下
MariaDB [zabbix]> show tables; // 檢視資料匯入是否成功
3.2、配置nginx和php-fpm//配置nginx和php-fpm整合,執行方案如下:
[root@localhost ~]# cd /etc/nginx/
[root@localhost nginx]# vim nginx.conf //檢視nginx.conf檔案
//配置nginx.conf.default檔案有PHP檔案程式碼的配置
[root@localhost nginx]# vim nginx.conf.default
location / { //第二步
root html;
index index.php index.html index.htm; //加上nginx.php表示引導頁。
location ~ \.php$ {
root /usr/share/nginx/html; //更改釋出目錄 //第一步
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
//新增$document_root;表示釋出目錄 //第三步
include fastcgi_params;
}
//檢視nginx.conf.default檔案並去掉#號空行。
[root@localhost nginx]# grep -vE "#|^$" nginx.conf.default
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65; //以上為全域性配置
server { //以下為server主機的配置
listen 80;
server_name localhost;
location / { //location /是正常匹配,處於正則匹配後執行。
root html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ { //location ~是正則匹配,是優先匹配,
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
//把修改後的nginx.conf.default檔案覆蓋掉nginx.conf的預設檔案內容
[root@localhost nginx]# grep -vE "#|^$" nginx.conf.default >nginx.conf
[root@localhost nginx]# systemctl start php-fpm.service //啟動php-fpm服務
[root@localhost nginx]# netstat -tunlp |grep 9000
tcp 0 0 127.0.0.1:9000 LISTEN 9719/php-fpm: maste
[root@localhost nginx]# ps -ef |grep php
root 9068 8641 0 02:29 pts/0 00:00:00 grep --color=auto php
[root@localhost nginx]# netstat -tunlp |grep -aw 9000
tcp 0 0 127.0.0.1:9000 LISTEN 5759/php-fpm: pool
[root@localhost nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost nginx]# systemctl restart nginx.service
//拷貝Zabbix-web網站程式至Nginx釋出目錄,檔案位置在/root/zabbix-4.0.25/frontends/php
[root@localhost php]# \cp -a /root/zabbix-4.0.25/frontends/php/* /usr/share/nginx/html/
//反斜槓表示強制拷貝不提示。
4、啟動所有服務,並設定開機自啟動。//啟動並配置開機自啟動程式:
[root@localhost ~]# /etc/init.d/zabbix_server restart
[root@localhost ~]# systemctl start mariadb.service
[root@localhost ~]# systemctl start nginx.service
[root@localhost ~]# systemctl start php-fpm.service
//併為其執行enable操作,設定開機自啟動
5、通過Zabbix Web GUI安裝設定:通過瀏覽器Zabbix_WEB驗證,通過瀏覽器訪問http://192.168.1.59 如上異常錯誤解決方法程式碼如下,安裝缺失的軟包,並修改php.ini對應引數的值即可:
[root@localhost ~]# yum install php-mbstring php-bcmath php-gd php-xml -y
[root@localhost ~]# yum install gd gd-devel -y //解決上圖報錯問題
[root@localhost ~]# sed -i '/post_max_size/s/8/16/g;/max_execution_time/s/30/300/g;
> /max_input_time/s/60/300/g;s/\;date.timezone.*/date.timezone
> \= PRC/g;s/\;always_populate_raw_post_data/always_populate_raw_post_data/g' /etc/php.ini
[root@localhost ~]# systemctl start php-fpm.service
配置資料庫連線,輸入資料庫名、使用者、密碼,單擊Test
connection,顯示OK,單擊下一步即可填寫Zabbix
Title顯示,可以為空,可以輸入自定義的名稱檢視安裝前摘要,確認資訊是否正確:需修建立zabbix.conf.php檔案,執行如下命令,zabbix.conf.php內容程式碼如下。或者單擊“Download the configuration file”下載zabbix.conf.php檔案,並將該檔案上傳至/usr/share/nginx/html/conf/,並設定可寫許可權。重新整理WEB頁面,最後單擊Finish即可:<?php
// Zabbix GUI configuration file.
global $DB;
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = 'localhost';
$DB['PORT'] = '0';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = '123456';
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';
$ZBX_SERVER = 'localhost';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'ZABBIX監控系統';
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
重新整理頁面顯示:恭喜你!你已安裝zabbix前端;登入Zabbix
WEB介面,預設使用者名稱和密碼為:Admin/zabbixzabbix後臺管理介面:6、原始碼編譯安裝Zabbix Agent端(本機)
1、下載zabbix版本,各個版本之間安裝方法相差不大,可以根據實際情況選擇安裝版本,本文版本為Zabbix-4.0.25.tar.gz。
// zabbix原始碼下載地址(建議從官網下載):
// https://www.zabbix.com/download_sources#tab:40LTS
//OR
[root@localhost ~]#
> wget -c https://cdn.zabbix.com/zabbix/sources/stable/4.0/zabbix-4.0.25.tar.gz //-c:斷點續傳
[root@localhost ~]# md5sum zabbix-4.0.25.tar.gz //檢視他的md5值
0694c540b1d014cdc5c6a50d361d77f2 zabbix-4.0.25.tar.gz
//因為zabbix基於C語言開發;安裝編譯時依賴包、庫檔案://本機不用安裝,編譯zabbix_server時已安裝
[root@localhost ~]# yum -y install gcc curl curl-devel net-snmp net-snmp-devel perl-DBI
> libxml2-devel libevent-devel pcre mysql-devel
2、編譯安裝zabbix-Agent://解壓zabbix-4.0.25.tar.gz
[root@localhost ~]# tar -xzvf zabbix-4.0.25.tar.gz
//-x extract解壓,-z gzip壓縮,-v verbose詳細,-f file檔案
//zabbix-server編譯安裝,需要通過原始碼部署三個步驟:
//1、預編譯:
[root@localhost zabbix-4.0.25]# ./configure --prefix=/usr/local/zabbix --agent-server
> --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
[root@localhost zabbix-4.0.25]# ./configure --help |more /檢視每個引數的含義,
// --prefix=/usr/local/zabbix :原始碼安裝目錄絕對路徑
// --enable-agent : 開啟核心元件agent;
// --with-mysql=原始碼地址 :若mysql是原始碼安裝的,需把mysql的安裝庫指導原始碼的安裝目錄;
// --enable-ipv6 :開啟IPV6,後續支援IPV6監控,
// --with-net-snmp:通過snmp監控客戶端
// --with-libcurl:支援curl,去獲取網頁的關鍵詞,做web監控是用到庫檔案
// --with-libxml2:web介面
//2、編譯
[root@localhost zabbix-4.0.25]# make
//3、安裝:
[root@localhost zabbix-4.0.25]# make install
//4、新增軟連結(相當於快捷方式);啟動指令碼要找/usr/local/sbin;不然啟動時會報錯
[root@localhost ~]# ln -s /usr/local/zabbix/sbin/zabbix_agentd /usr/local/sbin/
//5、同時cp zabbix_server啟動指令碼至/etc/init.d/目錄,
// 啟動zabbix_agent Zabbix_agent預設監聽埠為10050
[root@localhost zabbix-4.0.25]#cp misc/init.d/tru64/zabbix_agentd /etc/init.d/zabbix_agentd
[root@localhost ~]# chmod o+x /etc/init.d/zabbix_agentd
[root@localhost ~]# /etc/init.d/zabbix_agentd restart
zabbix-agent的監聽埠為10050[root@localhost ~]# netstat -tunlp |grep -aw 10050
tcp 0 0 0.0.0.0:10050 LISTEN 14210/zabbix_agentd
tcp6 0 0 :::10050 LISTEN 14210/zabbix_agentd
注:學習地址:https://ke.qq.com/user/index/index.html#/plan/cid=2025906&tid=102127284&term_id=102127284
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart ——W.S.Landor
來自為知筆記(Wiz)