zabbix安装配置简单,参照官网手册就好了,关键是记录下过程中遇到的奇葩问题
https://www.zabbix.com/documentation/start
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.gz
一、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/images.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,....}下
二、配置文件更改
#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.conf
三、配置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创建虚拟主机访问:
- log_format monitor.yr.com '$remote_addr - $remote_user [$time_local] $request '
- '$status $body_bytes_sent $http_referer '
- '$http_user_agent $http_x_forwarded_for';
- server
- {
- listen 80;
- server_name monitor.yr.com;
- index index.html index.htm index.php default.html default.htm default.php;
- root /home/wwwroot/zabbix/;
- location ~ .*\.(php|php5)?$
- {
- try_files $uri =404;
- fastcgi_pass unix:/tmp/php-cgi.sock;
- fastcgi_index index.php;
- include fcgi.conf;
- }
- location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
- {
- expires 30d;
- }
- location ~ .*\.(js|css)?$
- {
- expires 12h;
- }
- access_log /home/wwwlogs/monitor.yr.com.log monitor.yr.com;
- }
/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代码文件中:
- #more /home/wwwroot/zabbix/conf/zabbix.conf.php
- <?php
- // Zabbix GUI configuration file
- global $DB;
- $DB['TYPE'] = 'MYSQL';
- $DB['SERVER'] = 'localhost';
- $DB['PORT'] = '3306';
- $DB['DATABASE'] = 'zabbix';
- $DB['USER'] = 'root';
- $DB['PASSWORD'] = '123456';
- // SCHEMA is relevant only for IBM_DB2 database
- $DB['SCHEMA'] = '';
- $ZBX_SERVER = '42.120.x.x';
- $ZBX_SERVER_PORT = '10051';
- $ZBX_SERVER_NAME = '';
- $IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
- ?>
四、利用postfix配置邮件服务器发送报警
postfix安装略,可直接yum install postfix
配置文件更改:
- #vi /etc/postfix/main.cf
- queue_directory = /var/spool/postfix
- command_directory = /usr/sbin
- daemon_directory = /usr/libexec/postfix
- mail_owner = postfix
- myhostname = internal.yr.com #邮件域名
- mydomain = internal.yr.com
- myorigin = $mydomain
- inet_interfaces = all
- #注意,这里权限开放错误的话,会导致邮件发送不出去,开始时没理解,只设了允许本机IP,导致其它机器测试telnet 25过来全不通,WEB管理界面Monitoring-->Events-->Time可查看出错信息
- mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
- unknown_local_recipient_reject_code = 550
- mynetworks = 42.120.x.x, 127.0.0.1
- relay_domains = $mydestination, 42.120.x.x, internal.yr.com
- alias_maps = hash:/etc/aliases
- alias_database = hash:/etc/aliases
- home_mailbox = Maildir/
- smtpd_banner = $myhostname ESMTP unknow
- debug_peer_level = 2
- debugger_command =
- PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
- xxgdb $daemon_directory/$process_name $process_id & sleep 5
- sendmail_path = /usr/sbin/sendmail.postfix
- newaliases_path = /usr/bin/newaliases.postfix
- mailq_path = /usr/bin/mailq.postfix
- setgid_group = postdrop
- html_directory = no
- manpage_directory = /usr/share/man
- sample_directory = /usr/share/doc/postfix-2.3.3/samples
- readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES
/etc/init.d/postfix start
================
过程中出现的问题
================
如果出现管理界面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 [email protected];
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 [email protected] 或mail -s "test" [email protected] 服务器上测试邮件发出是正常的可以收到,日志文件中也查看不出错误,查看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