zabbix安裝配置及郵件報警

zabbix安裝配置簡單,參照官網手冊就行了,關鍵是記錄下過程當中遇到的奇葩問題
https://www.zabbix.com/documentation/startphp

centos5.8 x86_64    lnmp環境  
zabbix2.0.5源碼包安裝
http://sourceforge.net/settings/mirror_choices?projectname=zabbix&filename=ZABBIX%20Latest%20Stable/2.0.5/zabbix-2.0.5.tar.gzcss

1、zabbix安裝
1)賬號建立:
groupadd zabbix
useradd -g zabbix zabbix
2)建立zabbix數據庫(注意:將zabbix數據庫按順序導入,不然可能會出錯)
mysql>create database zabbix;
mysql>exit;
#mysql -uroot -p zabbix<database/mysql/schema.sql
#mysql -uroot -p zabbix<database/mysql/p_w_picpaths.sql
#mysql -uroot -p zabbix<database/mysql/data.sql
3)源碼安裝:
#tar -zxvf zabbix-2.0.5.tar.gz
#cd zabbix-2.0.5
#./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl
#make install
安裝路徑默認在:/usr/local/{sbin,etc,....}下html

2、配置文件更改
#vi /usr/local/etc/zabbix_server.conf
ListenPort=10051
LogFile=/tmp/zabbix_server.log
DebugLevel=4                          #調試時能夠將dubug log值開啓高一點
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=root
DBPassword=123456
DBSocket=/tmp/mysql.sock
DBPort=3306
ListenIP=42.120.x.x前端

啓動服務:
/usr/local/sbin/zabbix_server -c /usr/local/etc/zabbix_server.confmysql

3、配置zabbix的web管理訪問
#cd zabbix-2.0.5
#cp -a frontends/php /home/wwwroot/zabbix  
zabbix的web前端是用php寫的,將其代碼文件拷貝到可訪問的web目錄下便可, /home/wwwroot/zabbix是個人web目錄
#chown www.www -R /home/wwwroot/zabbix
個人lnmp環境,nginx建立虛擬主機訪問:linux

  
  
  
  
  1. log_format  monitor.yr.com  '$remote_addr - $remote_user [$time_local] $request '  
  2.              '$status $body_bytes_sent $http_referer '  
  3.              '$http_user_agent $http_x_forwarded_for';  
  4. server  
  5.         {  
  6.                 listen       80;  
  7.                 server_name monitor.yr.com;  
  8.                 index index.html index.htm index.php default.html default.htm default.php;  
  9.                 root  /home/wwwroot/zabbix/;  
  10.  
  11.                 location ~ .*\.(php|php5)?$  
  12.                         {  
  13.                                 try_files $uri =404;  
  14.                                 fastcgi_pass  unix:/tmp/php-cgi.sock;  
  15.                                 fastcgi_index index.php;  
  16.                                 include fcgi.conf;  
  17.                         }  
  18.  
  19.                 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$  
  20.                         {  
  21.                                 expires      30d;  
  22.                         }  
  23.  
  24.                 location ~ .*\.(js|css)?$  
  25.                         {  
  26.                                 expires      12h;  
  27.                         }  
  28.                 access_log  /home/wwwlogs/monitor.yr.com.log  monitor.yr.com;  
  29.         } 

/etc/init.d/nginx reload
/etc/init.d/php-fpm restart
WEB訪問:http://monitor.yr.com  默認用戶名admin 密碼zabbix
按照提示輸入數據庫的鏈接信息及主機端口,依次:
Database type : mysql
Database host : localhost
Database name : zabbix
User          : root
Password      : 123456
Host          : 42.120.x.x
Port          : 10051
完成後這些信息是會記錄到對應的前端php代碼文件中:nginx

  
  
  
  
  1. #more /home/wwwroot/zabbix/conf/zabbix.conf.php  
  2. <?php 
  3. // Zabbix GUI configuration file  
  4. global $DB;  
  5. $DB['TYPE']     = 'MYSQL';  
  6. $DB['SERVER']   = 'localhost';  
  7. $DB['PORT']     = '3306';  
  8. $DB['DATABASE'] = 'zabbix';  
  9. $DB['USER']     = 'root';  
  10. $DB['PASSWORD'] = '123456';  
  11. // SCHEMA is relevant only for IBM_DB2 database  
  12. $DB['SCHEMA'] = '';  
  13. $ZBX_SERVER      = '42.120.x.x';  
  14. $ZBX_SERVER_PORT = '10051';  
  15. $ZBX_SERVER_NAME = '';  
  16. $IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;  
  17. ?> 

4、利用postfix配置郵件服務器發送報警
postfix安裝略,可直接yum install postfix
配置文件更改:web

  
  
  
  
  1. #vi /etc/postfix/main.cf  
  2. queue_directory = /var/spool/postfix  
  3. command_directory = /usr/sbin  
  4. daemon_directory = /usr/libexec/postfix  
  5. mail_owner = postfix 
  6. myhostname = internal.yr.com         #郵件域名  
  7. mydomain = internal.yr.com  
  8. myorigin = $mydomain  
  9. inet_interfaces = all                               
  10. #注意,這裏權限開放錯誤的話,會致使郵件發送不出去,開始時沒理解,只設了容許本機IP,致使其它機器測試telnet 25過來全不通,WEB管理界面Monitoring-->Events-->Time可查看出錯信息 
  11. mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain  
  12. unknown_local_recipient_reject_code = 550 
  13. mynetworks = 42.120.x.x, 127.0.0.1  
  14. relay_domains = $mydestination, 42.120.x.x, internal.yr.com  
  15. alias_maps = hash:/etc/aliases  
  16. alias_database = hash:/etc/aliases  
  17. home_mailbox = Maildir/  
  18.      
  19. smtpd_banner = $myhostname ESMTP unknow  
  20. debug_peer_level = 2 
  21. debugger_command =  
  22.          PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin  
  23.          xxgdb $daemon_directory/$process_name $process_id & sleep 5  
  24. sendmail_path = /usr/sbin/sendmail.postfix  
  25. newaliases_path = /usr/bin/newaliases.postfix  
  26. mailq_path = /usr/bin/mailq.postfix  
  27. setgid_group = postdrop 
  28. html_directory = no 
  29. manpage_directory = /usr/share/man  
  30. sample_directory = /usr/share/doc/postfix-2.3.3/samples  
  31. readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES 

/etc/init.d/postfix startsql

================
過程當中出現的問題
================
若是出現管理界面zabbix服務未啓動:Zabbix server is not running the information displayed may not be current
Zabbix Server is running的值爲NO
注意檢查:
1)/etc/hosts文件
#127.0.0.1               localhost.localdomain localhost
42.120.x.x    aliyun      #localhost注意更改爲本身的主機名,這個問題折騰了好久,42.120.x.x是我本機的外網IP
127.0.0.1 internal.yr.com localhost.localdomain localhost    後面郵件告警設置時指定的域名數據庫

2)查看日誌/tmp/zabbix_server.log分析錯誤,本地測下mysql權限是否開放
#mysql -h 42.120.x.x -P 3306 -u root -p
#fgrep -A 5 DBconnect /tmp/zabbix_server.log            檢查數據庫鏈接信息
調試過程:
mysql>grant all on zabbix.* to 'root'@'42.120.x.x';     #如沒有權限則需賦權
mysql>drop user root@'42.120.x.x';
mysql>create user root@'42.120.x.x' identified by '123456';
mysql>show grants for root@42.120.x.x;
mysql>grant all privileges on *.* to root@'42.120.x.x';
mysql>flush privileges;
smysql>show grants for root@localhost;
若是不但願以root賬號來鏈接數據庫,能夠建立zabbix賬號來鏈接zabbix數據庫,賦予權限. web管理界面鏈接時更改成zabbix賬號來鏈接
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)

mysql> show grants for zabbix@localhost;
+---------------------------------------------------------------------------------------------------------------+
| Grants for zabbix@localhost                                                                                   |
+---------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'zabbix'@'localhost' IDENTIFIED BY PASSWORD '*DEEF4D7D88CD046ECA02A80393B7780A63E7E789' |
| GRANT ALL PRIVILEGES ON `zabbix`.* TO 'zabbix'@'localhost'                                                    |
+---------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

本地測試
#mysql -h localhost -uzabbix -p

3)telnet localhost 10051    檢查zabbix端口是否開通
防火牆對應端口10050是否開放或selinux是否關閉

郵件發送不出去問題:
sendmail yr@mail.xx.com 或mail -s "test" yr@mail.xx.com 服務器上測試郵件發出是正常的能夠收到,日誌文件中也查看不出錯誤,查看web界面envents記錄以下:

 

 如上提示鏈接不上smtp服務器,測試telnet  42.120.x.x  25確實如此,前面已經提到須要更改postfix配置文件中inet_interfaces = all ,或者限制開放部分IP訪問25端口的權限。還有注意hosts裏的localhost  

附:經常使用詳細參數說明  ListenPort=10051 LogFile=/var/log/zabbix/zabbix_server.log LogFileSize=32 PidFile=/var/run/zabbix/zabbix_server.pid DBHost=10.80.100.247 DBName=zabbix                            zabbix所屬數據庫名稱 DBUser=zabbix                            zabbix所屬數據庫用戶 DBPassword=xxxxxx                        zabbix數據庫密碼 DBSocket=/data/mysql/log/mysqld.sock DBPort=3306 StartPollers=512                         輪詢的初始值(0-1000) #StartIPMIPollers=4                      IPMI輪詢的初始值(0-1000) StartPollersUnreachable=40               輪詢不可達的主機數(包括IPMI 0-1000) #StartTrappers=8                         捕獲的初始值(0-1000) StartPingers=20                          ping的初始值(0-1000) StartDiscoverers=40                      自動發現的初始值(0-250) ListenIP=10.80.x.x HousekeepingFrequency=2 CacheSize=64M                            緩存大小 StartDBSyncers=8                         數據庫同步時間 HistoryCacheSize=64M TrendCacheSize=64M                       總趨勢緩存大小 HistoryTextCacheSize=64M Timeout=30 AlertScriptsPath=/var/lib/zabbixsrv/alertscripts       腳本的存放位置 ExternalScripts=/var/lib/zabbixsrv/externalscripts FpingLocation=/usr/sbin/fping LogSlowQueries=5000                                    日誌慢查詢設定 Include=/etc/zabbix_server.general.conf Include=/etc/zabbix_server.conf.d  

相關文章
相關標籤/搜索