centos7安裝配置zabbix4.0


zabbix01    198.8.8.211    zabbix-server4.0

zabbix02    198.8.8.212    zabbix-agent4.0

一:zabbix服務端環境部署:

  1.1部署LAMP環境:zabbix中web監控管理界面,需要LNMP架構支持

yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash  

    1.1.1:配置httpd:

      ServerName zabbix01.zm.com:80

      <IfModule dir_module>
        DirectoryIndex index.html index.php
      </IfModule>

    1.1.2:配置php:

      date.timezone = PRC

    1.1.3:啟動httpd,mysql

      關閉防火牆

      systemctl stop firewalld

      systemctl disabled firewalld

      關閉selinux

      setenforce 0

      getenforce

      vim /etc/sysconfig/selinux

      SELINUX=enforcing改為SELINUX=disabled

      reboot

      systemctl start httpd

      systemctl start mariadb

      netstat -ntap | grep '(80|3306)'

    mysql啟動后執行初始安全設置:

      

[root@zabbix01 ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): \\回車
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] n
 ... skipping.

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] n
 ... skipping.

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

  

    1.1.4:創建測試頁:

      [root@zabbix01 ~]# vim /var/www/html/index.php

<?php

phpinfo();

?>

:wq

     

       [root@zabbix01 ~]# mysql -u root -p

      MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin; 

        //創建zabbix數據庫(中文編碼格式)

      MariaDB [(none)]> GRANT all  ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zzz';

         //授予zabbix用戶zabbix數據庫的所有權限,密碼zzz

      MariaDB [(none)]> flush privileges;

        //刷新權限

      MariaDB [(none)]> quit

      [root@zabbix01 ~]# vim /var/www/html/index.php

         //修改測試頁內容,測試zabbix用戶是否能夠登陸數據庫    

<?php
$link=mysql_connect('198.8.8.211','zabbix','zz');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
mysql_close();
?>

      查詢mysql用戶:

        SELECT User, Host, Password FROM mysql.user;  

MariaDB [(none)]> select User, Host  FROM mysql.user;
+--------+-----------+
| User   | Host      |
+--------+-----------+
| zabbix | %         |
| root   | 127.0.0.1 |
| root   | ::1       |
|        | localhost |
| root   | localhost |
|        | zabbix01  |
| root   | zabbix01  |
+--------+-----------+
7 rows in set (0.00 sec)

        新建zabbix用戶

MariaDB [(none)]> GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zzz';
MariaDB [(none)]> GRANT all ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY 'zzz';
MariaDB [(none)]> GRANT all ON zabbix.* TO 'zabbix'@'zabbix01' IDENTIFIED BY 'zzz';

  

MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user   | host      |
+--------+-----------+
| zabbix | %         |
| root   | 127.0.0.1 |
| root   | ::1       |
|        | localhost |
| root   | localhost |
| zabbix | localhost |
|        | zabbix01  |
| root   | zabbix01  |
| zabbix | zabbix01  |
+--------+-----------+
9 rows in set (0.00 sec)
MariaDB [(none)]> flush privileges; 

      瀏覽器訪問http://198.8.8.211/

       上圖說明php連通數據庫完成。

 

二:部署zabbix server:https://www.zabbix.com/download

  安裝php支持的zabbix組件:

    [root@zabbix01 ~]# yum install php-bcmath php-mbstring -y

  yum源文件獲取:

    [root@zabbix01 ~]# rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm

  安裝zabbix組件:

    [root@zabbix01 ~]# yum install zabbix-server-mysql zabbix-web-mysql -y

  自動生成數據庫文件:

    [root@zabbix01 ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.1/create.sql.gz | mysql -u zabbix(用戶名) -p zabbix(庫名)

  修改zabbix配置文件:

    grep -n '^'[a-Z] /etc/zabbix/zabbix_server.conf

    vim /etc/zabbix/zabbix_server.conf

      ListenPort=10051

      LogFile=/var/log/zabbix/zabbix_server.log

      LogFileSize=0

      PidFile=/var/run/zabbix/zabbix_server.pid

      SocketDir=/var/run/zabbix

      DBName=zabbix

      DBUser=zabbix

      DBPassword=zzz

      DBPort=3306

      SNMPTrapperFile=/var/log/snmptrap/snmptrap.log

      ListenIP=198.8.8.211

      Timeout=4

      AlertScriptsPath=/usr/lib/zabbix/alertscripts

      ExternalScripts=/usr/lib/zabbix/externalscripts

      LogSlowQueries=3000

    

   修改zabbix在httpd中的時區:

    vim /etc/httpd/conf.d/zabbix.conf

    <IfModule mod_php5.c>
        php_value date.timezone Asia/Shanghai
        php_value max_execution_time 300
        php_value memory_limit 128M
        php_value post_max_size 16M
        php_value upload_max_filesize 2M
        php_value max_input_time 300
        php_value max_input_vars 10000
        php_value always_populate_raw_post_data -1
        # php_value date.timezone Europe/Riga
    </IfModule>

  

  啟動zabbix及httpd服務:

    systemctl enable zabbix-server

    systemctl start zabbix-server

    netstat -anpt | grep zabbix 

    systemctl restart httpd.service

  web界面訪問:

    http://198.8.8.211/zabbix/

 

 

 

 

 

 

 

設置中文:Administrator-Users-Admin-Language

 

web界面亂碼:


方法一:

       如web界面中文亂碼,需要復制相應文字,使zabbix識別

  下載STKAITI.TTF字體拷貝到如下路徑:

    cp STKAITI.TTF /usr/share/zabbix/fonts/

  使zabbix系統識別字體

    vim /usr/share/zabbix/include/defines.inc.php

     :%s /graphfont/kaiti/g //采用全局替換模式

方法二:

  復制C:\Windows\Fonts下的簡黑字體

   

 

  拷貝到/usr/share/fonts/dejavu/simhei.ttf

  進入/etc/alternatives

   刪除名為zabbix-web-font的軟連接

  重建軟連接:

    ln -s /usr/share/fonts/dejavu/simhei.ttf zabbix-web-font

 

登陸后報錯:

正常安裝完zabbix后,登錄后zabbix監控報錯zabbix server is not running: the information displayed may not be current

[root@zabbix zabbix]# find / -name zabbix.conf.php
/etc/zabbix/web/zabbix.conf.php
[root@zabbix zabbix]# vim /etc/zabbix/web/zabbix.conf.php

<?php
// Zabbix GUI configuration file.
global $DB;

$DB['TYPE']     = 'MYSQL';
$DB['SERVER']   = '192.168.8.8';
$DB['PORT']     = '3306';
$DB['DATABASE'] = 'zabbix01';
$DB['USER']     = 'zabbix01';
$DB['PASSWORD'] = 'z';

// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';

$ZBX_SERVER      = '192.168.8.8';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'Zabbix01';

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

 

如還報錯:

netstat -lnp | zabbix

查看端口10051是否開啟

如未開啟:

vi /etc/zabbix/zabbix_server.conf

DBHost=x.x.x.x

重啟zabbix-server:

systemctl status zabbix-server

 

三:配置被監控端-如果監控服務器需要監控自己,也需要安裝配置:

  CentOS7添加方法:

  3.1安裝zabbix-agent客戶端

  3.1.1配置zabbix yum源:

     rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm

  3.1.2安裝客戶端:

    yum install -y zabbix-agent

  3.1.3修改agent配置文件:

    [root@zabbix02 ~]# vim /etc/zabbix/zabbix_agentd.conf 

      PidFile=/var/run/zabbix/zabbix_agentd.pid

      LogFile=/var/log/zabbix/zabbix_agentd.log

      LogFileSize=0

      Server=198.8.8.211

      ListenPort=10050

      ServerActive=198.8.8.211

      Hostname=zabbix01

      Include=/etc/zabbix/zabbix_agentd.d/*.conf

  3.1.4 關閉防火牆

      [root@zabbix02 ~]# systemctl stop firewalld

  3.1.5 關閉selinux

      [root@zabbix02 ~]# setenforce 0

      [root@zabbix02 ~]# vim /etc/selinux/config

#SELINUX=enforcing
SELINUX=disabled

  3.1.6啟動zabbix-agent

      [root@zabbix02 ~]# systemctl start zabbix-agent.service

      [root@zabbix02 ~]# systemctl enable zabbix-agent.service

 

  Windows添加方法:

    官方安裝方法:

      https://www.zabbix.com/download

    下載windows包:

      https://www.zabbix.com/download_agents

      zabbix_agents-4.0.0-win-amd64

    解壓后得到bin和conf兩個文件夾:

    修改配置文件D:\Program Files\Zabbix\conf\zabbix_agentd.win.conf

      修改下面幾項 

      EnableRemoteCommands=1 #允許在本地執行遠程命令 
      LogRemoteCommands=1 #執行遠程命令是否保存操作日志 
      Server = 172.16.20.90 #填寫zabbix服務器IP地址 
      ListenPort=10050
      Hostname= Zabbix server #zabbix_agent監控服務器名稱 (監控主機名稱) 
      Log=c:\zabbix_agentd.log 
      ServerActive=172.16.20.90 #填寫zabbix服務器IP地址


    
新建cmd快捷方式,以管理員身份運行

    安裝zabbix客戶端:

      d:\program files\zabbix\bin\zabbix_agentd.exe -i -c d:\program files\zabbix\conf\zabbix_agentd.win.conf

    中間不可有空格:

      d:\zabbix\bin\zabbix_agentd.exe -i -c d:\zabbix\conf\zabbix_agentd.win.conf

    啟動zabbix客戶端:

      d:\zabbix\bin\zabbix_agentd.exe -s -c d:\zabbix\conf\zabbix_agentd.win.conf

C:\Windows\system32>d:\program files\zabbix\bin\zabbix_agentd.exe -i -c d:\program files\zabbix\conf\zabbix_agentd.win.conf
'd:\program' 不是內部或外部命令,也不是可運行的程序
或批處理文件。

C:\Windows\system32>d:\zabbix\bin\zabbix_agentd.exe -i -c d:\zabbix\conf\zabbix_agentd.win.conf
zabbix_agentd.exe [5640]: service [Zabbix Agent] installed successfully
zabbix_agentd.exe [5640]: event source [Zabbix Agent] installed successfully

C:\Windows\system32>d:\zabbix\bin\zabbix_agentd.exe -s -c d:\zabbix\conf\zabbix_agentd.win.conf
zabbix_agentd.exe [7624]: service [Zabbix Agent] started successfully

  

 

 

 

四:在zabbix服務器添加被監控機      

   4.1創建主機:

     配置-主機-創建主機

 

 

 

 

五:報警配置:

  5.1郵件報警:

    [root@zabbix01 ~]# yum install mailx -y

    [root@zabbix01 ~]# vim /etc/mail.rc

    添加:

set from=xxx@163.com
set smtp=smtp.163.com
set smtp-auth-user=xxx@163.com
set smtp-auth-password=123456
set smtp-auth=login

    測試郵件發送:

[root@zabbix01 ~]# echo 'hello' | mail -s 'testmail' zm_cm@163.com

  5.2設置郵件發送腳本:

[root@zabbix01 ~]# vim /usr/lib/zabbix/alertscripts/mailx.sh

  

#!/bin/bash
#send mail

messages=`echo $3 | tr '\r\n' '\n'`
subject=`echo $2 | tr '\r\n' '\n'`
echo "${messages}" | mail -s "${subject}" $1 >>/tmp/mailx.log 2>&1
        touch /tmp/mailx.log
        chown -R zabbix.zabbix /tmp/mailx.log
        chmod +x /usr/lib/zabbix/alertscripts/mailx.sh
        chown -R zabbix.zabbix /usr/lib/zabbix/

  添加可執行權限:

[root@zabbix01 ~]# chmod +x /usr/lib/zabbix/alertscripts/mailx.sh

  測試發件:

[root@zabbix01 ~]# /usr/lib/zabbix/alertscripts/mailx.sh zm_cm@163.com  '111''222'

  5.3配置zabbix自動觸發腳本

 

 

 

 

告警主機:{HOST.NAME}
告警IP:{HOST.IP}
告警時間:{EVENT.DATE}-{EVENT.TIME}
告警等級:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}:{ITEM.VALUE}
事件ID:{EVENT.ID}

持續時間需改為60s,否則會報錯:字段 "esc_period": 必須在 "60" 和 "604800" 之間 值錯誤。

 

 

 

 六:監控腳本配置

   6.1 io監控腳本:

UserParameter=custom.vfs.dev.read.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$4}' //磁盤讀的次數 
UserParameter=custom.vfs.dev.read.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$7}' //磁盤讀的毫秒數
UserParameter=custom.vfs.dev.write.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$8}' //磁盤寫的次數
UserParameter=custom.vfs.dev.write.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$11}' //磁盤寫的毫秒數
UserParameter=custom.vfs.dev.io.active[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$12}'
UserParameter=custom.vfs.dev.io.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$13}' //花費在IO操作上的毫秒數
UserParameter=custom.vfs.dev.read.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$6}' //讀扇區的次數(一個扇區的等於512B)
UserParameter=custom.vfs.dev.write.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$10}' //寫扇區的次數(一個扇區的等於512B)

  6.2 重啟zabbix-agent服務

    [root@zabbix01 ~]# systemctl restart zabbix-agent

  6.3 登陸web頁面添加模板

 

七:zabbix-server主機ip修改后web報錯

  7.1:修改 vim /etc/zabbix/zabbix_server.conf 中ip

  7.2:修改 vim /etc/zabbix/web/zabbix.conf.php 中ip

<?php
// Zabbix GUI configuration file.
global $DB;

$DB['TYPE']     = 'MYSQL';
$DB['SERVER']   = '192.168.1.6';
$DB['PORT']     = '3306';
$DB['DATABASE'] = 'zabbix01';
$DB['USER']     = 'zabbix01';
$DB['PASSWORD'] = 'xxxxxx';

// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';

$ZBX_SERVER      = '192.168.1.6';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'zabbix01';

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

 

 

 

參考:

https://blog.csdn.net/rujianxuezha/article/details/79842998

https://www.linuxidc.com/Linux/2018-10/154773.htm


免責聲明!

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



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