环境:

rhel 6.5 64bit

目的:

构筑zabbix服务端,开启java监控端口,并且能对外进行邮件通知



添加zabbix用户与组

useradd zabbix

usermod-aG root zabbix



安装必要的包

yum  -y install php php-*curl-devel mysql mysql-server httpd php mysql-devel gnutls mysql-developenldap-devel OpenIPMI OpenIPMI* ncurses-devel unixODBC unixODBC-develmysql-connector-odbc libstdc* libX* gcc vim make alsa-lib jpackage-utils pcrepcre-devel net-snmp net-snmp-devel net-snmp-libs net-snmp-perl net-snmp-utilsrsyslog-* curl curl-devel  java* gnutls-devellibgssapi_krb5.so.2 libz.so.1 libstdc++.so.6



安装额外的包(请自行下载,一下有一些包为后期飞信机器人使用准备的)

fping-2.4b2-10.el6.x86_64.rpm

iksemel-1.4-2.el6.x86_64.rpm

iksemel-devel-1.4-2.el6.x86_64.rpm

iksemel-utils-1.4-2.el6.x86_64.rpm

libgsasl-1.8.0-0.99.el6.x86_64.rpm

libiksemel3-1.4-2_2.el6.x86_64.rpm

libntlm-1.3-3.el6.x86_64.rpm

libssh2-1.4.2-1.el6.x86_64.rpm

libssh2-devel-1.4.2-1.el6.x86_64.rpm

libssh2-docs-1.4.2-1.el6.x86_64.rpm

OpenIPMI-devel-2.0.16-14.el6.x86_64.rpm

php-bcmath-5.3.3-26.el6.x86_64.rpm

php-mbstring-5.3.3-26.el6.x86_64.rpm

php-pecl-ssh2-0.11.0-7.el6.x86_64.rpm

rsyslog-snmp-5.8.10-8.el6.x86_64.rpm



启动mysql

/etc/init.d/mysqld start



修改httpd/conf/httpd.conf文件

[root@mail ~]# vim /etc/httpd/conf/httpd.conf

添加

AddType application/x-httpd-php .php

PHPIniDir "/etc/php.ini"

修改

DirectoryIndexindex.php index.html index.html.var

添加

ServerName *:80



修改/etc/php.ini

short_open_tag = On

post_max_size = 32M

max_execution_time = 300

max_input_time = 300

date.timezone = Asia/Shanghai



添加Mysql用户

CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;

GRANT ALL ON zabbix.* TO zabbix@'localhost' IDENTIFIED BY'zabbix';

flush privileges;



向mysql注入zabbix数据库

mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql

mysql -uzabbix -pzabbix zabbix < database/mysql/p_w_picpaths.sql

mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql



拷贝php管理网页到http服务目录

cp -R  frontends/php/*  /var/www/html/zabbix



配置zabbix包

./configure --prefix=/usr/local/zabbix  --enable-server --enable-agent --with-mysql--enable-java --enable-ipv6 --with-net-snmp --with-libcurl --with-ldap  --with-ssh2 --with-jabber  --with-openipmi --with-unixodbc



编译安装

make && make install



修改服务器配置文件

vim /usr/local/zabbix/etc/zabbix_server.conf

修改以下内容:

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix

JavaGateway=192.168.1.100

JavaGatewayPort=10052

StartJavaPollers=5

AlertScriptsPath=/usr/local/zabbix/alertscripts



修改java监控端配置文件

vim /usr/local/zabbix/sbin/zabbix_java/settings.sh

LISTEN_IP="0.0.0.0"

LISTEN_PORT=10052

START_POLLERS=5



拷贝启动脚本到

cp /root/Desktop/zabbix-2.2.2/misc/init.d/fedora/core5/* /etc/init.d/

chown root.root /etc/init.d/zabbix*

chmod a+x /etc/init.d/zabbix*



修改启动脚本(自动启动zabbix服务端与java监控服务端端口)

vim /etc/init.d/zabbix_server

修改以下内容

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

ZABBIX_JAVA_GW_FILE="/tmp/zabbix_java.pid"

start() {

       echo -n $"Starting $prog: "

       /usr/local/zabbix/sbin/zabbix_java/startup.sh

       daemon $ZABBIX_BIN

       RETVAL=$?

       [ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_server

       echo

}

stop() {

       echo -n $"Stopping $prog: "

       killproc $ZABBIX_BIN

       RETVAL=$?

       [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix_server

       /usr/local/zabbix/sbin/zabbix_java/shutdown.sh > /dev/null

       if [ -n "$ZABBIX_JAVA_GW_FILE" -a -e "$ZABBIX_JAVA_GW_FILE" ]; then

               rm -f $ZABBIX_JAVA_GW_FILE

       fi

       echo

}



vim /etc/init.d/zabbix_agentd

修改以下内容

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



编写mail发信脚本(经测试,163邮箱可以发信,红字部分请自己修改相应内容)

vim /usr/local/zabbix/alertscripts/sendmail.sh


#!/bin/sh

SMTPSRV=smtp.163.com

PORT=25

MAIL_FROM=xxxxxxxx@163.com

RCPT_TO=$1

EHLO=xxxxxxxx@163.com

USER=`printf "xxxxxxxx" |openssl base64`

PASSWD=`printf "********" |openssl base64`

SUBJECT=$2

OUTPUT=$3

(for i in "ehlo $EHLO" "AUTH LOGIN" "$USER" "$PASSWD" "mail FROM:<$MAIL_FROM>" "rcpt TO:<$1>" "data";

  do

      sleep 2

      echo ${i}

      sleep 2

  done

echo "from:<$MAIL_FROM>"

echo "to:<$1>"

echo "subject:$2 $(date '+%T-%D')"

echo ""

echo "$3"

echo "."

sleep 2

echo "QUIT")|telnet $SMTPSRV $PORT >> /dev/null


修改发信脚本权限
chown zabbix.zabbix /usr/local/zabbix/alertscripts/sendmail.sh

chmod a+x /usr/local/zabbix/alertscripts/sendmail.sh



添加系统启动项

[root@localhost init.d]# chkconfig --level 345 zabbix_server on

[root@localhost init.d]# chkconfig --level 345 zabbix_agentd on

[root@localhost init.d]# chkconfig --level 345 httpd on

[root@localhost init.d]# chkconfig --level 345 mysqld on



启动zabbix

/etc/init.d/httpd start

/etc/init.d/mysqld restart

/etc/init.d/zabbix_server start

/etc/init.d/zabbix_agentd start



访问zabbix网页

http://192.168.1.100/zabbix/

zabbix会自动弹起初始化配置向导,一路点击下一步,填写相应的信息至finish。

重新登录

http://192.168.1.100/zabbix/

默认用户名:Admin

密码:zabbix


zabbix安装完成。


下期将进行对于mail发信与基于应用监控的一些说明。