监控系统之--zabbix

本操作步骤是在安装Apache和PHP的基础之上的操作,具体如何安装Apache和Php请参考【nagios主机监控系统】安装章节Apache和PHP的安装

1、下载软件,

[root@node1 ~]# wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.0.6/zabbix-2.0.6.tar.gz/download 

2.安装zabbix所需的组件(server,agent)
[root@node1 ~]# yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI
3.创建用户账号(server,agent)
[root@node1 ~]# groupadd zabbix
[root@node1 ~]# useradd -g zabbix zabbix
[root@node1 ~]# usermod -s /sbin/nologin zabbix
4.创建zabbix数据库并导入zabbix数据库数据(server)
[root@node1 ~]#  mysql -u root -p123456

mysql> grant all on zabbix.* to zabbix@localhost identified by '123456';
Query OK, 0 rows affected (2.50 sec)

mysql> create database zabbix;
Query OK, 1 row affected (0.09 sec)


[root@node1 opt]#  tar zxvf zabbix-2.0.6.tar.gz
[root@node1 opt]# cd zabbix-2.0.6
[root@node1 zabbix-2.0.6]#  mysql -uzabbix -p123456 zabbix < database/mysql/schema.sql
Warning: Using a password on the command line interface can be insecure.
[root@node1 zabbix-2.0.6]# mysql -uzabbix -p123456 zabbix < database/mysql/images.sql
Warning: Using a password on the command line interface can be insecure.
[root@node1 zabbix-2.0.6]# mysql -uzabbix -p123456 zabbix < database/mysql/data.sql
Warning: Using a password on the command line interface can be insecure.

5.编译安装(server,agent)
server: (192.168.7.201)
[root@node1 ~]#  ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl

ti/CORE -I. -I/usr/include/net-snmp    

  Enable server:         yes
  Server details:
    With database:         MySQL
    WEB Monitoring via:    cURL
    Native Jabber:         no
    SNMP:                  net-snmp
    IPMI:                  no
    SSH:                   no
    ODBC:                  no
    Linker flags:          -rdynamic      -L/usr/local/mysql/lib      -L/usr/kerberos/lib64  -L/usr/lib64 -L/usr/lib64 -L/usr/lib64/lib  -L/usr/lib64 -L/usr/lib64 -L/usr/lib64/lib  
    Libraries:             -lm -lrt  -lresolv    -lmysqlclient       -lcurl -ldl -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lidn -lssl -lcrypto -lz  -lnetsnmp -lcrypto -lm -lwrap -lcrypto  -lnetsnmp -lcrypto -lm -lwrap -lcrypto  

  Enable proxy:          no

  Enable agent:          yes
  Agent details:
    Linker flags:          -rdynamic     -L/usr/kerberos/lib64
    Libraries:             -lm -lrt  -lresolv    -lcurl -ldl -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lidn -lssl -lcrypto -lz

  Enable Java gateway:   no

  LDAP support:          no
  IPv6 support:          yes

***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************


# make install
agent:  (192.168.7.249)
# ./configure --enable-agent

Configuration:

  Detected OS:           linux-gnu
  Install path:          /usr/local
  Compilation arch:      linux

  Compiler:              gcc
  Compiler flags:        -g -O2 

  Enable server:         no

  Enable proxy:          no

  Enable agent:          yes
  Agent details:
    Linker flags:          -rdynamic   
    Libraries:             -lm -lrt  -lresolv  

  Enable Java gateway:   no

  LDAP support:          no
  IPv6 support:          no

***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************


# make install
这里笔者由于当时编译时忘记自定义安装目录导致zabbix配置文件使用了默认路径,在/usr/local/etc/下,这里若重新编译则下面更改的地方较多,后面的内容都以此路径为准。
参照本博配置的朋友,建议编译时加 --prefix=/usr/local/zabbix 参数,则zabbix配置文件默认在/usr/local/zabbix/etc目录下,后面启动服务前需加载zabbix目录下bin与sbin目录的环境变量
默认zabbix安装路径/usr/local/下的bin与sbin目录因为与系统合并,所以无需加载环境变量
.编辑配置文件(server,agent)
[root@node1 ~]#  cd /usr/local/etc/
去掉配置文件注释:
# cat zabbix_server.conf |grep -v "#" |grep -v "^$" > zabbix_server.conf.bak
# cp zabbix_server.conf.bak zabbix_server.conf
# cat zabbix_agentd.conf |grep -v "#" |grep -v "^$" > zabbix_agentd.conf.bak
# cp zabbix_agentd.conf.bak zabbix_agentd.conf
server: (192.168.7.201)
# vi /usr/local/etc/zabbix_server.conf
修改如下内容并删除其他未修改参数条目:
-------------
LogFile=/var/log/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
-------------
# vi /usr/local/etc/zabbix_agentd.conf
修改如下内容并删除其他未修改参数条目:
-------------
LogFile=/var/log/zabbix_agentd.log
Server=127.0.0.1,192.168.7.201
UnsafeUserParameters=1
-------------
agent:  (192.168.7.249)
# vi /usr/local/etc/zabbix_agentd.conf
修改如下内容并删除其他未修改参数条目:
-------------
LogFile=/var/log/zabbix_agentd.log
Server=192.168.7.201
UnsafeUserParameters=1
-------------
# touch /var/log/zabbix_server.log
# chmod 777 /var/log/zabbix_server.log
# touch /var/log/zabbix_agentd.log
# chmod 777 /var/log/zabbix_agentd.log

7、启动守护进程(server,agent)
在服务器端运行启动zabbix_server
# zabbix_server
server启动端口为10051
在所有被监控的机器上运行zabbix_agentd 。

[root@node1 etc]# zabbix_server
zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory

1.先确认/usr/local/mysql/lib/下是否有libmysqlclient.so.18这个文件.
ll /usr/local/mysql/lib/|grep libmysqlclient.so.18
2.修改ld.so.conf文件
echo "/usr/local/mysql/lib" >>/etc/ld.so.conf
然后执行ldconfig使其生效.


[root@node1 etc]# zabbix_server
zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
[root@node1 etc]#  locate libmysqlclient.so.18
[root@node1 etc]#  locate libmysqlclient.*
[root@node1 etc]# whereis libmysqlclient.so.18
libmysqlclient.so:
[root@node1 etc]# ll /usr/local/mysql/lib/|grep libmysqlclient.so.18
lrwxrwxrwx 1 mysql mysql        20 Jan  7 20:39 libmysqlclient_r.so.18 -> libmysqlclient.so.18
lrwxrwxrwx 1 mysql mysql        24 Jan  7 20:39 libmysqlclient_r.so.18.1.0 -> libmysqlclient.so.18.1.0
lrwxrwxrwx 1 mysql mysql        20 Jan  7 20:39 libmysqlclient.so -> libmysqlclient.so.18
lrwxrwxrwx 1 mysql mysql        24 Jan  7 20:39 libmysqlclient.so.18 -> libmysqlclient.so.18.1.0
-rwxr-xr-x 1 mysql mysql   8132645 Jan  7 20:25 libmysqlclient.so.18.1.0
[root@node1 etc]# echo "/usr/local/mysql/lib" >>/etc/ld.so.conf
[root@node1 etc]# ldconfig
[root@node1 etc]#  service zabbix_server restart
zabbix_server: unrecognized service
[root@node1 etc]# zabbix_server
[root@node1 etc]# zabbix_agentd
[root@node1 etc]# cd /opt/zabbix-2.0.6
[root@node1 zabbix-2.0.6]# cp misc/init.d/tru64/zabbix_server   /etc/init.d/zabbix_server
[root@node1 zabbix-2.0.6]# cp misc/init.d/tru64/zabbix_agentd   /etc/init.d/zabbix_agentd
[root@node1 zabbix-2.0.6]#  cd /etc/init.d/
[root@node1 init.d]# chmod 755 zabbix_*
[root@node1 init.d]# chkconfig --add zabbix_server 
service zabbix_server does not support chkconfig
[root@node1 init.d]# chkconfig --add zabbix_server
service zabbix_server does not support chkconfig
[root@node1 init.d]# mkdir /usr/local/apache2/htdocs/zabbix
[root@node1 init.d]#  cd frontends/php
-bash: cd: frontends/php: No such file or directory
[root@node1 init.d]# cd /opt/zabbix-2.0.6
[root@node1 zabbix-2.0.6]#  cd frontends/php
[root@node1 php]# cp -a . /usr/local/apache2/htdocs/zabbix

8.安装zabbix web界面(server)
复制ZABBIX PHP源代码文件
zabbix的服务端程序是用php写的,因此需要一个支持LAMP架构的服务器平台
现在将ZABBIX安装目录下 frontends/php 下面的php源代码文件拷贝到web服务器html文件目录下面。
这里建议用子目录替换APACHE HTML根目录或使用APACHE虚拟主机
这里测试环境我为了方便就选择了前者。
先建立一个子目录,将zabbix终端php文件拷贝到该子目录里面,执行下面的命令:
# mkdir /usr/local/apache2/htdocs/zabbix
# cd frontends/php
# cp -a . /usr/local/apache2/htdocs/zabbix

安装前端

步骤一、重新编译PHP:
./configure  --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl \
--enable-ftp --enable-sockets --disable-ipv6 --with-gd \
--with-jpeg-dir=/usr/local --with-png-dir=/usr/local \
--with-freetype-dir=/usr/local --enable-gd-native-ttf \
--with-iconv-dir=/usr/local --enable-mbstring --enable-calendar \
--with-gettext --with-libxml-dir=/usr/local --with-zlib \
--with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd \
--enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath \
--with-apxs2=/usr/local/apache2/bin/apxs

configure: error: Please reinstall the BZip2 distribution

原因如下:
1. 确认安装了 bzip2 和 bzip2-devl, 如果 没有安装之:
yum install bzip2
yum install bzip2-devel

configure: error: png.h not found.
[root@node1 php-5.4.10]# yum install libpng*

Installed: libpng-devel.x86_64 2:1.2.10-17.el5_8 libpng-devel.i386 2:1.2.10-17.el5_8
Complete!

Configure: error: freetype.h not found.
的解决办法
CentOS
yum install freetype-devel

步骤二 编译:
 make
步骤三 安装:
 make install


 "a.php" [New] 5L, 27C written

确认PHP配置文件的路径:
[root@node1 bin]# ./php  a.php | grep php.ini
Configuration File (php.ini) Path => /usr/local/php/etc
Loaded Configuration File => /usr/local/php/etc/php.ini


/usr/local/apache2/bin/apachectl restart

zabbix_server restart
zabbix_agentd restart


max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 32M
date.timezone = Asia/Shanghai
mbstring.func_overload=2

猜你喜欢

转载自gaojingsong.iteye.com/blog/2271673