實驗環境:
centos 6.5 x86_64 3臺
mysql服務 1臺
zabbix-server服務器(可以跟mysql是同一臺) 1臺
被監控的zabbix-agent 至少1臺
database主機
關閉防火牆
[root@rslinux ~]# /etc/init.d/iptables stop
禁用開機自啓
[root@rslinux ~]# chkconfig iptables off
[root@rslinux ~]# chkconfig --list iptables
iptables 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉
安裝數據庫
[root@rslinux ~]# yum -y install mysql-server mysql
[root@rslinux ~]# /etc/init.d/mysqld start
正在啓動 mysqld: [確定]
[root@rslinux ~]# mysql -u root
爲用戶授權
grant all privileges on *.* to'root'@'192.168.4.%' identified by 'rootpass'; grant all privileges on zabbix.* to'zabbix'@'192.168.4.61' identified by 'zabbixpass';
刷新授權
flushprivileges;
配置mysql
添加以下兩行即可
[root@rslinux ~]# vim /etc/my.cnf
[mysqld] ... ... #設置字符集爲utf8 character-set-server=utf8 #讓innodb的每個表文件單獨存儲 innodb_file_per_table=1 ... ...
zabbix-server主機
[root@rslinux11 ~]# /etc/init.d/iptables stop
iptables:將鏈設置爲政策 ACCEPT:filter [確定]
iptables:清除防火牆規則: [確定]
iptables:正在卸載模塊: [確定]
[root@rslinux11 ~]# chkconfig iptables off
[root@rslinux11 ~]# chkconfig --list iptables
iptables 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉
[root@rslinux11 ~]# yum list zabbix22*
zabbix22.x86_64 2.2.11-1.el6 @epel zabbix22-agent.x86_64 2.2.11-1.el6 @epel zabbix22-dbfiles-mysql.noarch 2.2.11-1.el6 @epel zabbix22-server.noarch 2.2.11-1.el6 @epel zabbix22-server-mysql.x86_64 2.2.11-1.el6 @epel zabbix22-web.noarch 2.2.11-1.el6 @epel zabbix22-web-mysql.noarch 2.2.11-1.el6 @epel 可安裝的軟件包 zabbix22-dbfiles-pgsql.noarch 2.2.11-1.el6 epel zabbix22-dbfiles-sqlite3.noarch 2.2.11-1.el6 epel zabbix22-proxy.noarch 2.2.11-1.el6 epel zabbix22-proxy-mysql.x86_64 2.2.11-1.el6 epel zabbix22-proxy-pgsql.x86_64 2.2.11-1.el6 epel zabbix22-proxy-sqlite3.x86_64 2.2.11-1.el6 epel zabbix22-server-pgsql.x86_64 2.2.11-1.el6 epel zabbix22-web-pgsql.noarch 2.2.11-1.el6 epel
[root@rslinux11~]# yum -y install zabbix22 zabbix22-agent zabbix22-dbfiles-mysqlzabbix22-server zabbix22-server-mysql zabbix22-web zabbix22-web-mysql
[root@rslinux11 ~]# yum -y install mysql
[root@rslinux11 ~]# rpm -ql zabbix22-server-mysql
/usr/sbin/zabbix_server_mysql
頓時感覺無語... ...
現在只能用find查找了... ...
[root@rslinux11 ~]# find / -name *.sql
/usr/share/doc/unixODBC-2.2.14/doc/UserManual/My.sql
/usr/share/zabbix-mysql/schema.sql
/usr/share/zabbix-mysql/data.sql
/usr/share/zabbix-mysql/upgrades/1.8/patch.sql
/usr/share/zabbix-mysql/upgrades/2.0/patch.sql
/usr/share/zabbix-mysql/upgrades/2.0/rc4_rc5.sql
/usr/share/zabbix-mysql/upgrades/1.6/patch.sql
/usr/share/zabbix-mysql/p_w_picpaths.sql
/usr/share/ibus-pinyin/db/create_index.sql
將zabbix-mysql的數據導入到zabbix庫中
mysql -h 192.168.4.41-u root -prootpass zabbix < /usr/share/zabbix-mysql/schema.sql mysql -h 192.168.4.41-u root -prootpass zabbix < /usr/share/zabbix-mysql/p_w_picpaths.sql mysql -h 192.168.4.41-u root -prootpass zabbix < /usr/share/zabbix-mysql/data.sql
編輯之前記得備份
[root@rslinux11 ~]# cp /etc/zabbix/zabbix_server.conf{,.bak}
[root@rslinux11 zabbix]# egrep -v"^#|^$" /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log LogFileSize=0 PidFile=/var/run/zabbix/zabbix.pid DBHost=192.168.4.41 DBName=zabbix DBUser=zabbix DBPassword=zabbixpass DBPort=3306 DBSocket=/var/lib/mysql/mysql.sock StartPollers=5 CacheSize=256M AlertScriptsPath=/var/lib/zabbix/
[root@rslinux11 zabbix]# /etc/init.d/httpd start
[root@rslinux11 zabbix]#/etc/init.d/zabbix-server start
[root@rslinux11 zabbix]# chkconfig zabbix-server on
[root@rslinux11 zabbix]# chkconfig httpd on
[root@rslinux11 zabbix]# chkconfig --list zabbix-server
[root@rslinux11 zabbix]# chkconfig --listhttpd
[root@rslinux11 ~]# netstat -anpt | grep -c zabbix
0
[root@rslinux11 ~]# tail -f/var/log/zabbix/zabbix_server.log
3101:20160308:170715.484 [Z3001] connection to database 'zabbix' failed:[2003] Can't connect to MySQL server on '192.168.4.41' (13)
臨時關閉,不需要重啓
[root@rslinux11 zabbix]# setenforce 0
或者
直接關閉,需 重啓
[root@rslinux11 ~]# vim /etc/selinux/config
SELINUX=disabled SELINUXTYPE=targeted
[root@rslinux11 ~]#/etc/init.d/zabbix-server restart
過濾zabbix進程,由於進程太多,我這裏就直接看個數了,就不一顯示
[root@rslinux11 ~]# netstat -anpt | grep-c zabbix
25
看日誌,顯示正常
[root@rslinux11 ~]# tail -f/var/log/zabbix/zabbix_server.log
3201:20160308:171405.601 server #25 started[proxy poller #1]
3202:20160308:171405.603 server #26 started [self-monitoring #1]
3183:20160308:171405.901 server #7 started [poller #5]
3181:20160308:171405.912 server #5 started [poller #3]
3182:20160308:171405.913 server #6 started [poller #4]
... ...
... ...
其實到這裏就可以用瀏覽器訪問看看了,但是這裏還有php的參數需要改(必須)
方法是:http://ip/zabbix
修改php參數
方法一:
[root@rslinux11 ~]# vim/etc/httpd/conf.d/zabbix.conf
Alias /zabbix /usr/share/zabbix <Directory"/usr/share/zabbix"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all php_value date.timezone Asia/Shanghai php_value max_execution_time 300 php_value post_max_size 16M php_value max_input_time 300 php_value memory_limit 128M php_value upload_max_filesize 2M </Directory> ... ...
[root@rslinux11 ~]# /etc/init.d/httpd restart
方法二:
我這裏爲了方便我就把他們都放到一塊兒了,默認這個php.ini文件裏頭底下的參數都有,需要註釋才行,不然就該衝突了
[root@rslinux11 ~]# vim /etc/php.ini
... ... date.timezone = Asia/Shanghai max_execution_time = 300 post_max_size = 16M max_input_time = 300 memory_limit = 128M upload_max_filesize = 2M ... ...
修改完以後,就可以一直下一步了
這些配置信息將會保存寫入到“/etc/zabbix/web/zabbix.conf.php”(/${PATH}/zabbix/web/zabbix.conf.php)文件中
[root@rslinux11 ~]# vim/etc/zabbix/web/zabbix.conf.php
<?php // Zabbix GUI configuration file global $DB; $DB["TYPE"] = 'MYSQL'; $DB["SERVER"] = '192.168.4.41'; $DB["PORT"] = '3306'; $DB["DATABASE"] = 'zabbix'; $DB["USER"] = 'zabbix'; $DB["PASSWORD"] = 'zabbixpass'; // SCHEMA is relevant only for IBM_DB2database $DB["SCHEMA"] = ''; $ZBX_SERVER = '192.168.4.61'; $ZBX_SERVER_PORT = '10051'; $ZBX_SERVER_NAME = 'shouhui_zabbix'; $IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG; ?>
注意:
安裝完zabbix後要把這個文件刪除,或者移動到別的地方也行,否則每次在瀏覽器輸入"http://ip/zabbix"就會再重新裝一次;
[root@rslinux11 ~]# ll /usr/share/zabbix/setup.php
-rw-r--r--. 1 root root 4666 12月 16 2014 /usr/share/zabbix/setup.php
故障處理:
出現這個問題,不要着急,在配置文件找找就好了
將 ZBX_SERVER 的ip地址修改爲,你安裝zabbix-server的那臺主機的IP就可以了
[root@rslinux11 ~]# vim/etc/zabbix/web/zabbix.conf.php
... ... $ZBX_SERVER = '192.168.4.61'; $ZBX_SERVER_PORT = '10051'; $ZBX_SERVER_NAME = 'shouhui_zabbix';