企業實戰之監控升級視覺化zabbix4.0 系列 一
@commandersu
2021-07-20 09:35
字數 18395
閱讀 1694
zabbix簡介前言
常見開源的的監控系統有zabbix ,nagios ,cacti。
nagios的簡單介紹
1,重在監控告警,在這一方面zabbix比他更優秀,告警配置視覺化,web化
2,nagios新增監控需要更改配置檔案。
3,沒有監控的歷史資料,圖形支援差,也就是說只是知道報警,但是沒有記錄原因
4,不支援分佈時候監控系統。
比如:不支援分散式部署
Cacti的簡單介紹
1,重在採集伺服器。網路裝置的監控資料並繪圖
2,依賴於snmp協議
3,不好自定義監控
4,告警支援不友好
zabbix的簡單介紹
1,所有監控配置都web化,web採用php開發
2,支援分散式監控
3,支援多種方式資料採集:簡單監控,agent監控,snmp介面,jmx介面監控
4,告警配置web化:郵件,微信,釘釘,簡訊
5,zaabix和grafana的結合方便監控資料的視覺化
比如:支援
zabbix監控的搭建簡單理論
1,zabbix server會去採集監控資料,採集的監控資料會寫入到sql資料庫
2,zabbix的web後端採用的php語言開發,所有的配置資訊,使用者認證等都會寫入到sql資料庫。
3,企業級zabbix的搭建依賴環境:主流採用LNMP(centos7+nginx+mysql+php)
4,環境下使用者請求流程
使用者->nginx—>php-fpm->執行php程式->操作mysql
zabbix工作原理圖
zabbix 由以下幾個元件部分構成:
>1) Zabbix Server:
負責接收 agent 傳送的報告資訊的核心元件,所有配置,統計資料及操作資料均由其組
織進行;
---
>2) Database Storage:
專用於儲存所有配置資訊,以及由 zabbix 收集的資料;
---
>3) Web interface:
zabbix 的 GUI 介面,通常與 Server 執行在同一臺主機上;
---
>4) Proxy:
可選元件,常用於分佈監控環境中,代理 Server 收集部分被監控端的監控資料
並統一發往 Server 端;
---
>5) Agent:
部署在被監控主機上,負責收集本地資料併發往 Server 端或 Proxy 端;
注:zabbix node 也是 zabbix server 的一種 。
---
>程序
預設情況下zabbix包含5個程式: zabbix_agentd、 zabbix_get、 zabbix_proxy、
zabbix_sender、zabbix_server,另外一個 zabbix_java_gateway 是可選,這個需要另
外安裝
---
下面來分別介紹下他們各自的作用:
abbix_agentd客
戶端守護程序,此程序收集客戶端資料,例如 cpu 負載、記憶體、硬碟使用情況等。
---
>zabbix_get
zabbix 工具,單獨使用的命令,通常在 server 或者proxy端執行獲取遠端客戶端資訊的
命令。 通常使用者排錯。 例如在server端獲取不到客戶端的記憶體資料, 我們可以使用
zabbix_get獲取客戶端的內容的方式來做故障排查。
---
>zabbix_sender
zabbix 工具,用於傳送資料給 server 或者proxy,通常用於耗時比較長的檢查。很多檢
查非常耗時間,導致 zabbix 超時。於是我們在指令碼執行完畢之後,使用 sender 主動提
交資料。
---
>zabbix_server
zabbix 服務端守護程序。zabbix_agentd、zabbix_get、zabbix_sender、
zabbix_proxy、zabbix_java_gateway 的資料最終都是提交到 server
備註:當然不是資料都是主動提交給 zabbix_server,也有的是 server 主動去取資料。
---
>zabbix_proxy
zabbix 代理守護程序。功能類似server,唯一不同的是它只是一箇中轉站,它需要把收
集到的資料提交/被提交到 server 裡。
---
>zabbix_java_gateway
zabbix2.0 之後引入的一個功能。顧名思義:Java 閘道器,類似 agentd,但是隻用於
Java方面。需要特別注意的是,它只能主動去獲取資料,而不能被動獲取資料。 它的數
據最終會給到server或者proxy。
---
zabbix監控環境中相關術語
#主機(host) :
要監控的網路裝置,可由 IP 或 DNS 名稱指定;
---
#主機組(host group):
主機的邏輯容器,可以包含主機和模板,但同一個組織內的主機和模板不能互相連結;
主機組通常在給使用者或使用者組指派監控許可權時使用;
---
#監控項(item) :
一個特定監控指標的相關的資料;這些資料來自於被監控物件;item是 zabbix 進行數
據收集的核心,相對某個監控物件,每個 item 都由"key"標識;
---
#觸發器(trigger) :
一個表示式,用於評估某監控物件的特定 item 內接收到的資料是否在合理範圍內,也就
是閾值;接收的資料量大於閾值時,觸發器狀態將從"OK"轉變為"Problem",當資料再
次恢復到合理範圍,又轉變為"OK";
---
#事件(event) :
觸發一個值得關注的事情,比如觸發器狀態轉變,新的 agent 或重新上
線的 agent 的自動註冊等;
---
#動作(action) :
指對於特定事件事先定義的處理方法,如傳送通知,何時執行操作;
---
#報警媒介型別(media) :
傳送通知的手段或者通道,如 Email、Jabber 或者 SMS 等;
---
#模板 (template) :
用於快速定義被監控主機的預設條目集合, 通常包含了 item、 trigger、graph、
screen、 application 以及 low-level discovery rule;模板可以直接連結至某個主機;
---
#前端(frontend) :
Zabbix 的 web 介面
zabbix各種相關元件關係圖
一搭建zabbix
1搭建環境
作業系統 | 主機名 | ip | 記憶體 |
---|---|---|---|
centos7.5 | zabbix | 192.168.200.173 | 1G |
1.1搭建nginx
[root@zabbix ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@zabbix ~]# setenforce 0
setenforce: SELinux is disabled
[root@zabbix ~]# systemctl stop firewalld
[root@zabbix ~]# systemctl stop NetworkManager
[root@zabbix ~]# ls
anaconda-ks.cfg nginx-1.16.1.tar.gz
[root@zabbix ~]# yum install -y wget gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel
#安裝支援程式我們原始碼編譯
[root@zabbix ~]# tar xf nginx-1.16.1.tar.gz -C /usr/src/
[root@zabbix ~]# cd /usr/src/nginx-1.16.1/
[root@zabbix nginx-1.16.1]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
[root@zabbix nginx-1.16.1]# ./configure --prefix=/usr/local/nginx && make && make install
#編譯安裝
[root@zabbix nginx-1.16.1]# ln -s /usr/local/nginx/sbin/* /usr/bin/ #將命令連結出來
[root@zabbix nginx-1.16.1]#which nginx
#檢視有了nginx的命令
/usr/bin/nginx
[root@zabbix nginx-1.16.1]# cd /usr/local/nginx/conf/
[root@zabbix conf]# ls
fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params
fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default
fastcgi_params koi-win nginx.conf scgi_params.default win-utf
[root@zabbix conf]# egrep -v "#|^$" nginx.conf.default > nginx.conf
#精簡配置檔案
[root@zabbix conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
[root@zabbix conf]# 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@zabbix conf]# /usr/local/nginx/sbin/nginx
#啟動nginx
[root@zabbix conf]# ss -antup | grep 80
tcp LISTEN 0 128 *:80 *:* users:(("nginx",pid=18266,fd=6),("nginx",pid=18265,fd=6))
#檢視下nginx的埠有沒有開
#使用systemctl管理nginx
[root@zabbix conf]# vim /usr/lib/systemd/system/nginx.service
[Unit] #這個模組主要是對服務的描述
Description=nginx #描述服務是什麼
After=network.target # 描述服務的類別
[Service] #是服務的具體執行引數
Type=forking #後臺執行的形式
ExecStart=/usr/local/nginx/sbin/nginx #啟動命令
[Install] #服務安裝的相關設定
WantedBy=multi-user.target
#測試一下啊systemctl管理(如果這裡有問題,請重啟下伺服器就可以了)
[root@zabbix conf]# ss -antup | grep 80
tcp LISTEN 0 128 *:80 *:* users:(("nginx",pid=1213,fd=6),("nginx",pid=1212,fd=6))
[root@zabbix conf]# systemctl stop nginx
[root@zabbix conf]# ss -antup | grep 80
[root@zabbix conf]#
#開啟
[root@zabbix conf]# systemctl start nginx
[root@zabbix conf]# ss -antup | grep 80
tcp LISTEN 0 128 *:80 *:* users:(("nginx",pid=1249,fd=6),("nginx",pid=1248,fd=6))
1.2關於systemctl管理服務引數說明
- [Service]部分是服務的關鍵,是服務的一些具體執行引數的設定
- Type=forking是後臺執行的形式,
- PIDFile為存放PID的檔案路徑,
- ExecStart為服務的執行命令,
- ExecReload為重啟命令,
- ExecStop為停止命令,
- rivateTmp=True表示給服務分配獨立的臨時空間,
*注意:[Service]部分的啟動、重啟、停止命令全部要求使用絕對路徑,使用相對路徑則會報錯;
1.3在瀏覽器上驗證下nginx
二搭建php
php和nginx結合使用是有2中方式的,
1是socket方式(這個方式需要兩個服務在同一個伺服器上)
2是網路方式,這樣的可以不在同一個服務其上 (預設是網路)
2.1編譯安裝php
[root@zabbix conf]# cd ~
[root@zabbix ~]# wget http://hk1.php.net/distributions/php-5.6.40.tar.gz #現在5.64安裝包
[root@zabbix ~]# yum -y install epel-release #用yum安裝一個epel源,這個檔案是擴充套件的一些服務的源
[root@zabbix ~]# yum -y clean all
[root@zabbix ~]# yum makecache
[root@zabbix ~]# yum -y install gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel libmcrypt libmcrypt-devel
[root@zabbix ~]# wget https://www.php.net/distributions/php-5.6.40.tar.gz
[root@zabbix ~]# echo "$?"
0
[root@zabbix ~]# ls
anaconda-ks.cfg nginx-1.16.1.tar.gz php-5.6.40.tar.gz
[root@zabbix ~]# tar xf php-5.6.40.tar.gz -C /usr/src/
[root@zabbix ~]# cd /usr/src/php-5.6.40/
[root@zabbix php-5.6.40]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-ctype --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir --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 --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-fpm
#出現一下的式樣就ok了
Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
[root@zabbix php-5.6.40]# make && make install
php主要編譯安裝說明
- [x]--prefix指定php的安裝目錄
- [x]--with-config-file-path指定php的配置檔案位置
- [x]--with-mysql、--with-mysqli讓php可以操作mysql
- [x]--enable-fpm主要是nginx要來呼叫php語言得使用php-fpm
2.2啟動php
[root@zabbix php-5.6.40]# tail -1 /etc/profile #新增環境變數
export PATH=$PATH:/usr/local/php/sbin/:/usr/local/php/bin/
[root@zabbix php-5.6.40]# source /etc/profile #讓他立即生效
[root@zabbix php-5.6.40]# php-fpm -t #檢測一下配置檔案有沒有錯誤,現在報錯是因為沒有配置檔案在裡面,我們需要複製一份過去,
[04-Nov-2019 10:04:15] ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)
[04-Nov-2019 10:04:15] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
[04-Nov-2019 10:04:15] ERROR: FPM initialization failed
[root@zabbix php-5.6.40]# ls php.ini-
php.ini-development php.ini-production
# deve是開發環境的,production是生產環境的
[root@zabbix php-5.6.40]# cp php.ini-production /usr/local/php/etc/php.ini
[root@zabbix php-5.6.40]# cd /usr/local/php/etc/
[root@zabbix etc]# ls
pear.conf php-fpm.conf.default php.ini
[root@zabbix etc]# cp php-fpm.conf.default php-fpm.conf
[root@zabbix etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[root@zabbix etc]# php-fpm -t
[04-Nov-2019 10:16:00] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
[root@zabbix etc]# php-fpm -v
PHP 5.6.40 (fpm-fcgi) (built: Nov 4 2019 09:37:11)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
#使用systemctl將php管理起來,並啟動
[root@zabbix etc]# cat /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
[Install]
WantedBy=multi-user.target
[root@zabbix etc]# systemctl start php-fpm
[root@zabbix etc]# ss -antup | grep 9000
tcp LISTEN 0 128 127.0.0.1:9000 *:* users:(("php-fpm",pid=8872,fd=0),("php-fpm",pid=8871,fd=0),("php-fpm",pid=8870,fd=7))
2.3修改nginx的配置,讓php和nginx連用起來
[root@zabbix etc]# cd /usr/local/nginx/conf/
[root@zabbix conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm index.php; #必須加上.php結尾的主頁,要不然nginx呼叫動態的時候找不到回直接報錯就不找了
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #去哪裡尋找php檔案。
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
[root@zabbix conf]# 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@zabbix conf]# nginx -s reload
[root@zabbix conf]# cd /usr/local/nginx/html/
[root@zabbix html]# touch index.php #裡邊什麼都不用寫
[root@zabbix html]# cat test.php
<?php
echo "mr.su it's ok";
?>
2.4驗證php+nginx是否連線成功
三mysql資料庫安裝
3.1搭建mysql資料庫
[root@zabbix html]# cd ~
[root@zabbix ~]# wget https://www.mysql.com//Downloads/MySQL-5.6/mysql-5.6.39.tar.gz
[root@zabbix ~]# ls
anaconda-ks.cfg mysql-5.6.39.tar.gz nginx-1.16.1.tar.gz php-5.6.40.tar.gz
[root@zabbix ~]# yum install -y gcc gcc-c++ make tar openssl openssl-devel cmake ncurses ncurses-devel
[root@zabbix ~]# useradd -M -s /sbin/nologin mysql
[root@zabbix ~]# tar xf mysql-5.6.39.tar.gz -C /usr/src/
[root@zabbix ~]# cd /usr/src/mysql-5.6.39/
[root@zabbix mysql-5.6.39]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=all -DWITH_DEBUG=0 -DWITH_SSL=yes -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1
[root@zabbix mysql-5.6.39]# echo "$?"
0
[root@zabbix mysql-5.6.39]# make && make install
[root@zabbix mysql-5.6.39]# echo "$?"
0
[root@zabbix mysql-5.6.39]# cp support-files/mysql.server /etc/init.d/mysqld
[root@zabbix mysql-5.6.39]# chmod +x /etc/init.d/mysqld
[root@zabbix mysql-5.6.39]# tail -1 /etc/profile #修改環境變數,本質是要伺服器找到命令,所以做軟連線也是可以的
export PATH=$PATH:/usr/local/mysql/bin/
#修改配置檔案
[root@zabbix mysql-5.6.39]# cat /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
datadir=/data/mysql
user=mysql
skip-name-resolve
long_query_time=2
slow_query_log_file=/data/mysql/mysql-slow.log
expire_logs_days=2
innodb-file-per-table=1
innodb_flush_log_at_trx_commit = 2
log_warnings = 1
max_allowed_packet = 512M
connect_timeout = 60
net_read_timeout = 120
[mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid
重要的編譯選項說明
- [x] CMACK_INSTALL_PREFIX指定安裝的目錄
- [x] MYSQL_DATADIR指定Mysql的資料目錄
3.2初始化資料庫
[root@zabbix mysql-5.6.39]# mkdir -p /data/mysql #建立資料目錄
[root@zabbix mysql-5.6.39]# chown -R mysql:mysql /usr/local/mysql /data/mysql/ #分別對資料目錄,和執行目錄授權
[root@zabbix mysql-5.6.39]# yum install -y perl-Module-Install #初始資料庫的一個依賴程式
[root@zabbix mysql-5.6.39]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --user=mysql --datadir=/data/mysql/ #初始完成以後輸出的特別像亂碼,往上看,找到兩個ok就初始化完成了
[root@zabbix mysql-5.6.39]# cat /usr/lib/systemd/system/mysqld.service #使用systemctl管理mysql
[Unit]
Description=mysqld
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/mysqld start
[Install]
WantedBy=multi-user.target
[root@zabbix mysql-5.6.39]# systemctl start mysqld
[root@zabbix mysql-5.6.39]# ss -antup | grep 3306
tcp LISTEN 0 80 *:3306 *:* users:(("mysqld",pid=26225,fd=10))
3.3給mysql建立zabbix賬號並驗證連線
[root@zabbix mysql-5.6.39]# cd ~
[root@zabbix ~]# mysqladmin -h 127.0.0.1 -u root password 'zabbixpwd'
Warning: Using a password on the command line interface can be insecure.
[root@zabbix ~]# echo "$?"
0
[root@zabbix ~]# mysql -uroot -pzabbixpwd -h 127.0.0.1
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.39 Source distribution
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.200.%' IDENTIFIED BY 'zabbixpwd' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
[root@zabbix ~]# mysql -uroot -pzabbixpwd -h 192.168.200.173 #驗證密碼在遠處登入
mysql> exit
[root@zabbix ~]# cat /usr/local/nginx/html/test_mysql.php #建立測試nginx+php+mysql 的測試檔案
<?php
$link=mysql_connect("127.0.0.1","root","zabbixpwd");
if(!$link) echo "FAILD!連線錯誤,使用者名稱密碼不對";
else echo "OK!可以連線";
?>
3.4通過http://192.168.200.173/test_mysqsl.php
四搭建zabbix4.0
4.1下載並編譯安裝zabbix
[root@zabbix ~]# yum install -y libevent-devel wget tar gcc gcc-c++ make net-snmp-devel libxml2-devel libcurl-devel #yum安裝zabbix的支援程式
[root@zabbix ~]# useradd -M -s /sbin/nologin zabbix
[root@zabbix ~]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz #下載zabbix4.0的原始碼包
[root@zabbix ~]# ls
anaconda-ks.cfg mysql-5.6.39.tar.gz nginx-1.16.1.tar.gz php-5.6.40.tar.gz zabbix-4.0.3.tar.gz
[root@zabbix ~]# tar xf zabbix-4.0.3.tar.gz -C /usr/src/
[root@zabbix ~]# cd /usr/src/zabbix-4.0.3/
[root@zabbix zabbix-4.0.3]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2
#出現以下的就ok了
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
[root@zabbix zabbix-4.0.3]# make && make install
[root@zabbix zabbix-4.0.3]# tail -1 /etc/profile #修改變數檔案,使其能找到命令
export PATH=$PATH:/usr/local/zabbix/sbin/:/usr/local/zabbix/bin/
[root@zabbix zabbix-4.0.3]# source /etc/profile #立即生效
[root@zabbix zabbix-4.0.3]# zabbix_server --version
zabbix_server (Zabbix) 4.0.3
Revision 87993 20 December 2018, compilation time: Nov 13 2019 09:44:17
Copyright (C) 2018 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.
選項說明
- --prefix指定安裝目錄
- --enable-server安裝zabbix server
- --enable-agent安裝zabbix agent
- --with-mysql用mysql來儲存
4.2初始化zabbix資料庫,啟動zabbix
[root@zabbix zabbix-4.0.3]# mysql -h 127.0.0.1 -uroot -pzabbixpwd
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@'127.0.0.1' identified by 'zabbixpwd';
Query OK, 0 rows affected (0.04 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)
mysql> set names utf8; #設定編碼
Query OK, 0 rows affected (0.00 sec)
mysql> use zabbix; #切換資料庫準備導表
Database changed
mysql> source /usr/src/zabbix-4.0.3/database/mysql/schema.sql #開始導表,不要順序亂了
mysql> source /usr/src/zabbix-4.0.3/database/mysql/data.sql
mysql> source /usr/src/zabbix-4.0.3/database/mysql/images.sql #導表完成
#修改zabbix的配置檔案
[root@zabbix zabbix-4.0.3]# cd /usr/local/zabbix/etc/
[root@zabbix etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d
[root@zabbix etc]# cp zabbix_server.conf zabbix_server.conf.bak
[root@zabbix etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.bak zabbix_server.conf.d
[root@zabbix etc]# cat zabbix_server.conf
LogFile=/usr/local/zabbix/zabbix_server.log
DBHost=127.0.0.1
DBName=zabbix
DBUser=zabbix
DBPassword=zabbixpwd
DBPort=3306
Timeout=30
AlertScriptsPath=/usr/local/zabbix/alertscripts #放置我們微信告警,以及郵件告警指令碼的位置。
ExternalScripts=/usr/local/zabbix/externalscripts
LogSlowQueries=3000
#一定要把配置檔案裡的#號都刪掉
#啟動zabbix
[root@zabbix etc]# chown zabbix:zabbix -R /usr/local/zabbix/ #給目錄降權
[root@zabbix etc]# zabbix_server #啟動zabbix,命令就是zabbix
[root@zabbix etc]# ss -lntup | grep 10051 #檢視埠,server端已經啟動
tcp LISTEN 0 128 *:10051
[root@zabbix etc]# mkdir -p /usr/local/nginx/html/zabbix
[root@zabbix etc]# cp -a /usr/src/zabbix-4.0.3/frontends/php/* /usr/local/nginx/html/zabbix/ #將所有的zabbix的網頁複製到nginx下
4.3在web介面登入zabbix
使用ip登入。ip/zabbix
#修改php的檔案
[root@zabbix etc]# vim /usr/local/php/etc/php.ini
#將以下幾行修改成這個樣子
660:post_max_size = 32M
372:max_execution_time = 350
382:max_input_time = 350
936:date.timezone = Asia/Shanghai
702:always_populate_raw_post_data = -1
[root@zabbix etc]# systemctl restart php-fpm #重啟php
[root@zabbix etc]# ss -antup | grep 9000
tcp LISTEN 0 128 127.0.0.1:9000 *:* users:(("php-fpm",pid=42895,fd=0),("php-fpm",pid=42894,fd=0),("php-fpm",pid=42893,fd=7))
root@zabbix ~]# ls
anaconda-ks.cfg mysql-5.6.39.tar.gz nginx-1.16.1.tar.gz php-5.6.40.tar.gz zabbix-4.0.3.tar.gz zabbix.conf.php
[root@zabbix ~]# mv zabbix.conf.php /usr/local/nginx/html/zabbix/conf/
[root@zabbix ~]# cat /usr/local/nginx/html/zabbix/conf/zabbix.conf.php #裡面改就是我們剛剛形成的一些內容
<?php
// Zabbix GUI configuration file.
global $DB;
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = '127.0.0.1';
$DB['PORT'] = '3306';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = 'zabbixpwd';
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';
$ZBX_SERVER = 'localhost';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = '';
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
4.4禁用沒用的使用者
4.5修改超戶的密碼
4.6zabbix網頁漢化補丁包
[root@zabbix ~]# ls /usr/local/nginx/html/zabbix/fonts/ #這個目錄裡放著的就是zabbix的字型,但是沒有中文字型所以會出現亂碼,我們的解決方法就是下載個字型覆蓋到這
DejaVuSans.ttf
[root@zabbix ~]# wget https://raw.githubusercontent.com/chenqing/ng-mini/master/font/msyh.ttf #下載字型的網址。
[root@zabbix ~]# ls
anaconda-ks.cfg msyh.ttf mysql-5.6.39.tar.gz nginx-1.16.1.tar.gz php-5.6.40.tar.gz zabbix-4.0.3.tar.gz
[root@zabbix ~]# mv msyh.ttf /usr/local/nginx/html/zabbix/fonts/
[root@zabbix ~]# ls /usr/local/nginx/html/zabbix/fonts/
DejaVuSans.ttf msyh.ttf
[root@zabbix ~]# vim /usr/local/nginx/html/zabbix/include/defines.inc.php #修改php檔案裡的預設,將DejaVuSans字型,改成msyh微軟雅黑字型
65 define('ZBX_GRAPH_FONT_NAME', 'msyh'); // font file name
110 define('ZBX_FONT_NAME', 'msyh'); #將65行和110行替換成這個樣子。
#php插入的不像java之類的需要編譯類檔案等,直接就可以使用。