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  

相关文章
相关标签/搜索