公司的監控系統是單純用nagios+nrpe實現的,並不支持分佈式。如今公司須要實現監控系統改造,因爲nagios分佈式在搭建和配置等諸多方面都比較繁雜,在此經過文檔等了解到zabbix的諸多好的功能和特性,因此決定用zabbix來實現分佈式。很少說,先看看zabbix server端和zabbix agent端的安裝與配置、監控的基本實現。
php
1、服務端安裝(版本是2.2.5)
html
1.確保編譯環境mysql
# yum -y install make gcc gcc-c++
2.安裝和配置LAMP(yum或者源碼包安裝)ios
# yum -y install httpd mysql mysql-server mysql-devel php php-gd php-xml php-mysql php-mbstring php-bcmath perl-DBI curl libcurl-devel net-snmp net-snmp-devel libssh2 libssh2-devel # vim /etc/httpd/conf/httpd.conf #添加 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps #在DirectoryIndex中添加index.php <IfModule dir_module> DirectoryIndex index.php index.html </IfModule> # service httpd restart
3.下載zabbix安裝包
c++
# mkdir -pv pkgs/builds # pkgs爲安裝包存放目錄,builds爲安裝包解壓後存放的目錄 # cd pkgs/ # wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.2.5/zabbix-2.2.5.tar.gz/download # tar xf zabbix-2.2.5.tar.gz -C builds/
4.添加zabbix用戶web
# useradd zabbix # echo "zabbix" | passwd --stdin zabbix
5.建立數據庫(使用mysql數據庫)、用戶與導入表
sql
mysql> create database zabbix character set utf8; mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; mysql> grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix'; mysql> flush privileges; # mysql -uzabbix -pzabbix -hlocalhost zabbix < database/mysql/schema.sql # mysql -uzabbix -pzabbix -hlocalhost zabbix < database/mysql/p_w_picpaths.sql # mysql -uzabbix -pzabbix -hlocalhost zabbix < database/mysql/data.sql
6.編譯安裝zabbix
數據庫
# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-ssh2 # make install
7.建立和修改服務啓動腳本文件
vim
# cp misc/init.d/fedora/core/zabbix_server /etc/init.d/ # cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/ # sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_server # sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_agentd
8.修改zabbix配置文件
bash
# sed -i 's/^DBUser=.*$/DBUser=zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf # sed -i 's/^.*DBPassword=.*$/DBPassword=zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf
9.配置php
# vim /etc/php.ini max_input_time = 600 max_execution_time = 300 date.timezone = Asia/Shanghai post_max_size = 32M memory_limit = 128M mbstring.func_overload = 2
10.添加服務端口
cat >>/etc/services <<EOF zabbix-agent 10050/tcp Zabbix Agent zabbix-agent 10050/udp Zabbix Agent zabbix-trapper 10051/tcp Zabbix Trapper zabbix-trapper 10051/udp Zabbix Trapper EOF
11.複製web interface到www目錄下面
# cp -R /root/pkgs/builds/zabbix-2.2.5/frontends/php /var/www/html/zabbix
12.配置隨機啓動
# chkconfig --add zabbix_server # chkconfig zabbix_server on
13.啓動zabbix server服務
# service zabbix_server start
確認好web服務器配置並開啓,就輸入http://ip/zabbix來進行web的安裝
2、web頁面配置
1.查看那個配置項不符合就解決,而後下一步
2.輸入數據庫鏈接信息
3.輸入zabbix server信息(可不填)
4.以前操做的彙總呈現
5.先下載這個文件,而後在傳到服務器裏,給予執行權限;以後點retry
6.沒有問題就能夠選擇finish,會跳出登錄頁面,默認帳號爲admin,密碼zabbix
7.登錄後的頁面呈現
3、zabbix agent安裝、配置、基本監控實現
1.添加zabbix用戶
# groupadd zabbix # useradd -g zabbix zabbix
2.確保編譯環境
# yum -y install make gcc gcc-c++
3.安裝所須要的依賴包
# yum -y install curl curl-devel net-snmp net-snmp-devel libssh2 libssh2-devel
4.zabbix agent安裝
# ./configure --prefix=/usr/local/zabbix --enable-agent --with-net-snmp --with-libcurl --with-ssh2 # make install
5.建立和修改配置啓動腳本
# cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/ # sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_agentd
6.配置zabbix_agentd.conf文件
Server=192.168.244.133 #該ip爲zabbix_server的IP ServerActive=192.168.244.133 #該ip爲zabbix_server的IP Hostname=192.168.244.136 #hostname能夠爲字符串,可是要保證zabbix_server可以解析
7.添加服務端口
cat >>/etc/services <<EOF zabbix-agent 10050/tcp Zabbix Agent zabbix-agent 10050/udp Zabbix Agent zabbix-trapper 10051/tcp Zabbix Trapper zabbix-trapper 10051/udp Zabbix Trapper EOF
8.配置隨機啓動
# chkconfig --add zabbix_agentd # chkconfig zabbix_agentd on
9.啓動zabbix agent進程
# service zabbix_agentd start Starting zabbix_agentd: [ OK ] # netstat -nltp | grep zabbix tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 1953/zabbix_agentd
8.在zabbix server的web頁面中添加被監控主機
Configuration --> Host --> Create host --> 填寫主機信息 --> save
9.添加監控項目,這裏用監控主機網卡流量作爲示例
10.保存之後等待幾分鐘,而後在Monitoring --> Latest data --> host中查看剛纔添加的監控服務變化狀況走勢圖
以上就是zabbix server和zabbix agent安裝、配置、監控的基本實現了,剛開始學習zabbix的朋友快去試一試吧~