zabbix 網絡監控 -- 服務端的配置

zabbix是一個基於WEB界面的提供分佈式系統監視以及網絡監視功能的企業級的開源解決方案。

zabbix能監視各種網絡參數,保證服務器系統的安全運營;並提供柔軟的通知機制以讓系統管理員快速定位/解決存在的各種問題。

zabbix由2部分構成,zabbix server與可選組件zabbix agent。

zabbix server可以通過SNMP,zabbix agent,ping,端口監視等方法提供對遠程服務器/網絡狀態的監視,數據收集等功能,它可以運行在Linux, Solaris, HP-UX, AIX, Free BSD, Open BSD, OS X等平臺上。

zabbix agent需要安裝在被監視的目標服務器上,它主要完成對硬件信息或與操作系統有關的內存,CPU等信息的收集。zabbix agent可以運行在Linux ,Solaris, HP-UX, AIX, Free BSD, Open BSD, OS X, Tru64/OSF1, Windows NT4.0, Windows 2000/2003/XP/Vista)等系統之上。

zabbix server可以單獨監視遠程服務器的服務狀態;同時也可以與zabbix agent配合,可以輪詢zabbix agent主動接收監視數據(trapping方式),同時還可被動接收zabbix agent發送的數據(trapping方式)。另外zabbix server還支持SNMP (v1,v2),可以與SNMP軟件(例如:net-snmp)等配合使用。

服務端安裝zabbix_server,zabbix_agentd兩個服務,客戶端只需安裝zabbix_agentd一個服務,監控原理其實就是zabbix_agentd服務將從系統中獲取的相關數據傳送給zabbix_server服務,然後zabbix_server服務將數據以PHP頁面顯示出來

zabbix的主要特點:   
- 安裝與配置簡單,學習成本低
- 支持多語言(包括中文)   
- 免費開源   
- 自動發現服務器與網絡設備   
- 分佈式監視以及WEB集中管理功能   
- 可以無agent監視   
- 用戶安全認證和柔軟的授權方式   
- 通過WEB界面設置或查看監視結果   
- email等通知功能等等   

Zabbix主要功能:    
- CPU負荷   
- 內存使用   
- 磁盤使用   
- 網絡狀況   
- 端口監視   
- 日誌監視



zabbix服務端部署:


1.配置前先關閉iptables和SELINUX,避免安裝過程中報錯。


[root@localhost tw]# service iptables stop

iptables: Flushing firewall rules: [  OK  ]
iptables: Setting chains to policy ACCEPT: filter [  OK  ]
iptables: Unloading modules: [  OK  ]

[root@localhost tw]# chkconfig iptables off

[root@localhost tw]# getenforce
Disabled


2.安裝LAMP環境

yum install -y httpd mysql mysql-server mysql-devel php php-mysql php-common php-mbstring php-gd php-odbc php-xml php-pear


3.下載zabbix-2.2.6.tar.gz

wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.6/zabbix-2.2.6.tar.gz


4.安裝zabbix所需的組件(server,agent)

yum install -y curl curl-devel net-snmp net-snmp-devel perl-DBI


5.創建用戶賬號(server,agent)

[root@localhost tw]#useradd zabbix

[root@localhost tw]#usermod -s /sbin/nologin zabbix



6.創建zabbix數據庫並導入zabbix數據庫(server)

[root@localhost tw]#tar zxf zabbix-2.2.6.tar.gz

[root@localhost tw]#mysqladmin -u root password 123456
 (確認MySQL已啓動,啓動命令:/etc/rc.d/init.d/mysqld start(stop、status))

[root@localhost tw] mysql -p123456

下面爲寫入數據庫的數據,手動寫入:

mysql> create database zabbix;

mysql> grant all on zabbix.* to zabbix@localhost identified by '123456';

mysql> use zabbix;

mysql> source /usr/zabbix-2.2.6/database/mysql/schema.sql(注意路徑/usr)

mysql> source /usr/zabbix-2.2.6/database/mysql/images.sql

mysql> source /usr/zabbix-2.2.6/database/mysql/data.sql

mysql> exit


7.編譯安裝,如果是客戶端安裝選擇--enable-agent就行了。

[root@localhost tw]#cd zabbix-2.2.6

[root@localhost zabbix-2.2.6]# ./configure --with-mysql --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy --

prefix=/usr/local/zabbix (安裝路徑可以修改,建議使用默認路徑)


8.編輯配置文件

[root@localhost zabbix-2.2.6]#cd /usr/local/zabbix/etc

[root@localhost etc]# cp zabbix_server.conf zabbix_server.conf.bak

[root@localhost etc]# cp zabbix_agentd.conf  zabbix_agentd.conf.bak

[root@localhost etc]# vi zabbix_server.conf #服務端的配置
LogFile=/var/log/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456


[root@localhost etc]# vi  zabbix_agentd.conf #客戶端配置(服務端不需要)
LogFile=/tmp/zabbix_agentd.log
Server=127.0.0.1
UnsafeUserParameters=1


[root@localhost etc]# touch /var/log/zabbix_server.log

[root@localhost etc]# touch /var/log/zabbix_agentd.log

[root@localhost etc]# chmod 777 /var/log/zabbix_*


9.啓動服務(server,agent)

[root@localhost etc]cd /usr/zabbix-2.2.6

[root@localhost zabbix-2.2.6]# cp misc/init.d/tru64/zabbix_server  /etc/init.d/

[root@localhost zabbix-2.2.6]# cp misc/init.d/tru64/zabbix_agentd  /etc/init.d/

[root@localhost zabbix-2.2.6]# chmod +x /etc/init.d/zabbix_*     #添加服務

[root@localhost zabbix-2.2.6]# chkconfig --add zabbix_server

[root@localhost zabbix-2.2.6]# chkconfig --add zabbix_agentd     #設置服務器開機自動啓動

注:執行chkconfig時如出現zabbix_server 服務不支持 chkconfig,編輯
zabbix_server和zabbix_agentd中開頭添加以下內容即可

(vi /etc/init.d/zabbix_agentd    

   #chkconfig:345 61 61)


(vi /etc/init.d/zabbix_server   
   #chkconfig:345 61 61)


[root@localhost zabbix-2.2.6]# chkconfig zabbix_server on

[root@localhost zabbix-2.2.6]# chkconfig zabbix_agentd on

[root@localhost zabbix-2.2.6]# service zabbix_server start

Zabbix server started.


(如果自定義安裝目錄在/usr/local/zabbix下,需要執行命令:
  1、 cd /usr/local/zabbix/sbin
  2、cp zabbix_server /usr/local/sbin/
  3、cp zabbix_agentd /usr/local/sbin/)


[root@localhost zabbix-2.2.6]# service zabbix_agentd start
Zabbix agent started.

[root@localhost zabbix-2.2.6]# ps -ef |grep zabbix


zabbix    1803     1  0 08:21 ?        00:00:00

/usr/local/sbin/zabbix_agentd
zabbix    1805  1803  0 08:21 ?        00:00:00

/usr/local/sbin/zabbix_agentd
zabbix    1806  1803  0 08:21 ?        00:00:00

/usr/local/sbin/zabbix_agentd
zabbix    1807  1803  0 08:21 ?        00:00:00

/usr/local/sbin/zabbix_agentd
zabbix    1808  1803  0 08:21 ?        00:00:00

/usr/local/sbin/zabbix_agentd
zabbix    1814     1  0 08:21 ?        00:00:00

/usr/local/sbin/zabbix_server
root      2043  2006  0 08:23 pts/0    00:00:00 grep zabbix


[root@localhost zabbix-2.2.6]# netstat -lantp |grep 10050
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                 

  LISTEN      59118/zabbix_agentd

[root@localhost zabbix-2.2.6]#netstat -lantp |grep 10051

tcp        0      0 0.0.0.0:10051               0.0.0.0:*                 

  LISTEN      58931/./zabbix_serv

tcp        0      0 127.0.0.1:10051             127.0.0.1:56376           

  TIME_WAIT   -    




10.安裝zabbix web界面(httpd)

複製php文件,zabbix的終端程序是用php寫的,因此需要一個支持php腳本解析的web服務器。然後將frontends/php下面的php文件拷貝到web服務器html文件目錄下面。

[root@localhost zabbix-2.2.6]#cp  -r   /usr/zabbix-2.2.6/frontends/php  /var/www/html/zabbix
(cp: 無法獲取"frontends/php" 的文件狀態(stat): 沒有那個文件或目錄----解決:找到rontends/php路徑即可)

[root@localhost zabbix-2.2.6]#/etc/init.d/httpd restart            #啓動apache服務


11.安裝zabbix web界面(nginx)


1.安裝php

yum install -y php php-mysql php-gd libjpeg* php-imap php-ldap php-odbc

php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash

libmcrypt libmcrypt-devel php-fpm php-pecl*

2.安裝nginx

[root@localhost]#wget http://nginx.org/download/nginx-1.9.9.tar.gz

[root@localhost]#tar zxf nginx-1.9.9.tar.gz

[root@localhost]#cd nginx-1.9.9

[root@localhost nginx-1.9.9]#./configure --user=www --group=www --

prefix=/usr/local/nginx --with-http_stub_status_module --with-

http_ssl_module --error-log-path=/data/logs/nginx/error.log --http-log-

path=/data/logs/nginx/access.log

[root@localhost nginx-1.9.9]#make && make install

3.配置nginx參數(修改成下列內容支持PHP)

[root@localhost zabbix-2.0.6]#cp -r frontends/php

/usr/local/nginx/html/zabbix

[root@localhost zabbix-2.0.6]#vi /usr/local/nginx/conf/nginx.conf

    server {

        listen       88;

        server_name  127.0.0.1;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;


        location / {

            root   html/zabbix;

            index  index.php index.htm index.html;

        }


        #error_page  404              /404.html;


        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }


        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}


        # pass the PHP scripts to FastCGI server listening on

127.0.0.1:9000

        #

        location ~ \.php$ {

            root           html/zabbix;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root

$fastcgi_script_name;

            include        fastcgi_params;

        }

4.啓動

[root@localhost zabbix-2.2.6]#chown -R /usr/local/nginx

[root@localhost zabbix-2.2.6]#/usr/local/nginx/sbin/nginx           //啓

動nginx

[root@localhost zabbix-2.2.6]#/etc/init.d/php-fpm start          //啓動

php


特別註釋:httpd與Nginx只需要安裝其中一種即可,請選擇安裝



11.修改PHP參數

[root@localhost zabbix-2.2.6]# vi  /etc/php.ini

[Date]

; Defines the default timezone used by the date functions
;

http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = Asia/Shanghai    #修改一下時區

[root@localhost zabbix-2.2.6]# /etc/init.d/httpd  restart

12、安裝前端


在瀏覽器裏輸入192.168.35.135/zabbix出現zabbix安裝界面點擊next





(下一步出現PHP bacmath  no   Fail錯誤


解決:[root@localhost zabbix-2.2.6]#yum install -y php-bcmath     #安裝php-bcmath即可






這種情況下,是缺少LAMP環境,安裝即可:

yum install -y httpd mysql mysql-server mysql-devel php php-mysql php-common php-mbstring php-gd php-odbc php-xml php-pear


其他報錯,根據提示修改/etc/php.ini文件裏的參數即可,然後next,配置如下

Database type:MySQL

Database host:localhost

Database port:3306

Database name:zabbix

user         :zabbix

Password     :123456


post_max_size = 16M
max_execution_time = 300
max_input_time = 300


點擊Test connection出現OK繼續next,配置如下


測試連接時若報錯,添加如下命令:
# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock









下載配置文件,並把他放置在/usr/local/apache2/htdocs/zabbix/conf/ 目錄下,點擊next即可用登錄;

默認用戶:Admin

默認密碼:zabbix


出現界面,部署成功。

顯示簡體中文界面,點擊:右上角Profile,選擇Chinese(zh_CN),保存即可。







發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章