zabbix服务器搭建

时间:2022-06-03 17:48:44

zabbix服务器源码安装

参看官方文档 这里不做过多的翻译,我的系统是centos6.5,安装的时候是base安装,所以要装一些其他依赖包,除此之外,还有一些php插件:

extension=bcmath.so
extension=gd.so
extension=gettext.so
extension=mysqli.so

下面介绍一下二次编译php插件的方法:

[root@mediawiki bcmath]# which php-config
/usr/local/php/bin/php-config
[root@mediawiki bcmath]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
[root@mediawiki bcmath]# ./configure --with-php-config=/usr/local/php/bin/php-config
[root@mediawiki bcmath]# make
[root@mediawiki bcmath]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-/ echo "extension=bcmath.so" >> /usr/local/php/php.ini

PHP gd FreeType support,从官网下载:http://jaist.dl.sourceforge.net/project/freetype/freetype2/2.5.5/freetype-2.5.5.tar.bz2

下面几个重要的插件支持

zabbix
PHP gd JPEG support
PHP gd FreeType support
PHP gettextwget http://down1.chinaunix.net/distfiles/jpegsrc.v6b.tar.gz
# tar -xf jpegsrc.v6b.tar.gz
# ./configure --prefix=/usr/local/jpeg-6b
# make
# mkdir -p /usr/local/jpeg-6b/man/man1/
# mkdir -p /usr/local/jpeg-6b/bin/
# make install wget http://jaist.dl.sourceforge.net/project/freetype/freetype2/2.5.5/freetype-2.5.5.tar.bz2
# ./configure --prefix=/usr/local/freetype
# make
# make install # ./configure --with-php-config=/usr/local/php/bin/php-config --with-jpeg-dir=/usr/local/jpeg-6b/ --with-freetype-dir=/usr/local/freetype/
# make
# make install mysql_connect(): No such file or directory [include/db.inc.php:]
Error connecting to database [No such file or directory]
vim php.ini
mysqli.default_socket = /data/mysql/mysql.sock

我知道,到这里有些同学犯困惑了,找不到php.ini文件,学生还是提倡多看官方文档的介绍:http://php.net/manual/en/function.phpinfo.php

zabbix服务器搭建

按照上面的介绍,写个php页面<?php echo phpinfo(); ?>,再从浏览器访问该页面就能看到

zabbix服务器搭建

zabbix下载安装
1.下载zabbix
下载地址  http://www.zabbix.com/download.php,在此我使用zabbix-2.0.13.tar.gz
#wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.0.13/zabbix-2.0.13.tar.gz
2.安装zabbix所需的组件
#yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI php-gd php-xml php-bcmath 
3.数据库创建并导入数据
#tar zxf zabbix-2.0..tar.gz
#cd zabbix-2.0.
#mysql -uroot -p
>create database zabbix;
>grant all on zabbix.* to zabbix@localhost identified by 'redhat';
>flush privileges;
# mysql -uzabbix -predhat zabbix < schema.sql
# mysql -uzabbix -predhat zabbix < images.sql
#mysql -uzabbix -predhat zabbix < data.sql

//为zabbix创建自己的数据库,以便zabbix可以把收集到的数据信息存放在那里调用。

4.编译安装
#./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-proxy --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl
//--prefix指定zabbix安装目录,--enable-server 支持zabbix服务器
--enable-agent支持zabbix代理
--enable-proxy 支持zabbix代理服务器
--with-mysql 使用MySQL客户端库可以选择指定路径mysql_config
--with-net-snmp 使用net - snmp软件包,择性地指定路径NET - SNMP配置
 --with-libcurl 使用curl包
#make && make install
5. 编译安装完毕后,在/usr/local/zabbix下面有下面几个目录:
root@192.168.100.252:/usr/local# tree zabbix/ -L
zabbix/
├── bin
│   ├── zabbix_get
│   └── zabbix_sender
├── etc
│   ├── zabbix_agent.conf
│   ├── zabbix_agent.conf.d
│   ├── zabbix_agentd.conf  客户端配置文件
│   ├── zabbix_agentd.conf.d  自定义监控文件存放目录
│   ├── zabbix_proxy.conf  
│   ├── zabbix_proxy.conf.d
│   ├── zabbix_server.conf  服务器端配置文件
│   └── zabbix_server.conf.d
├── sbin
│   ├── zabbix_agent
│   ├── zabbix_agentd
│   ├── zabbix_proxy
│   └── zabbix_server
├── scripts
└── share
├── man
└── zabbix directories, files

服务器端配置文件:

root@192.168.100.252:/usr/local# egrep -v "(^#|^$)" zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=redhat
DBSocket=/data/mysql/mysql.sock
DBPort=

启动服务端进程:

root@192.168.100.252:/usr/local# cd zabbix/sbin/
root@192.168.100.252:/usr/local/zabbix/sbin# ./zabbix_server
5. 从编译生成的文件中取出客户端文件,传送到客户端机器,目录下文件如下:
root@192.168.100.246:/usr/local/zabbix# tree -L
.
├── bin
│   ├── zabbix_get
│   └── zabbix_sender
├── etc
│   ├── zabbix_agent.conf
│   ├── zabbix_agent.conf.d
│   ├── zabbix_agentd.conf
│   └── zabbix_agentd.conf.d
├── sbin
│   ├── zabbix_agent
│   └── zabbix_agentd
└── scripts
└── monitor_mysql.sh directories, files 
客户端配置文件:
root@192.168.100.246:/usr/local# egrep -v "(^#|^$)" zabbix/etc/zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
Server=192.168.100.252
Hostname=server
Timeout=
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/

启动客户端进程:

root@192.168.100.246:/usr/local# cd zabbix/sbin/
root@192.168.100.246:/usr/local/zabbix/sbin# ./zabbix_agentd
6. 配置lighttpd启动zabbix前端web显示
6.1 编译安装lighttpd
. Upload fcgi-2.4..tar.gz , unzip , then
./configure
make
make install . UpLoad pcre-8.11.tar.gz , unzip, then:
./configure
make
make install . UpLoad lighttpd-1.4..tar.gz, unzip, then:
./configure --with-openssl --prefix=/usr/local/services/lighttpd
make
make install

6.2 配置lighttpd,启动进程

root@192.168.100.252:/usr/local/services/lighttpd/sbin# egrep -v "(^#|^$)" zabbix_httpd.conf
server.max-fds = 10240
server.max-connections = 4096
server.max-keep-alive-requests = 0
server.event-handler = "linux-sysepoll"
server.network-backend = "linux-sendfile"
server.modules = (
"mod_cgi",
"mod_fastcgi",
"mod_accesslog",
"mod_expire",
"mod_access",
"mod_compress",
"mod_rewrite"
)
server.document-root = "/data/release/htdocs"
server.port= 8001
server.errorlog = "/data/release/lighttpd_logs/error.log"
accesslog.filename = "/data/release/lighttpd_logs/access.log"
server.core-files = "enable"
index-file.names = ( "index.php", "index.html" )
mimetype.assign = (
".gz" => "application/x-gzip",
".swf" => "application/x-shockwave-flash",
".tar.gz" => "application/x-tgz",
".tgz" => "application/x-tgz",
".tar" => "application/x-tar",
".zip" => "application/zip",
".mp3" => "audio/mpeg",
".m3u" => "audio/x-mpegurl",
".wma" => "audio/x-ms-wma",
".wax" => "audio/x-ms-wax",
".wav" => "audio/x-wav",
".gif" => "image/gif",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".png" => "image/png",
".css" => "text/css",
".html" => "text/html",
".htm" => "text/html",
".js" => "text/javascript",
".text" => "text/plain",
".txt" => "text/plain",
".dtd" => "text/xml",
".xml" => "text/xml",
".mpeg" => "video/mpeg",
".mpg" => "video/mpeg",
".avi" => "video/x-msvideo",
".wmv" => "video/x-ms-wmv",
".bz2" => "application/x-bzip",
".tbz" => "application/x-bzip-compressed-tar",
".tar.bz2" => "application/x-bzip-compressed-tar"
)
static-file.exclude-extensions = ( ".fcgi", ".php", ".cgi", ".pl" )
cgi.assign = (
".pl" => "/usr/bin/perl",
".php" => "/usr/local/php/bin/php-cgi"
)
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"host" => "127.0.0.1",
"port" => 1026,
"bin-path" => "/usr/local/php/bin/php-cgi"
)
)
)
url.rewrite-once = (
"^/wiki/upload/(.+)" => "/wiki/upload/$1",
"^/$" => "/w/index.php",
"^/wiki/([^?]*)(?:\?(.*))?" => "/w/index.php?title=$1&$2"
)
expire.url = (
"/images/" => "access 1 months",
"/scripts/" => "access 1 months",
"/img/" => "access 1 months",
"/js/" => "access 1 months",
"/css/" => "access 1 months"
)

 

6.3 启动lighttpd进程
# ./zabbix_lighttpd -f zabbix_httpd.conf