zabbix在centos6下的編譯安裝
簡介
zabbix是開源的,它基于web界面的,提供分布式系統監視以及網絡監視功能,是一個all-in-one的高度集成的企業級監控解決方案。zabbix能監視各種網絡參數,保證服務器系統的安全運營;并提供靈活的通知機制以讓系統管理員快速定位/解決存在的各種問題。Zabbix由一個中心的Zabbix Server和若干可能安裝有Zabbix Agent被監控設備構成,主要特性可概括為以下幾點;
1.主要組成部分
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)等系統之上。
2.數據存儲
數據庫為PostgreSQL,Mysql,Oracle,SQLite或DB2。
可配置歷史和趨勢數據的保存時間
內建舊清理程序防止數據膨脹
詳細請參考:http://blog.chinaunix.net/uid-20726500-id-4513716.html
源碼安裝步驟
官方文檔:https://www.zabbix.com/documentation/2.4/manual/installation/install#from_the_sources
環境:Centos6.4 64bit
1.安裝依賴包和LAMP環境
安裝開發軟件包
yum -y groupinstall "Development Tools"
安裝LAMP(Linux,Apache, Mysql, Php)環境及zabbix所需644的依賴包
yum -y install httpd mysql mysql-server php php-mysql php-common php-mbstring php-gd php-odbc php-pear curl curl-devel net-snmp net-snmp-devel perl-DBI php-xml ntpdate php-bcmath
2.創建zabbix服務運行所需要的用戶和組
groupadd zabbix useradd -g zabbix zabbix passwd zabbixuser #修改用戶密碼
3. 初始化及配置mysql數據庫
啟動mysql服務:
chkconfig mysqld on #設置mysql服務開機啟動 service mysqld start # 或者/etc/init.d/mysqld start, 來啟動mysql服務
進入mysql的sql命令狀態,創建zabbix運行所需要的數據庫及用戶權限:
[root@cloudstack local]# mysqladmin -u root –h 127.0.0.1 password "123456" --root用戶初始化后無密碼,此處設定密碼為123456 [root@cloudstack local]# mysql –u root –h 127.0.0.1 –p -- -p是強制輸入密碼 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> --插入zabbix用戶 mysql>create database zabbix character set utf8; mysql>grant all privileges on zabbix.* to zabbixuser@'%' identified by 'zabbixpassword'; --或者insert into mysql.user(Host,User,Password) values("localhost","zabbix",password("zabbix")); Query OK, 1 row affected, 3 warnings (0.00 sec) mysql>flush privileges;
4安裝配置zabbix
4.1下載zabbix-2.4.7
mkdir /lyy cd /lyy wget http://fossies.org/linux/misc/zabbix-2.4.7.tar.gz/ tar -zxvf zabbix-2.4.7.tar.gz
4.2 編譯安裝zabbix
./configure --sysconfdir=/usr/local/zabbix/ --enable-server --enable-agent --with-net-snmp --with-libcurl --with-mysql
如果configure過程中提示少包,可以及時安裝,如:yum –y install mysql-devel。
Configure正確完成后,根據提示執行:
make install
注意:此處sysconfdir指定配置文件的路徑(zabbix_server.conf和zabbix_agent.conf),指定就在/usr/local/zabbix/目錄下的etc目錄了,如果不指定默認在/usr/local/下的etc目錄下。
4.3配置 zabbix server端及agent端的系統服務腳本
cp /lyy/zabbix-2.4.7/misc/init.d/tru64/zabbix_agentd /etc/init.d/ cp /lyy/zabbix-2.4.7/misc/init.d/tru64/zabbix_server /etc/init.d/ chown zabbixuser:zabbixuser /etc/init.d/zabbix_*
以上配置完畢后,可以直接在zabbixuser用戶下的任意目錄,執行
service zabbix_server start/stop/restart
如果不配置以上系統服務腳本,則需執行/usr/local/zabbix/sbin/zabbix_server(或者缺省的usr/local/sbin/zabbix_server)啟動服務。
4.4將zabbix的初始數據導入到數據庫中
mysql –u zabbixuser –h 192.168.229.131 -p zabbix < /lyy/zabbix-2.4.7/database/mysql/schema.sql mysql –u zabbixuser –h 192.168.229.131 -p zabbix < /lyy/zabbix-2.4.7/database/mysql/images.sql mysql –u zabbixuser –h 192.168.229.131 -p zabbix < /lyy/zabbix-2.4.7/database/mysql/data.sql
登錄數據庫查看下表是否都創建成功
4.5 配置zabbix的網站
將zabbix的頁面文件copy到指定目錄(跟apache配置的相同即可)
mkdir /var/www/html/zabbix cp -rf /lyy/zabbix-2.4.7/frontends/php/* /var/www/html/zabbix/ chown -R zabbixuser.zabbixuser /var/www/html/zabbix/
4.6配置php文件,適應zabbix安裝所需的參數
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 = 2是要求注釋掉的,否則會在后邊產生錯誤。
4.7配置zabbix server端的文件,定義數據庫的IP、用戶名、密碼
vim /usr/local/zabbix/etc/zabbix_server.conf
DBHost=192.168.229.131 DBName= zabbix DBUser=zabbixuser DBPassword=zabbixpassword #后面的供參考 StartPollers=30 #開啟多線程數,一般不要超過30個 StartTrappers=20 #trapper線程數 StartPingers=10 #fping線程數 StartDiscoverers=120 MaxHousekeeperDelete=5000 CacheSize=1024M #用來保存監控數據的緩存數,根據監控主機的數量適當調整 StartDBSyncers=8 #數據庫同步時間 HistoryCacheSize=1024M TrendCacheSize=128M #總趨勢緩存大小 HistoryTextCacheSize=512M AlertScriptsPath=/etc/zabbix/alertscripts LogSlowQueries=1000
5.配置apache文件,定義訪問zabbix的主機
vim /etc/httpd/conf/httpd.conf
ServerName 192.168.229.131 <VirtualHost *:80> DocumentRoot "/var/www/html" ServerName 192.168.229.131 </VirtualHost>
6啟動apache服務跟zabbix服務
chkconfig httpd on #設置開機啟動
此時查看并確認服務(mysqld, zabbix_server, httpd)啟動情況:
[root@localhost html]# netstat -plunt | grep LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1623/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 497/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 705/master tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 63120/zabbix_agentd tcp 0 0 127.0.0.1:10051 0.0.0.0:* LISTEN 63499/zabbix_server tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 3517/mysqld tcp 0 0 :::80 :::* LISTEN 63459/httpd tcp 0 0 :::22 :::* LISTEN 1623/sshd tcp 0 0 ::1:631 :::* LISTEN 1497/cupsd tcp 0 0 ::1:25 :::* LISTEN 1705/master
7訪問安裝界面并根據提示逐步完成安裝
7.1在瀏覽器中輸入:http://192.168.229.131/zabbix/ ,然后根據網頁提示一直往下進行。
注意: 當遇到配置/var/www/html/zabbix/conf/zabbix.conf.php失敗的情況,如下圖:
解決方法:
根據提示下載配置文件zabbix.conf.php,并拷貝到/var/www/html/zabbix/conf/目錄下,并給zabbixuser授權,之后點擊網頁上的重試即可。
[root@cloudstack onf]# cp /home/centos6/Desktop/zabbix.conf.php /var/www/html/zabbix/conf/ [root@cloudstack conf]# chown zabbixuser:zabbixuser zabbix.conf.php
7.2一切準備完畢后,進入登陸界面,初始的用戶名是admin和密碼是zabbix,之后會進入主界面。
注意:
1.在zabbix主界面遇到以下報錯:
date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PST/-8.0/no DST' instead [dashboard.php:130 →
解決方法:
第1步
[root@cloudstack init.d]# vi /etc/php.ini 配置date.timezone = Aisa/Shanghai
第2步
[root@cloudstack init.d]# vi /var/www/html/zabbix/include/page_header.php 在最前邊添加ini_set('date.timezone','Asia/Shanghai');
2.在zabbix主界面遇到報錯:server is not running
解決方法:
1.先看日志情況
vi /tmp/zabbix_server.log
2. 查看防火墻設置情況
3.參考http://my.oschina.net/jincon/blog/269870,可以其中一個函數被禁用導致的問題,解決:
vi /etc/php.ini 將其中disable_function=注釋掉即可。
8. Zabbix的簡單試用
配置和添加host:
更多使用方法介紹,請參考官方使用手冊。