title: Zabbix 系統概述與部署(1)
date: 2018-12-09 09:40:28
tags:php
Zabbix是一個很是強大的監控系統,是企業級的軟件,來監控IT基礎設施的可用性和性能.它是一個可以快速搭建起來的開源的監控系統,Zabbix能監視各類網絡參數,保證服務器系統的安全運營,並提供靈活的通知機制以讓系統管理員快速定位解決存在的各類問題,Zabbix系統幾乎可用於任何系統的監控過程,它能夠運行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X,等平臺上.html
Zabbix 是什麼?java
Zabbix 是一個高度集成的網絡監控解決方案,能夠提供企業級的開源分佈式監控解決方案,由一個國外的團隊持續維護更新,軟件能夠自由下載使用,運做團隊靠提供收費的技術支持贏利.mysql
Zabbix能夠對網絡和服務進行監控,Zabbix利用靈活的告警機制,可實現微信、短信和郵件的自動報警.Zabbix利用存儲的監控數據提供監控報告及實現圖形化顯示,linux
Zabbix支持polling和trapping兩種方式,全部的Zabbix報告均可以經過配置參數在WEB界面進行訪問,你能夠經過Web界面實時查看網絡和服務的監控情況,無論你是小型組織仍是大規模的公司.Zabbix均可以經過不通的配置來扮演監控你的IT基礎框架的角色,Zabbix是零成本的,由於Zabbix編寫和發佈基於GPL V2協議,意味着源代碼是免費發佈的.web
1.在開始安裝軟件以前,須要配置yum源與zabbix源,這裏咱們就使用163的YUM源吧.sql
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo [root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo [root@localhost ~]# rpm -ivh http://repo.zabbix.com/zabbix/4.1/rhel/7/x86_64/zabbix-release-4.1-1.el7.noarch.rpm
2.因爲Zabbix須要一個Web展示出頁面來,因此在這裏咱們須要自行安裝一個LAMP或LNMP環境.數據庫
[root@localhost ~]# yum install -y mariadb mariadb-server httpd php php-mysql Package 1:mariadb-5.5.60-1.el7_5.x86_64 already installed and latest version Package 1:mariadb-server-5.5.60-1.el7_5.x86_64 already installed and latest version Package httpd-2.4.6-88.el7.centos.x86_64 already installed and latest version Package php-5.4.16-46.el7.x86_64 already installed and latest version Package php-mysql-5.4.16-46.el7.x86_64 already installed and latest version Nothing to do
3.接着安裝Zabbix組件,這裏因爲是YUM安裝因此直接執行yum install
就搞定了.apache
[root@localhost ~]# yum install -y net-snmp zabbix-web zabbix-agent zabbix-server-mysql zabbix-web-mysql Package 1:net-snmp-5.7.2-37.el7.x86_64 already installed and latest version Package zabbix-web-4.2.0-0.1alpha1.el7.noarch already installed and latest version Package zabbix-agent-4.2.0-0.1alpha1.el7.x86_64 already installed and latest version Package zabbix-server-mysql-4.2.0-0.1alpha1.el7.x86_64 already installed and latest version Package zabbix-web-mysql-4.2.0-0.1alpha1.el7.noarch already installed and latest version Nothing to do
4.配置Zabbix表結構,建立MariaDB用戶並用於Zabbix受權使用,並恢復Zabbix表結構.vim
[root@localhost ~]# systemctl start mariadb [root@localhost ~]# systemctl enable mariadb [root@localhost ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.60-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; MariaDB [(none)]> exit [root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pzabbix zabbix
5.將Zabbix的頁面文件拷貝到指定目錄(跟apache配置的相同便可).
[root@localhost ~]# cp -a /usr/share/zabbix/* /var/www/html/ [root@localhost ~]# chmod 755 -R /var/www/html/ [root@localhost ~]# chown apache.apache -R /var/www/html/* [root@localhost ~]# systemctl restart httpd [root@localhost ~]# systemctl enable httpd
6.修改PHP配置文件,在PHP配置文件的末尾添加便可,主要目的是調整一下PHP參數,不然Zabbix不經過.
[root@localhost ~]# vim /etc/php.ini date.timezone = Asia/Shanghai max_execution_time = 300 max_input_time = 300 post_max_size = 32M memory_limit = 128M mbstring.func_overload = 0
7.配置Zabbix Server端配置文件,主要目的是定義數據庫的IP、用戶名、密碼等.
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf DBHost=localhost #監控主機數據庫IP,這裏是本地 DBName=zabbix #數據庫名 DBUser=zabbix #訪問,數據庫的用戶名 DBPassword=zabbix #訪問,數據庫訪問密碼
8.全部工做配置完成之後,啓動一下Zabbix進程和Apache服務.
systemctl restart httpd systemctl restart mariadb systemctl restart zabbix-server systemctl restart zabbix-agent
9.拓展環節:若是你的Zabbix登錄密碼忘記了,你可使用如下命令找回來.
MariaDB [(none)]> update zabbix.users set passwd=md5(123123) where name="Zabbix";
10.解決中文亂碼問題,並登錄系統看結果吧.
#在windows系統中:Win+R -> fonts -> 拷貝微軟雅黑字體更名爲 msyh.ttf [root@localhost ~]# cp -a msyh.ttf /var/www/html/fonts// [root@localhost ~]# vim /var/www/html/include/defines.inc.php #修改 zabbix php 頁面配置,將'DejaVuSans' 修改成 'msyh' 65 define('ZBX_GRAPH_FONT_NAME', 'msyh'); // font file name [root@localhost ~]# systemctl restart httpd 用戶名:Admin 密碼:zabbix
1.在監控以前咱們首先要安裝一個工具,就是Zabbix的客戶端組件.
[RHEL6] [root@localhost ~]# wget http://repo.zabbix.com/zabbix/4.1/rhel/6/x86_64/zabbix-agent-4.2.0-0.1alpha1.el6.x86_64.rpm [root@localhost ~]# rpm -ivh zabbix-agent-4.2.0-0.1alpha1.el6.x86_64.rpm [RHEL7] [root@localhost ~]# wget http://repo.zabbix.com/zabbix/4.1/rhel/7/x86_64/zabbix-agent-4.2.0-0.1alpha1.el7.x86_64.rpm [root@localhost ~]# rpm -ivh zabbix-agent-4.2.0-0.1alpha1.el7.x86_64.rpm
2.編輯Zabbix客戶端配置文件,指定Zabbix服務器的IP地址.
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf Server=192.168.1.10 #填寫Server的IP地址 ServerActive=192.168.1.10 #修改成Server的IP地址 Hostname=centos_01 #填寫本機的HostName
3.啓動Zabbix客戶端進程,並設置開機自啓動.
[root@localhost ~]# systemctl restart zabbix-agent [root@localhost ~]# systemctl enable zabbix-agent [root@localhost ~]# /usr/sbin/zabbix_agentd
1.首先下載監控Windows的客戶端組件,並修改一下配置文件.
https://assets.zabbix.com/downloads/3.4.6/zabbix_agents_3.4.6.win.zip https://www.zabbix.com/downloads/4.0.0/zabbix_agents-4.0.0-win-amd64.zip 修改文件:zabbix_agentd.win.conf Server=192.168.1.10 #填寫Server的IP地址 ServerActive=192.168.1.10 #修改成Server的IP地址 Hostname=centos_01 #填寫本機的HostName
2.打開命令行,並啓動相應服務便可.
zabbix_agentd.exe -c C:\zabbix\conf\zabbix_agentd.win.conf -i #將進程添加到 windows 服務管理 zabbix_agentd.exe -c C:\zabbix\conf\zabbix_agentd.win.conf -s #開啓服務
1.因爲Zabbix是基於Web界面的,因此在編譯安裝Zabbix以前,咱們應該準備好一個LAMP或者LNMP的系統環境,來確保Zabbix可以經過Web展示出來.
[root@localhost ~]# yum install -y gcc httpd httpd-devel mariadb mariadb-server mariadb-devel php php-mysql php-common php-gd php-xml Package gcc-4.8.5-36.el7.x86_64 already installed and latest version Package httpd-2.4.6-88.el7.centos.x86_64 already installed and latest version Package httpd-devel-2.4.6-88.el7.centos.x86_64 already installed and latest version Package 1:mariadb-5.5.60-1.el7_5.x86_64 already installed and latest version Package 1:mariadb-server-5.5.60-1.el7_5.x86_64 already installed and latest version Package 1:mariadb-devel-5.5.60-1.el7_5.x86_64 already installed and latest version Package php-5.4.16-46.el7.x86_64 already installed and latest version Package php-mysql-5.4.16-46.el7.x86_64 already installed and latest version Package php-common-5.4.16-46.el7.x86_64 already installed and latest version Package php-gd-5.4.16-46.el7.x86_64 already installed and latest version Package php-xml-5.4.16-46.el7.x86_64 already installed and latest version Nothing to do [root@localhost ~]# yum install -y libevent-devel php-bcmath php-common php-mbstring Package libevent-devel-2.0.21-4.el7.x86_64 already installed and latest version Package php-bcmath-5.4.16-46.el7.x86_64 already installed and latest version Package php-common-5.4.16-46.el7.x86_64 already installed and latest version Package php-mbstring-5.4.16-46.el7.x86_64 already installed and latest version Nothing to do
2.接着咱們先來安裝一下Zabbix編譯所依賴的包文件,具體操做以下.
[root@localhost ~]# yum install -y net-snmp-devel curl curl-devel libxml2-devel libcurl-devel libevent libevent-devel Package 1:net-snmp-devel-5.7.2-37.el7.x86_64 already installed and latest version Package curl-7.29.0-51.el7.x86_64 already installed and latest version Package libcurl-devel-7.29.0-51.el7.x86_64 already installed and latest version Package libxml2-devel-2.9.1-6.el7_2.3.x86_64 already installed and latest version Package libcurl-devel-7.29.0-51.el7.x86_64 already installed and latest version Package libevent-2.0.21-4.el7.x86_64 already installed and latest version Package libevent-devel-2.0.21-4.el7.x86_64 already installed and latest version Nothing to do
3.繼續,咱們經過wget命令下載一個Zabbix源碼包,執行如下編譯過程.
[root@localhost ~]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.2/zabbix-4.0.2.tar.gz [root@localhost ~]# useradd -M -s /sbin/nologin zabbix [root@localhost ~]# tar -xzvf zabbix-4.0.2.tar.gz [root@localhost ~]# cd zabbix-4.0.2/ [root@localhost ~]# ./configure --prefix=/usr/local/zabbix --enable-server \ --enable-agent --with-mysql --enable-ipv6 --with-net-snmp \ --with-libcurl --with-libxml2 --enable-java [root@localhost ~]# make && make install
4.配置Zabbix表結構,建立MariaDB用戶並用於Zabbix受權使用,並恢復Zabbix表結構.
[root@localhost ~]# systemctl start mariadb [root@localhost ~]# systemctl enable mariadb [root@localhost ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.60-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database zabbix DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; MariaDB [(none)]> grant all on zabbix.* to zabbix@"%" identified by "zabbix"; MariaDB [(none)]> grant all on zabbix.* to zabbix@"localhost" identified by "zabbix"; MariaDB [(none)]> exit [root@localhost ~]# cd /root/zabbix-4.0.2/database/mysql/ [root@localhost mysql]# mysql -uzabbix -pzabbix zabbix <schema.sql [root@localhost mysql]# mysql -uzabbix -pzabbix zabbix <images.sql [root@localhost mysql]# mysql -uzabbix -pzabbix zabbix <data.sql
5.將Zabbix的頁面文件拷貝到指定目錄(跟apache配置的相同便可).
[root@localhost ~]# cp -a /root/zabbix-4.0.2/frontends/php/* /var/www/html/ [root@localhost ~]# chown -R apache:apache /var/www/html/ [root@localhost ~]# systemctl restart httpd [root@localhost ~]# systemctl enable httpd
6.修改PHP配置文件,在PHP配置文件的末尾添加便可,主要目的是調整一下PHP參數,不然Zabbix不經過.
[root@localhost ~]# vim /etc/php.ini date.timezone = Asia/Shanghai max_execution_time = 300 max_input_time = 300 post_max_size = 32M memory_limit = 128M mbstring.func_overload = 0
7.配置Zabbix Server端配置文件,主要目的是定義數據庫的IP、用戶名、密碼等.
[root@localhost ~]# vim /usr/local/zabbix/etc/zabbix_server.conf DBHost=localhost #監控主機數據庫IP,這裏是本地 DBName=zabbix #數據庫名 DBUser=zabbix #訪問,數據庫的用戶名 DBPassword=zabbix #訪問,數據庫訪問密碼
8.全部工做配置完成之後,啓動一下Zabbix進程和Apache服務.
[root@localhost ~]# /usr/local/zabbix/sbin/zabbix_server [root@localhost ~]# echo "/usr/local/zabbix/sbin/zabbix_server" >> /etc/bashrc [root@localhost ~]# systemctl restart httpd
9.拓展環節:若是你的Zabbix登錄密碼忘記了,你可使用如下命令找回來.
MariaDB [(none)]> update zabbix.users set passwd=md5(123123) where name="Zabbix";
10.解決中文亂碼問題,並登錄系統看結果吧.
#在windows系統中:Win+R -> fonts -> 拷貝微軟雅黑字體更名爲 msyh.ttf [root@localhost ~]# cp -a msyh.ttf /var/www/html/fonts// [root@localhost ~]# vim /var/www/html/include/defines.inc.php #修改 zabbix php 頁面配置,將'DejaVuSans' 修改成 'msyh' 65 define('ZBX_GRAPH_FONT_NAME', 'msyh'); // font file name [root@localhost ~]# systemctl restart httpd 用戶名:Admin 密碼:zabbix
1.首先安裝依賴和,編譯環境.
[root@localhost ~]# yum install -y gcc pcre-devel pcre-static pcre-tools
2.編譯安裝Zabbix客戶端監控程序,這裏一樣適用相同的壓縮包.
[root@localhost ~]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.2/zabbix-4.0.2.tar.gz [root@localhost ~]# useradd -M -s /sbin/nologin zabbix [root@localhost ~]# tar -xzvf zabbix-4.0.2.tar.gz [root@localhost ~]# cd zabbix-4.0.2/ [root@localhost ~]# ./configure --prefix=/usr/local/zabbix --sysconfdir=/etc/zabbix --enable-agent [root@localhost ~]# make && make install
3.配置Zabbix-Agent端配置文件,修改主機列表.
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf Server=192.168.22.195 #填寫Server的IP地址 ServerActive=192.168.22.195 #修改成Server的IP地址 Hostname=centos_1 #填寫本機的HostName
4.啓動zabbix-agent端,並設置開機自啓動.
[root@localhost ~]# /usr/local/zabbix/sbin/zabbix_agentd [root@localhost ~]# echo "/usr/local/zabbix/sbin/zabbix_agentd" >> /etc/bashrc