zabbix学习笔记安装加实践(centos6.5+zabbix3.0细节)

Zabbix安装

搭建环境:Centos6.5_x86_64,Zabbix3.04

Server端:

1、安装开发软件包

yum -y groupinstall  "Development Tools"

2、安装所需的依赖包

yum-y install httpd mysql mysql-server php php-mysql php-common php-mbstringphp-gd php-odbc php-pear curl curl-devel net-snmp net-snmp-devel perl-DBIphp-xml ntpdate  php-bcmath

3、同步服务端的时间,保持所有服务器时间一致避免出现时间不同导致的不可用的监控数据

ntpdatepool.ntp.rog

4、创建zabbix服务运行所需要的用户和组

groupadd -g 201  zabbix

useradd -g zabbix  -u 201 -m zabbix

5、初始化mysql服务器

/etc/init.d/mysqldstart

6、创建zabbix运行所需要的数据库及用户权限

mysqladmin -uroot -h127.0.0.1  password "123456"

mysql-uroot -h127.0.0.1 -p

createdatabase zabbix character set utf8;

grantall privileges on zabbix.* to zabbix@'%' identified by '123456';

flushprivileges;

mysql  -uzabbix -p123456

ERROR1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)

登录不了

mysql  -uroot -p123456

Welcometo the MySQL monitor.  Commands end with; or \g.

YourMySQL connection id is 2307

Serverversion: 5.1.73 Source distribution

Copyright(c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracleis a registered trademark of Oracle Corporation and/or its

affiliates.Other names may be trademarks of their respective

owners.

Type'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

mysql>

mysql>use mysql

Readingtable information for completion of table and column names

Youcan turn off this feature to get a quicker startup with -A

Databasechanged

mysql>  select host,user,password from user;

+-----------------------+------------+-------------------------------------------+

|host                  | user       | password                                  |

+-----------------------+------------+-------------------------------------------+

|localhost             | root       |*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

|localhost.localdomain | root       |                                           |

|127.0.0.1             | root       |                                           |

|localhost             |            |                                           |

|localhost.localdomain |            |                                           |

|%                     | zabbixuser |*D1663F6CF6DD180D35CDC9DD46105B7DADD7DF19 |

|%                     | zabbix     |*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

+-----------------------+------------+-------------------------------------------+

7rows in set (0.00 sec)

mysql>delete fromuser where user=' ';  ##删除user为空的数据

QueryOK, 2 rows affected (0.03 sec)

mysql>

mysql>

mysql>flush  privileges;

QueryOK, 0 rows affected (0.00 sec)

mysql>

mysql>

mysql>

mysql>flush  privileges;

QueryOK, 0 rows affected (0.00 sec)

然后就登录成功

mysql  -uzabbix -p123456

Welcometo the MySQL monitor.  Commands end with; or \g.

YourMySQL connection id is 2334

Serverversion: 5.1.73 Source distribution

Copyright(c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracleis a registered trademark of Oracle Corporation and/or its

affiliates.Other names may be trademarks of their respective

owners.

Type'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>exit

Bye

7、下载解压zabbix

wgethttp://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.2.2/zabbix-2.2.2.tar.gz/download

cd/usr/src/

tarxf zabbix-2.2.2.tar.gz

8、将zabbix的初始数据导入到数据库中

/usr/src/zabbix-2.2.2/database/mysql

mysql-uzabbix  -h192.168.168.32 –p123456

mysql-uzabbixuser -h192.168.239.130 -p zabbix

mysql-uzabbixuser -h192.168.239.130 -p zabbix

红色字体的语句执行有问题,用以下语句执行

Mysql  -uroot  -p123456

Use zabbix;

source /usr/src/zabbix-2.2.2/database/mysql/schema.sql

source /usr/src/zabbix-2.2.2/database/mysql/images.sql

source /usr/src/zabbix-2.2.2/database/mysql/data.sql

#登录数据库查看下表是否都创建成功

9、编译安装zabbix

./configure–sysconfdir=/etc/zabbix/–enable-server –enable-agent –with-net-snmp –with-libcurl –with-mysql

./configure --prefix=/etc/zabbix --enable-server --enable-agent--with-net-snmp --with-libcurl --with-mysql

configure:error: Not found mysqlclient library

yum install mysql-devel

./configure --prefix=/etc/zabbix --enable-server --enable-agent--with-net-snmp --with-libcurl --with-mysql

  Enable proxy:          no

  Enable agent:          yes

  Agent details:

    Linker flags:          -rdynamic    

    Libraries:             -lm -ldl -lrt  -lresolv    -lcurl

  Enable Java gateway:   no

  LDAP support:          no

  IPv6 support:          no

***********************************************************

*            Now run'make install'                       *

*                                                        *

*            Thank you for using Zabbix!                  *

*                                 *

***********************************************************

zabbix编译常规报错解决方法

一、CentOS编译报错

以下操作可能需要第三方源,参考此进行安装第三方Yum源

rpm -ivh http://ftp.sjtu.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm

[if !supportLineBreakNewLine]

[endif]

1、configure: error:Jabber library not found

  #yum

install iksemel-devel即可

[if !supportLineBreakNewLine]

[endif]

2、configure: error:LIBXML2 library not found

#yum install libxml2-devel

[if !supportLineBreakNewLine]

[endif]

3、configure: error:unixODBC library not found

#yuminstall unixODBC-devel

[if !supportLineBreakNewLine]

[endif]

4、configure: error:Invalid OPENIPMI directory - unable to find ipmiif.h

#yum install OpenIPMI-devel

[if !supportLineBreakNewLine]

[endif]

5、configure: error:Unable to find "javac" executable in path

  #yum

install java*    具体什么包没找,直接通配算逑,生产环境可去掉--enable-java选项

[if !supportLineBreakNewLine]

[endif]

6、configure: error:Curl library not found

#yum install curl-devel

[if !supportLineBreakNewLine]

[endif]

二、Ubuntu编译报错

1、configure:

error:MySQLlibrary not found

# apt-getinstall libmysqlclient-dev

2、configure error:Invalid Net-SNMP directory - unable to find net-snmp-config

# apt-getinstall snmp snmpd libsnmp-dev

3、configure: error:Curl library not found

#apt-getinstall php5-curl -y

4、configure: error:LIBXML2 library not found

#apt-getinstall libcurl4-gnutls-dev

5、在profile中不能设置中文:

  "You are not able to choose some of

the languages, because locales for them are not installed on the web

server." 两个问题排查一下:

a

)检查zabbix的php文件:/usr/share/zabbix/include/locales.inc.php

检查“ 'zh_CN' =>

array('name' => _('Chinese (zh_CN)'),        'display'

=> true) ”display的值是否为true

b

)执行命令:dpkg-reconfigure

locales,检查是否安装中文包,如果没有,安装中文包:apt-getinstall

-y language-pack-kde-zh-hans

三、其他常规编译报错

以下摘自网络:

1、configure: error:No curses/termcap library found

网上有的说法是:

--with-named-curses-libs=/usr/lib/libncursesw.so.5

其实是不对的,虽然能解决configure的错误,但是make的时候会提示错误,正确的做法应该是

yum -y install ncurses-devel

debian: apt-get install libncurses5-dev

[if !supportLineBreakNewLine]

[endif]

2、configure: error:xml2-config not found

yum-y install libxml2-devel

debian:apt-get install libxml2-dev

[if !supportLineBreakNewLine]

[endif]

3、configure: error:Cannot find OpenSSL's

yum-y install openssl-devel

[if !supportLineBreakNewLine]

[endif]

4、configure: error:libjpeg.(a|so) not found

yum-y install gd

yum -y install gd-devel

debian:apt-get install libjpeg-dev

[if !supportLineBreakNewLine]

[endif]

5、configure: error:libpng.(a|so) not found.

apt-getinstall libpng12-dev

[if !supportLineBreakNewLine]

[endif]

6、configure: error:cannot find output from lex; giving up

yum-y install flex

[if !supportLineBreakNewLine]

[endif]

7、configure: error:mod_deflate has been requested but can not be built due to prerequisitefailures

yum-y install zlib-devel openssl-devel

debian:apt-get install zlib1g-dev

[if !supportLineBreakNewLine]

[endif]

8、configure: error:libXpm.(a|so) not found.

apt-getinstall libxpm-dev

[if !supportLineBreakNewLine]

[endif]

9、configure: error:freetype.h not found.

apt-getinstall libfreetype6-dev

[if !supportLineBreakNewLine]

[endif]

10、configure: error:...No recognized SSL/TLS toolkit detected

apt-getinstall libssl-dev

[if !supportLineBreakNewLine]

[endif]

11、Configure:error: xml2-config not found. Please check your libxml2 installation.

yuminstall libxml2 libxml2-devel (For Redhat & Fedora)

# aptitude install libxml2-dev (For ubuntu)

[if !supportLineBreakNewLine]

[endif]

12、 Checking for

pkg-config…/usr/bin/pkg-config

configure:

error: Cannot find OpenSSL’s

yum install openssl openssl-devel

[if !supportLineBreakNewLine]

[endif]

13、Configure:error: Please reinstall the BZip2 distribution

yuminstall bzip2 bzip2-devel

[if !supportLineBreakNewLine]

[endif]

14、Configure:error: Please reinstall the libcurl distribution -easy.h should be in/include/curl/

#yuminstall curl curl-devel (For Redhat & Fedora)

#install libcurl4-gnutls-dev (For Ubuntu)

[if !supportLineBreakNewLine]

[endif]

15、Configure: error:libjpeg.(also) not found.

yum-y install gd

yum -y install gd-devel

yum install libjpeg libjpeg-devel

[if !supportLineBreakNewLine]

[endif]

16、Configure:error: libpng.(also) not found.

yuminstall libpng libpng-devel

apt-get install libpng12-dev

[if !supportLineBreakNewLine]

[endif]

17、Configure:error: freetype.h not found.

yuminstall freetype-devel

[if !supportLineBreakNewLine]

[endif]

18、Configure: error:Unable to locate gmp.h

yuminstall gmp-devel

[if !supportLineBreakNewLine]

[endif]

19、Configure:error: Cannot find MySQL header files under /usr.Note that the MySQL clientlibrary is not bundled anymore!

yuminstall mysql-devel (For Redhat & Fedora)

# apt-get install libmysql++-dev (For Ubuntu)

[if !supportLineBreakNewLine]

[endif]

20、Configure: error:Please reinstall the ncurses distribution

yuminstall ncurses ncurses-devel

[if !supportLineBreakNewLine]

[endif]

21、 Checking for

unixODBC support… configure:

error: ODBC header file ‘/usr/include/sqlext.h’not found!

yuminstall unixODBC-devel

[if !supportLineBreakNewLine]

[endif]

22、Configure:error: Cannot find pspell

yuminstall pspell-devel

[if !supportLineBreakNewLine]

[endif]

23、configure:error: mcrypt.h not found. Please reinstall libmcrypt.

yuminstall libmcrypt libmcrypt-devel (For Redhat & Fedora)

# apt-get install libmcrypt-dev

[if !supportLineBreakNewLine]

[endif]

24、Configure:error: snmp.h not found. Check your SNMP installation.

yuminstall net-snmp net-snmp-devel

[if !supportLineBreakNewLine]

[endif]

25、开启LDAP服务还需要

yum-y install openldap-devel openldap-servers openldap-clients

[if !supportLineBreakNewLine]

[endif]

26、configure: error:No curses/termcap library found

网上有的说法是:–with-named-curses-libs=/usr/lib/libncursesw.so.5

其实是不对的,虽然能解决configure的错误,但是make的时候会提示错误,正确的做法应该是

yum -y install ncurses-devel (for redhat)

apt-get install libncurses5-dev(for debian)

[if !supportLineBreakNewLine]

[endif]

27、configure: error:cannot find output from lex; giving up

yum-y install flex

[if !supportLineBreakNewLine]

[endif]

28、configure: error:mod_deflate has been requested but can not be built due to prerequisitefailures

yum-y install zlib-devel openssl-devel

debian:apt-get install zlib1g-dev

[if !supportLineBreakNewLine]

[endif]

29、configure: error:libXpm.(a|so) not found.

apt-getinstall libxpm-dev

make&& make install

#此处指定sysconfdir配置文件的路径就在/etc/zabbix/目录下了,如果不指定默认在/usr/local/etc下

10、Copy zabbixserver端跟agent端的启动脚本,并设置执行权限

cp -r /root/tools/zabbix-3.0.16/misc/init.d/tru64/*   /etc/init.d/

chmod +x /etc/init.d/zabbix_*

sed -i "s@DAEMON=/usr/local/sbin/@DAEMON=/etc/zabbix/sbin/@g"/etc/init.d/zabbix_server

sed -i "s@DAEMON=/usr/local/sbin/@DAEMON=/etc/zabbix/sbin/@g"/etc/init.d/zabbix_agentd

注:具体要查看拷贝后zabbix_server  zabbix_agentd里面的路径,官方zabbix安装默认路径是  /usr/local/zabbix

[root@localhost php]# chkconfig --add /etc/init.d/zabbix_server

[root@localhost php]# chkconfig --add /etc/init.d/zabbix_agentd

[root@localhost php]# chkconfig httpd on

[root@localhost php]# chkconfig mysqld on

[root@localhost php]# chkconfig zabbix_server on

[root@localhost php]# chkconfig zabbix_agentd on

11、将zabbix的页面文件copy到指定目录(跟apache配置的相同即可)

mkdir  -p /var/www/html/zabbix

/usr/src/zabbix-2.2.2

cp-a  zabbix-2.2.2/frontends/php/*/var/www/html/zabbix/

chown-R  apache.apache /var/www/html/zabbix/

12、配置php文件,适应zabbix安装所需的参数

安装php

--with-mysql=/usr/local/mysql\

--with-mysqli=/usr/local/mysql/bin/mysql_config\

--with-xmlrpc\

--with-openssl\

--enable-bcmath\

--with-zlib\

--with-freetype-dir\

--with-gd\

--with-jpeg-dir\

–with-openssl \

--with-png-dir\

--with-iconv=/usr/local/libiconv\

--enable-short-tags\

--enable-sockets\

--enable-zend-multibyte\

--enable-soap\

--enable-mbstring\

--enable-static\

--enable-gd-native-ttf\

--with-curl\

--with-xsl\

--with-gettext\

--enable-ftp\

--with-libxml-dir\

--with-config-file-path=/usr/local/php/lib

make  &&make  install

vim/etc/php.ini

date.timezone= Asia/Shanghai

max_execution_time= 300

max_input_time= 300

post_max_size= 32M

memory_limit= 128M

mbstring.func_overload= 2   #这一句需要注释

13、配置apache文件,定义安装访问zabbix的虚拟主机

vim/etc/httpd/conf/httpd.conf

ServerName127.0.0.1

DocumentRoot "/var/www/html"

ServerName192.168.128.130

在LoadModule php5_module       modules/libphp5.so下添加

AddTypeapplication/x-httpd-php .php .php3 .php4

    DirectoryIndex index.html index.php

在此处添加  index.php

[root@localhost bin]# ./apachectl   -t

Syntax OK

[root@localhost bin]# ./apachectl   restart

14、配置zabbix server端的文件,定义数据库的IP、用户名、密码

vim/etc/zabbix/etc/zabbix_server.conf

PidFile=/tmp/zabbix_server.pid

ListenPort=10051

DBHost=192.168.239.130

DBName=zabbix

DBUser=zabbix

DBPassword=123456

StartPollers=30

  #开启多线程数,一般不要超过30个

StartTrappers=20

 #trapper线程数

StartPingers=10

  #fping线程数

StartDiscoverers=120

MaxHousekeeperDelete=5000

CacheSize=1024M

  #用来保存监控数据的缓存数,根据监控主机的数量适当调整

StartDBSyncers=8

 #数据库同步时间

HistoryCacheSize=1024M

TrendCacheSize=128M

                    #总趋势缓存大小

HistoryTextCacheSize=512M

AlertScriptsPath=/etc/zabbix/alertscripts   修改成自己zabbix的目录(/etc/zabbix/share/zabbix/alertscripts)

LogSlowQueries=1000

###网络上配置信息

#egrep -v "(#|^$)" /etc/zabbix/zabbix_server.conf

LogFile=/var/log/zabbix/zabbix_server.log

DBHost=localhost

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix

DBSocket=/var/lib/mysql/mysql.sock

DBPort=3306StartPollers=160                 (测试环境默认值即可)

StartTrappers=10                             (测试环境默认值即可)

StartPingers=100                             (测试环境默认值即可)

StartDiscoverers=120                         (测试环境默认值即可)

MaxHousekeeperDelete=5000                    (测试环境默认值即可)

CacheSize=1024M                              (测试环境默认值即可)

StartDBSyncers=4                             (测试环境默认值即可)

HistoryCacheSize=1024M                       (测试环境默认值即可)

TrendCacheSize=1024M                         (测试环境默认值即可)

HistoryTextCacheSize=512M                    (测试环境默认值即可)

AlertScriptsPath=/etc/zabbix/alertscripts

LogSlowQueries=1000

自己虚拟机配置

[root@zabbix-server~]# grep   '^[a-Z]'    /etc/zabbix/etc/zabbix_server.conf

ListenPort=10051

LogFile=/tmp/zabbix_server.log

DBHost=localhost

DBName=zabbix

DBUser=zabbix

DBPassword=123456

DBSocket=/tmp/mysql.sock

DBPort=3306

ListenIP=127.0.0.1

Timeout=4

LogSlowQueries=3000

客户端:

# vim /etc/zabbix/zabbix_agentd.conf

Server=127.0.0.1                     此处添加服务端的 ip,如服务器不为本机,则需要填写远端 zabbix_server 的 ip 地址 

ServerActive=127.0.0.1               此处修改为服务端的 ip 

/tmp/zabbix_agentd.log               修改日志路径 

UnsafeUserParameters=0               默认是不启用自定义脚本功能的,要自定义 key,需开启,设置为 1 

Include=/etc/zabbix/zabbix_agentd.conf.d/     自定义的agentd配置文件可以写在

自己虚拟机配置

[root@zabbix-serveretc]# grep  '^[a-Z]' zabbix_agentd.conf

PidFile=/tmp/zabbix_agentd.pid

LogFile=/tmp/zabbix_agentd.log

LogFileSize=0

Server=192.168.128.130                              (写zabbix服务器的ip)

#ServerActive=192.168.128.130                        (写zabbix服务器的ip)

Hostname=zabbix-server  #zabbix服务器页面添加时的主机相同

[root@zabbix-serveretc]#

15、启动apache服务跟zabbix服务

/etc/init.d/httpdstart

/etc/init.d/zabbix_serverstart

16、访问安装界面按照界面提示一步一步的完成安装

http://192.168.239.130/zabbix/setup.php

 a) 进入安装界面点击Next

 b) 确保所有的监测项都是OK,点击Next

 c)填写zabbix数据库的用户名、密码、地址等信息,点击Test connection,OK后点击Next

 d) 填写zabbix服务器的信息,主机名,server程序监听的的端口,主机IP地址等,如果server跟web在一台服务器上保持默认即可,点击Next

 e) 确认前面几部填写的信息没有问题的话点击Next

 f) 检查web程序的config文件,如果没问题会显示OK,直接点击finish即可完成安装(如果此处有问题一般是zabbix虚拟主机目录文件的权限问题,上面已经有设置的过程一般不会出现问题)

#如果因为手误,数据库密码或者用户名等的填写错了,后面会一直报错,我们可以手动的去编辑配置文件vim /var/www/html/zabbix/conf/zabbix.conf.php  手动定义相关的参数即可

 g) 进入登录界面点击登录,默认admin  zabbix

#至此,server端的安装完成

Agent端

1、安装开发软件包

yum-y groupinstall "Development Tools"

yum-y install ntpdate

2、同步客户端时间,防止跟服务器端不一致,导致检测到不可用的监控数据

ntpdatepool.ntp.org

3、创建zabbix运行所需要的用户跟组

groupadd -g 201 zabbix

useradd-g zabbix -u 201 -m zabbix

4、解压安装zabbixagent端

cd/usr/src/

tarxf zabbix-2.2.2.tar.gz

cdzabbix-2.2.2

./configure --prefix=/etc/zabbix -enable-agent

make&& make install

5、copy agent端运行所需要的脚本

cpmisc/init.d/tru64/zabbix_agentd   /etc/init.d/

chmod+x /etc/init.d/zabbix_agentd

6、配置agent端配置文件

vim/etc/zabbix/etc/zabbix_agentd.conf

#此处千万别写成了zabbix_agent.conf,否则配置了不生效

Server=192.168.239.130

                  #填写Server的IP地址

ServerActive=192.168.239.130

            #修改为Server的IP地址

Hostname=Centos-03

                      #填写本机的HostName,注意Server端要能解析

UnsafeUserParameters=1

                  #是否允许自定义的key,1为允许,0为不允许

Include=

etc/zabbix/zabbix_agentd.conf.d/#自定义的agentd配置文件(key)可以在这里面写;

7、启动zabbix agent端

/etc/init.d/zabbix_agentdstart

解决zabbix中文乱码、汉化

1、在windows中找一个自己喜欢的字体或者去网上下载一个字体

2、将字体上传至/var/www/html/zabbix/fonts目录下

3、修改zabbix页面管理的中文字体设置

vim

/var/www/html/zabbix/include/defines.inc.php        #修改以下两行

define('ZBX_FONT_NAME','simkai');

define('ZBX_GRAPH_FONT_NAME', 'simkai');

4、登陆页面设置相应用户的默认语言Administrator—->Users(此处要保证显示的是用户,否则显示的都是用户组)

5、点击用户名进入用户信息编辑,默认语言选择简体中文,然后点击save保存

6、刷新页面

1#已经成为中文,在有些地方还是会有英文的但是zabbix的汉化相对其他开源软件来说已经做的十分的好了!!

添加windows监控主机

https://www.zabbix.com/downloads/2.2.0/zabbix_agents_2.2.0.win.zip

.exe文件copy到磁盘根目录的zabbix文件夹

配置拷贝到c盘根目录,修改名字为zabbix_agentd.conf

你可能感兴趣的:(zabbix学习笔记安装加实践(centos6.5+zabbix3.0细节))