Script to Install Zabbix Server on Centos6

Olá, meu nome é Diego Luisi e no artigo de hoje demonstrarei como instalar o Zabbix Server em Servidor Linux usando o CentOS 6 de forma automatizada, usando um script que fara todo o trabalho duro para você.

1) Primeiramente vamos atualizar nosso servidor

# yum update -y

2) Agora vamos instalar o Mysql

# yum install mysql-server -y

3) Desabilitar o SELINUX

# vi /etc/sysconfig/selinux
Mude de: SELINUX=enforcing
Para: SELINUX=disabled
:wq
# shutdown -r now

4) Preparando o Script de Instalação

# mkdir -p /tmp/downloads/zabbix/
# cd /tmp/downloads/zabbix/
# touch zabbix_install.sh
# chmod +x zabbix_install.sh

5) Criando o Script de Instalação

# vi zabbix_install.sh
Cole o Conteudo abaixo

#######################################################################

#!/bin/bash

# ZABBIX INSTALL SCRIPT
# VER. 0.7.0 - http://blog.brendon.com
# Copyright (c) 2008-2012 Brendon Baumgartner
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#=====================================================================

# If necessary, edit these for your system
DBUSER='root'
DBPASS=''
DBHOST='localhost'

ZBX_VER='2.0.2'

# DO NOT EDIT BELOW THIS LINE

function checkReturn {
  if [ $1 -ne 0 ]; then
     echo "fail: $2"
     echo "$3"
     exit
  else
     echo "pass: $2"
  fi
  sleep 3
}

cat < /dev/null << eof
status
eof
RETVAL=$?
checkReturn $RETVAL "basic mysql access" "Install mysql server packages or fix mysql permissions"

if [ ! "rpm -qa|grep fping" ]; then
  if [ "uname -m" == "x86_64" ]; then
     rpm -Uhv http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
  elif [ "uname -m" == "i686" ]; then
     rpm -Uhv http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
  fi
fi

# removed  libidn-devel iksemel-devel 
# dependenices for curl: e2fsprogs-devel zlib-devel libgssapi-devel krb5-devel openssl-devel
yum -y install gcc mysql-devel curl-devel httpd php php-mysql php-bcmath php-gd php-xml php-mbstring net-snmp-devel fping e2fsprogs-devel zlib-devel libgssapi-devel krb5-devel openssl-devel wget libssh2-devel openldap-devel make patch
RETVAL=$?
checkReturn $RETVAL "Package install"

chmod 4755 /usr/sbin/fping

cd /tmp

# jabber packages are incomplete at rpmforge (iksemel)
# BEGIN pkgs for jabber (--with-jabber)
#wget http://dl.atrpms.net/el6-x86_64/atrpms/stable/libiksemel3-1.4-2_2.el6.x86_64.rpm
#rpm -i /tmp/libiksemel3-1.4-2_2.el6.x86_64.rpm
#wget http://dl.atrpms.net/el6-x86_64/atrpms/stable/iksemel-1.4-2_2.el6.x86_64.rpm
#rpm -i /tmp/iksemel-1.4-2_2.el6.x86_64.rpm
#wget http://dl.atrpms.net/el6-x86_64/atrpms/stable/iksemel-devel-1.4-2_2.el6.x86_64.rpm
#rpm -i /tmp/iksemel-devel-1.4-2_2.el6.x86_64.rpm
# END pkgs for jabber

rm -rf /etc/zabbix
rm -rf zabbix-$ZBX_VER
rm zabbix-$ZBX_VER.tar.gz
#wget http://sourceforge.net/projects/zabbix/files/latest/download?source=files
#wget http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/$ZBX_VER/zabbix-$ZBX_VER.tar.gz
wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/$ZBX_VER/zabbix-$ZBX_VER.tar.gz
RETVAL=$?
checkReturn $RETVAL "downloading source" "check ZBX_VER variable or mirror might be down"
tar xzf zabbix-$ZBX_VER.tar.gz
cd zabbix-$ZBX_VER

./configure --enable-agent  --enable-ipv6  --enable-proxy  --enable-server --with-mysql --with-libcurl --with-net-snmp --with-ssh2 --with-ldap --sysconfdir=/etc/zabbix
RETVAL=$?
checkReturn $RETVAL "Configure"
# --with-jabber
# ipmi
# ldap

make
RETVAL=$?
checkReturn $RETVAL "Compile"

make install
RETVAL=$?
checkReturn $RETVAL "make install"

echo "DROP DATABASE IF EXISTS zabbix;" | mysql -h${DBHOST} -u${DBUSER} --password=${DBPASS}

(
echo "CREATE DATABASE zabbix;"
echo "USE zabbix;"
cat /tmp/zabbix-$ZBX_VER/database/mysql/schema.sql
cat /tmp/zabbix-$ZBX_VER/database/mysql/images.sql
cat /tmp/zabbix-$ZBX_VER/database/mysql/data.sql
) | mysql -h${DBHOST} -u${DBUSER} --password=${DBPASS}

#### BEGIN ZABBIX SERVER & AGENT PROCESS INSTALL & START
adduser -r -d /var/run/zabbix-server -s /sbin/nologin zabbix
#mkdir -p /etc/zabbix/alert.d
mkdir -p /var/log/zabbix-server
mkdir -p /var/log/zabbix-agent
mkdir -p /var/run/zabbix-server
mkdir -p /var/run/zabbix-agent
chown zabbix.zabbix /var/run/zabbix*
chown zabbix.zabbix /var/log/zabbix*
#cp /tmp/zabbix-$ZBX_VER/misc/conf/zabbix_server.conf /etc/zabbix
#cp /tmp/zabbix-$ZBX_VER/misc/conf/zabbix_agentd.conf /etc/zabbix

cp /tmp/zabbix-$ZBX_VER/misc/init.d/fedora/core5/zabbix_server /etc/init.d
cp /tmp/zabbix-$ZBX_VER/misc/init.d/fedora/core5/zabbix_agentd /etc/init.d

cd /etc/zabbix
patch -p0 -l < /tmp/mytmp393; mv /tmp/mytmp393 /etc/zabbix/zabbix_server.conf sed "s/_dbpass_/${DBPASS}/g" /etc/zabbix/zabbix_server.conf > /tmp/mytmp393; mv /tmp/mytmp393 /etc/zabbix/zabbix_server.conf

patch -p0 -l < /etc/httpd/conf.d/zabbix.conf echo "post_max_size = 16M" > /etc/php.d/local_zabbix.ini
echo "max_execution_time = 300" >> /etc/php.d/local_zabbix.ini
echo "max_input_time = 300" >> /etc/php.d/local_zabbix.ini
. /etc/sysconfig/clock
echo "date.timezone = $ZONE" >>  /etc/php.d/local_zabbix.ini

chkconfig httpd on
service httpd restart

#sed "s/max_execution_time = 30/max_execution_time = 300/g" /etc/php.ini > /tmp/mytmp393; mv /tmp/mytmp393 /etc/php.ini

#touch /usr/local/share/zabbix/conf/zabbix.conf.php
#chmod 666 /usr/local/share/zabbix/conf/zabbix.conf.php

cat > /usr/local/share/zabbix/conf/zabbix.conf.php << "eof" eof sed "s/_dbhost_/${DBHOST}/g" /usr/local/share/zabbix/conf/zabbix.conf.php > /tmp/mytmp393; mv /tmp/mytmp393 /usr/local/share/zabbix/conf/zabbix.conf.php
sed "s/_dbuser_/${DBUSER}/g" /usr/local/share/zabbix/conf/zabbix.conf.php > /tmp/mytmp393; mv /tmp/mytmp393 /usr/local/share/zabbix/conf/zabbix.conf.php
sed "s/_dbpass_/${DBPASS}/g" /usr/local/share/zabbix/conf/zabbix.conf.php > /tmp/mytmp393; mv /tmp/mytmp393 /usr/local/share/zabbix/conf/zabbix.conf.php

cd 
echo "Load http://localhost/zabbix/"
echo "username: admin"
echo "password: zabbix"

#######################################################################
Salve e saia.
:wq

6) Execute o Script de Instalação do Zabbix Server

# ./zabbix_install.sh
go

Seu Zabbix Server esta pronto, agora é só acessar seu server

http://localhost/zabbix/
username: admin
password: zabbix

Espero que tenham gostado e qualquer duvida ou sugestão será muito bem vinda.

You may also like...

6 Responses

  1. Ahaa, its pleasant conversation about this article at this place
    at this blog, I have read all that, so now me also commenting here.

  2. This design is steller! You obviously know how to keep a reader entertained.
    Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Fantastic job.
    I really enjoyed what you had to say, and more than that, how you presented it.
    Too cool!

  3. Hellen says:

    Hi there i am kavin, its my first occasion to commenting anywhere, when i read
    this article i thought i could also make comment due to this brilliant piece of writing.

  4. Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something.
    I think that you can do with a few pics to drive
    the message home a little bit, but other than that,
    this is great blog. A fantastic read. I will definitely be back.

  5. Good way of explaining, and pleasant article to take facts about my presentation topic, which i am going to deliver in academy.

  6. WOW just what I was searching for. Came here by searching for bat

Leave a Reply

Your email address will not be published. Required fields are marked *