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
- 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代碼文件中:nginx
- #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;
- ?>
4、利用postfix配置郵件服務器發送報警
postfix安裝略,可直接yum install postfix
配置文件更改:web
- #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 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