zbbix服务器搭建_Linux系统搭建Zabbix监控服务器

本文详细介绍了如何在CentOS5.7系统上通过yum安装LAMP环境,然后一步步配置并安装Zabbix 2.0.3监控服务器,包括创建数据库、导入数据、编译安装、配置服务端和客户端、设置数据库连接以及解决可能出现的问题。
摘要由CSDN通过智能技术生成

监控服务器: Hostname: station3.example.com   IP: 192.168.1.3   OS: CentOS5.7 32bit

一、yum安装LAMP

1.1安装主程序

# yum -y install httpd php mysql mysql-server php-mysql

1.2安装apache扩展

# yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

1.3安装php扩展

# yum -y install php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-bcmath

1.4安装mysql扩展

# yum -y install mysql-connector-odbc mysql-devel libdbi-dbd-mysql

1.5编译的apache加载php

# vim httpd.conf

增加391 DirectoryIndex index.php index.html index.html.var        #php目录索引

1.6开机启动

# service httpd start

# chkconfig httpd on

# service mysqld start

# chkconfig mysqld on

1.7设置mysql数据库root帐号密码。

# mysqladmin -u root password 'redhat'

1.8测试apache与php、mysql的连接:

# cd /var/www/html

# vim index.php

it works!

$link=mysql_connect('localhost','root','redhat');

if($link)

echo "success";

else

echo "fail";

?>

测试成功

二、Zabbix 安装

2.1yum安装zabbix需要的其他组件

# yum -y install net-snmp-devel curl-devel

2.2添加zabbix用户

# groupadd zabbix           添加zabbix组

# useradd zabbix -g zabbix   新建zabbix用户并将其加入到zabbix组

2.3解压软件

# tar zxvf zabbix-2.0.3.tar.gz -C /usr/src

# cd /usr/src/zabbix-2.0.3

2.4为zabbix创建数据库并添加用户

# /etc/init.d/mysqld start

Starting MySQL                      [  OK  ]

# mysql -uroot -predhat

mysql> create database zabbix character set utf8;#新建一个数据库叫zabbix

mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'redhat';

#给zabbix这个数据库授权,只允许zabbix这个用户通过本地登录,zabbix用户的密码为redhat

mysql> flush privileges;

2.5将zabbix源码包中的数据导入到新建的zabbix数据库

注:这一步是zabbix2.3与其他旧版不同的,在版本2.3里数据库的结构和名字都变了,而且导入也要严格按照顺序来。

# mysql -uzabbix -p'redhat' zabbix < /usr/src/zabbix-2.0.3/database/mysql/schema.sql

#这个是zabbix的数据库表结构,要先导入。

# mysql -uzabbix -p'redhat' zabbix < /usr/src/zabbix-2.0.3/database/mysql/images.sql

# mysql -uzabbix -p'redhat' zabbix < /usr/src/zabbix-2.0.3/database/mysql/data.sql

2.6编译安装

# yum -y install gcc*  先安装gcc库,否则编译报错找不到C编译器

# ./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --with-mysql=/usr/bin/mysql_config --with-net-snmp --with-libcurl

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

Now run 'make install'

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

[root@station3 zabbix-2.0.3]# make install

2.7 为zabbix server添加端口

[root@station3 ~]# vim /etc/services

添加如下信息

zabbix-agent    10050/tcp                       # Zabbix Agent

zabbix-agent    10050/udp                       # Zabbix Agent

zabbix-trapper  10051/tcp                       # Zabbix Trapper

zabbix-trapper  10051/udp                       # Zabbix Trapper

2.8 配置文件目录软连接

# ls /usr/local/zabbix/etc

zabbix_agent.conf    zabbix_agentd.conf    zabbix_proxy.conf    zabbix_server.conf

zabbix_agent.conf.d  zabbix_agentd.conf.d  zabbix_proxy.conf.d  zabbix_server.conf.d

# ln -s /usr/local/zabbix/etc /etc/zabbix

2.9更改配置文件中数据库相关的用户名密码

# vim /etc/zabbix/zabbix_server.conf

修改以下三项:

DBName=zabbix

DBUser=zabbix

DBPassword=redhat

注:DBPassword 默认是被注释掉的

www.it165.net

# vim /etc/zabbix/zabbix_agentd.conf

Hostname=station3.example.com

ServerActive=192.168.1.3:20051

2.10给zabbix服务端程序做软链接

# ll /usr/local/zabbix/bin

total 428

-rwxr-xr-x 1 root root 195326 Oct 24 13:59 zabbix_get

-rwxr-xr-x 1 root root 230852 Oct 24 13:59 zabbix_sender

# ll /usr/local/zabbix/sbin

total 5048

-rwxr-xr-x 1 root root  547886 Oct 24 13:59 zabbix_agent

-rwxr-xr-x 1 root root  622208 Oct 24 13:59 zabbix_agentd

-rwxr-xr-x 1 root root 1878726 Oct 24 13:59 zabbix_proxy

-rwxr-xr-x 1 root root 2097879 Oct 24 13:59 zabbix_server

# cd /usr/local/zabbix/bin/

# for i in *;do ln -s /usr/local/zabbix/bin/${i} /usr/bin/${i};done

# cd /usr/local/zabbix/sbin/

# for i in *;do ln -s /usr/local/zabbix/sbin/${i} /usr/sbin/${i};done

2.11添加数据库Lib文件位置到/etc/ld.so.conf中,并使其生效

# echo "/usr/local/mysql-5.1.48/lib/mysql/" >> /etc/ld.so.conf

# ldconfig

2.12拷贝相应的web程序到相关WEB服务目录下

# cp -r /usr/src/zabbix-2.0.3/frontends/php/ /var/www/html/zabbix/

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

2.13拷贝zabbix服务端和客户端启动脚本到/etc/init.d目录下.

注:这个地方存放脚本的目录结构也有变化,没有redhat这个目录,所以我cp的fedora目录里的启动脚本,具体区别可以阅读README。关键是是看zabbix_xxxx的文件结构符合redhat的Sys V结构。

# ll /usr/src/zabbix-2.0.3/misc/init.d/fedora/core5

total 8

-rwxr-xr-x 1 1005 1005 541 Oct  3 22:41 zabbix_agentd

-rwxr-xr-x 1 1005 1005 543 Oct  3 22:41 zabbix_server

# cp /usr/src/zabbix-2.0.3/misc/init.d/fedora/core5/zabbix_server /etc/init.d

# cp /usr/src/zabbix-2.0.3/misc/init.d/fedora/core5/zabbix_agentd /etc/init.d

2.14修改启动脚本

# vim /etc/init.d/zabbix_server

ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"  修改zabbix_server实际位置

# service zabbix_server start

Starting Zabbix Server:                                    [  OK  ]

# vim /etc/init.d/zabbix_agentd

ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"

# service zabbix_agentd start

Starting Zabbix Agent:                                     [  OK  ]

[root@station3 ~]# chkconfig zabbix_server on

[root@station3 ~]# chkconfig zabbix_agentd on

2.15修改PHP配置文件php.ini内容

# vim /etc/php.ini

date.timezone = Asia/Shanghai

post_max_size = 32M

max_execution_time = 300

max_input_time = 300

memory_limit = 128M

mbstring.func_overload = 2

# service httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd:                                            [  OK  ]

四、浏览器安装

(1)浏览器打开刚安装的zabbix  http://192.168.1.3/zabbix

# yum -y install php-bcmath     yum安装的php直接

自己编译php,那么在编译的时候加--enable-bcmath

cd php-5.2.7/ext/bcmath

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make && make install (make 可以得到so路径)

so路径拷贝到  extension路径

vim php.ini

extension=bcmath.so

重启apache

检测php组件,全部OK才可以点击next

(3)连接zabbix数据库

(4)设置zabbix服务IP和端口,name可以忽略

如果不能保存配置文件,点击Down将php生成的文件下载到本地,然后在上传到/var/www/html/zabbix/conf下,也可以用本地记事本打开zabbix.conf.php,复制其中的内容,在 vim /var/www/html/zabbix/conf/zabbix.conf.php,将刚才复制的内容粘贴,保存退出,在点击try连接测试,出现下图的OK即可。

(5)输入用户名密码登录

默认的用户名:admin   密码:zabbix

三、排错过程

安装完成,但有过问题,zabbix server竟然不能监控自己。 即使重启服务,任然报错。not running, not monitored.

# service zabbix_server restart

#service zabbix_agentdd restart

排错思路:1. 服务  2.端口   3.配置文件 4. 日志

检查对应进程都已经启动

# ps aux | grep zabbix

zabbix    4229  0.0  0.1   6016   736 ?        S    09:31   0:00 /usr/local/zabbix/sbin/zabbix_agentd

zabbix    4242  0.0  0.1   6016   800 ?        S    09:31   0:00 /usr/local/zabbix/sbin/zabbix_agentd

zabbix    4243  0.0  0.1   6016   608 ?        S    09:31   0:00 /usr/local/zabbix/sbin/zabbix_agentd

zabbix    4244  0.0  0.1   6016   608 ?        S    09:31   0:00 /usr/local/zabbix/sbin/zabbix_agentd

zabbix    4245  0.0  0.1   6016   608 ?        S    09:31   0:00 /usr/local/zabbix/sbin/zabbix_agentd

zabbix    4246  0.0  0.1   6032   812 ?        S    09:31   0:00 /usr/local/zabbix/sbin/zabbix_agentd

zabbix    4248  0.0  0.4  10264  2484 ?        S    09:31   0:00 /usr/local/zabbix/sbin/zabbix_server

root     15127  0.0  0.1   4880   668 pts/1    R+   12:56   0:00 grep zabbix

查看对应的日志错误,默认在/tmp/zabbix-*.log

# ll /tmp | grep zabbix

-rw-rw-r-- 1 zabbix zabbix    900 Oct 25 12:55 zabbix_agentd.log

-rw-rw-r-- 1 zabbix zabbix      4 Oct 25 09:31 zabbix_agentd.pid

-rw-rw-r-- 1 zabbix zabbix 362401 Oct 25 13:30 zabbix_server.log

-rw-rw-r-- 1 zabbix zabbix      4 Oct 25 09:31 zabbix_server.pid

# tail /tmp/zabbix_server.log

4248:20121025:133318.754 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'root'@'localhost' (using password: NO)

4248:20121025:133318.755 Database is down. Reconnecting in 10 seconds.

这是未将/usr/local/zabbix/etc/zabbix.conf.php中DB参数修改,连接失败所致。

[root@station3 ~]# vim /etc/zabbix/zabbix_server.conf

修改以下三项:

DBName=zabbix

DBUser=zabbix

DBPassword=redhat

# cat /tmp/zabbix_server.log

17376:20121025:143052.725 cannot send list of active checks to [127.0.0.1]: host [station3.example.com] not found

是因为zabbix_agentd.conf未设置IP:Port

# vim /etc/zabbix/zabbix_agentd.conf

ServerActive=192.168.1.3:20051

在configuration-> Hosts面板中Status,启用monitored, 才能监控server。

特别鸣谢:linuxsong对我的启发,算是抛砖引玉吧。期待大家的指点,多谢!

本文出自 “aha45” 博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值