[Monitoring] 在CentOS 中安裝Zabbix

Zabbix 是一套功能強大的監控工具, 除了監察基建狀況及通報外, 它還支援discovery, 即是安裝了Agent 後, server 便會自行找出並進行基本監管設定. 與之前用的Nagios 比較的確更方便. 在示範會於CentOS進行安裝 Zabbix  Server 及其Linux Agent.

前期配置: 安裝及設定 MariaDB

  1. 安裝 MariaDB.
    利用root 權限, 執行以下指令.

    yum install -y mariadb-server
    systemctl enable mariadb
    systemctl start mariadb
  2. 初始設定 Maria DB.
    利用root 權限, 執行以下指令.

    mysql_secure_installation
  3. 於Maria DB 建立Zabber database 及相關user 設定.
    執行以下指令.

    mysql -u root -p

    之後於MariaDB shell 中, 輸入以下指令.

    create database zabbix; 
    grant all privileges on zabbix.* to zabbix@'localhost' identified by '<<Zabbix_User_Password>>'; 
    grant all privileges on zabbix.* to zabbix@'%' identified by '<<Zabbix_User_Password>>'; 
    flush privileges;

前期配置: Httpd 及PHP

  1. 加入 EPAL (Extra Packages for Enterprise Linux) 及 webtatic repository.
    利用root 權限, 執行以下指令.

    yum -y install epel-release
    rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
  2. 安裝Httpd 及PHP.
    利用root 權限, 執行以下指令.

    # For HTTPD installation.
    yum install -y httpd
    # For PHP and related modules.
    yum -y install mod_php72w php72w-cli php72w-common php72w-devel php72w-pear php72w-gd php72w-mbstring php72w-mysql php72w-xml php72w-bcmath
    
    systemctl enable httpd
  3. 設定PHP.
    利用Root 權限開啟/etc/php.ini, 並修改以下設定.

    max_execution_time = 600
    max_input_time = 600
    memory_limit = 1024M
    post_max_size = 32M
    upload_max_filesize = 16M
    date.timezone = Asia/Hong_Kong
  4. 啟動Httpd.
    利用root 權限, 執行以下指令.

    systemctl start httpd

安裝及設定Zabbix

  1. 加入Zabbix repository.
    利用root 權限, 執行以下指令.

    rpm -ivh https://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
    yum-config-manager --enable rhel-7-server-optional-rpms
  2. 安裝Zabbix Server 及Web for MySQL.
    利用root 權限, 執行以下指令.

    yum install -y zabbix-get zabbix-server-mysql zabbix-web-mysql
  3. 加入Zabbix database tables.
    利用root 權限, 執行以下指令.

    # Unzip Zabbix MySQL script.
    cd /usr/share/doc/zabbix-server-mysql-3.4.6/
    gunzip create.sql.gz
    
    # Import to MariaDB.
    mysql -u root -p zabbix < create.sql
  4. 設定Zabbix Server.
    利用root 權限, 開啟/etc/zabbix/zabbix_server.conf, 並修改以下內容.

    DBHost=localhost
    DBPassword=<<Zabbix_User_Password>>
  5. 執行Zabbix Server.
    利用root 權限, 執行以下指令.

    systemctl enable zabbix-server
    systemctl start zabbix-server

     

安裝及設定 Zabbix Agent

  1. 安裝 Zabbix Agent.
    利用root 權限, 執行以下指令.

    yum install -y zabbix-agent

     

  2. 設定 Zabbix Agent.
    利用root 權限, 開啟/etc/zabbix/zabbix_server.conf, 並修改以下內容.

    # Zabbix Server IP/ Hostname.
    # In this case, as Server and agent are locate in same PC, so it can set as 127.0.0.1.
    Server=127.0.0.1
    
    # Zabbix Server Proxy IP / Hostname.
    ServerActive=127.0.0.1
    
    # Identity name in Zabbix
    Hostname=Agent_Test
  3. 啟動Agent.
    systemctl enable zabbix-agent
    systemctl start zabbix-agent

Optional: Firewalld 設定

若本身Linux 已設定了Firewalld, 則須要設定firewall rule 去接收資料. 需要的protocol 及port 如下:

程式 所需 Protocal / port
HTTPD HTTP (TCP port 80) / HTTPS (TCP port 443)
Zabbix Server TCP port 10051
Zabbix Agent TCP port 10050
  1. 設定Firewalld.
    利用root 權限, 執行以下指令.

    firewall-cmd --add-service={http,https} --permanent
    firewall-cmd --add-port={10051/tcp,10050/tcp} --permanent

初始設定Zabbix.

因為忘了take screenshots, 所以只能從Google 中找來. 若有冒犯在此謝過.

  1. 開啟Zabbix webpage.
    利用瀏覽器開啟網頁, 預設網址為:

    http://<<Zabbix_Server_IP / Zabbix_Host_Name>>/zabbix

    開啟後會見到Welcome page, 按 Next Step 繼續進行.

  2. 檢查系統設定.
    Zabbix 會檢查系統要求是否達到, 確定一切OK後按Next Step 繼續.
  3. Zabbix database 設定.
    Zabbix 會設定database, 輸入正確資料後按Next Step 繼續.
  4. Zabbix 系統設定.
    在此會設定Zabbix server, 因設定用了原廠設定, 故可直接按Next Step 繼續.
  5. Zabbix summary.
    確定資料正確後, 可按Next Step 繼續.
  6. 設定完成. 可以按Finish 離開.
  7. 進行測試.
    重新進入版面, 在登入版面的User 輸入admin, Password 輸入zabbix. 之後按Sign In 登入.
  8. 若見到admin dashboard 版面, 代表登入成功.

參考資料

About C.H. Ling 260 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.