搭建Zabbix監控環境

如下步驟,參考了 zabbix官方手冊php

 

監控需求

在搭建步驟以前,仍是整理一下本次的監控需求。mysql

  • 部署搭建簡單,足夠輕量級,
  • 配置簡單,適合菜鳥
  • 能夠監控多臺linux主機的cpu和內存狀態
  • 最好能夠監控日誌
  • 炫酷簡潔的圖形界面

以上,身爲主流監控工具的Zabbix徹底能夠知足。並且,有良好的擴展性,能夠知足日益增加的需求。linux

 

搭建步驟

肯定安裝環境

    1. 安裝ubuntu16.04系統
      ubuntu16.04安裝說明
    2. 更新系統源
      執行 sudo vi /etc/apt/sources.list,修改成:web

    3. # deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
      deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
      deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
      deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
      deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
      deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
      deb http://mirrors.aliyun.com/ubuntu/ xenial universe
      deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
      deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
      deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
      deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
      deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
      deb http://archive.canonical.com/ubuntu xenial partner
      deb-src http://archive.canonical.com/ubuntu xenial partner
      deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
      deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
      deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
      deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
      

       

      安裝Zabbix

        1. 首先更新下apt。
          執行 sudo apt-get update
        2. 而後安裝Zabbix全部依賴環境(能夠不帶版本號,但源裏目前使用7.0,因此就指定一下7.0 ; mysql環境設置密碼爲root就能夠)
          sudo apt-get install apache2 mysql-server php7.0 php7.0-gd libapache2-mod-php7.0 php7.0-mysql php7.0-bcmath php7.0-mbstring php7.0-xml php7.0-ldap
        3. 下載Zabbix安裝
          wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.4-1+xenial_all.deb
          dpkg -i zabbix-release_3.4-1+xenial_all.deb
          sudo apt-get update
        4. 安裝Zabbix的web環境(客戶機只須要安裝zabbix-agent)
          sudo apt-get install zabbix-server-mysql zabbix-frontend-php zabbix-agent

      修改數據庫鏈接

      sudo vim /etc/zabbix/zabbix_server.conf
      修改相關
      DBHost=localhost
      DBName=zabbix
      DBUser=zabbix
      DBPassword=zabbix
      #非必需,但推薦
      StartDiscoverers=5sql

    4. 建立mysql帳號

      mysql -u root -p
      mysql> create database zabbix character set utf8 collate utf8_bin;
      mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';數據庫

      mysql> flush privileges;apache

      mysql> exit;ubuntu

      導入mysql數據

      (password是剛纔設置的zabbix)vim

      cd /usr/share/zabbix-server-mysql/
      sudo gunzip *.gzapi

      mysql -u zabbix -p zabbix < create.sql

      配置php參數

      sudo vi /etc/apache2/conf-enabled/zabbix.conf

      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 Asia/Shanghai

      1. 啓動zabbix服務

        (輸入系統密碼)

        service zabbix-server start

        sudo service apache2 restart

        登陸網頁

        http://HOST_ip/zabbix/
        (填寫mysql的密碼zabbix

        填寫server_name爲zabbix server)

        狂點下一步。

        默認登陸帳號密碼 Admin/zabbix

        修改中文界面

        sudo vi /usr/share/zabbix/include/locales.inc.php 

        第55行,'zh_CN' => ['name' => _('Chinese (zh_CN)'),     'display' => true],

        把display改成true,刷新頁面便可。

        若是仍是不行,參考這裏

        配置客戶端

        zabbix-agent拷貝到home目錄

        而後執行(因爲koala中缺乏一個庫,須要聯網安裝)

        默認配置的服務器地址是192.168.1.200

      2. zabbix-agent.sh

         

         
        #!/bin/bash
        sudo  apt-get  install  libcurl3
        sudo  dpkg -i ~ /zabbix-agent_3 .4.10-1+xenial_amd64.deb
        sudo  sed  -i  '97s/127.0.0.1/192.168.1.200/g'  /etc/zabbix/zabbix_agentd .conf
        sudo  sed  -i  '138s/127.0.0.1/192.168.1.200/g'  /etc/zabbix/zabbix_agentd .conf
        sudo  sed  -i  '105s/# //g'  /etc/zabbix/zabbix_agentd .conf
        sudo  sed  -n  '/^Server=/p'  /etc/zabbix/zabbix_agentd .conf
        sudo  sed  -n  '/^ServerActive=/p'  /etc/zabbix/zabbix_agentd .conf
        sudo  sed  -n  '/^ListenPort=/p'  /etc/zabbix/zabbix_agentd .conf
        sudo  /etc/init .d /zabbix-agent  start
相關文章
相關標籤/搜索