Search code examples
zabbix

Update Zabbix with a script


I need to make a script that will update Zabbix on Ubuntu. It needs to update everything like the log files and so on. But I don't know how to make a script that will execute this. I've been trying to look up information on this subject but can't find anything.


Solution

  • Following is an old script that is used to install Zabbix-server automatically, but only for the first time, I think you must only edit thing which is required in the application

    #!/bin/sh
    #
    # zabbix 2.0.2 install with postgresql and jabber support
    #
    # 
    # software distributed under the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND
    #
    # written by:
    # Stefan Krueger 
    # tested on Debian Squeeze/Wheezy & Ubuntu 10.04 LTS/12.04 LTS (use sudo su -)
    #
    (
    dbpw=$(dd if=/dev/urandom bs=1 count=6 2>/dev/null | openssl base64)
    zbxver=zabbix-2.0.2
    ipadd=$(env LC_ALL=C /sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp')
    
    date
    
    # update system
    echo '###############'
    echo 'update system'
    echo '###############'
    apt-get update 
    
    # install requirements
    echo '###############'
    echo 'install requirements'
    echo '###############'
    sleep 1
    
    apt-get install -y postgresql build-essential fping apache2 php5 php5-pgsql php5-gd libsnmp-dev libcurl4-openssl-dev libapache2-mod-php5 libiksemel-dev libpq-dev libssh2-1-dev libopenipmi-dev
    
    #DB setup
    echo '###############'
    echo 'database setup '
    echo '###############' 
    sleep 1    
    
    adduser zabbix --no-create-home --system --group --disabled-password --shell /bin/false --quiet && echo 'User zabbix created' || echo 'User zabbix could not be created'
    
    su postgres -c "echo \"create user zabbix with password '${dbpw}' createdb;\" | psql" && echo "database user zabbix created" || echo "database user zabbix could not be created"
    su postgres -c "echo \"create database zabbix with owner=zabbix;\" | psql" && echo "database zabbix created" || echo "database zabbix could not be created"
    sleep 2
    #  zabbix installation
    
    echo '############################################################################'
    echo ''
    echo $zbxver installation
    echo ''
    echo '############################################################################'
    cd /tmp/
    mkdir -p /tmp/install
    cd /tmp/install
    wget http://prdownloads.sourceforge.net/zabbix/${zbxver}.tar.gz
    tar -zxvf ${zbxver}.tar.gz
    
    chmod -R 777 /tmp/install/* 
    su zabbix -s /bin/bash -c "psql -d zabbix -f /tmp/install/${zbxver}/postgresql/schema.sql" && echo "create schema success" || echo "create schema failed" 
    su zabbix -s /bin/bash -c "psql -d zabbix -f /tmp/install/${zbxver}/postgresql/images.sql" && echo "create schema success" || echo "create schema failed" 
    su zabbix -s /bin/bash -c "psql -d zabbix -f /tmp/install/${zbxver}/postgresql/data.sql" && echo "create schema success" || echo "create schema failed" 
    cd /tmp/install/${zbxver}
    chmod +x /tmp/install/${zbxver}/configure
    chmod +x ./configure
    /tmp/install/${zbxver}/configure  --enable-server --with-postgresql --with-net-snmp --with-libcurl --with-openipmi --with-jabber --with-ssh2 --enable-agent --prefix=/usr --mandir=\${prefix}/share/man --infodir=\${prefix}/share/info --sysconfdir=/etc/zabbix || exit
    make install
    #install frontend
    
    echo '############################################################################'
    echo ''
    echo '$zbxver installation'
    echo ' FRONTEND installation'
    echo ''
    echo '############################################################################'
    sleep 1
    
    sed -i.backup -e "s/post_max_size = 8M/post_max_size = 32M/g" -e "s/max_execution_time = 30/max_execution_time = 600/g" -e "s/max_input_time = 60/max_input_time = 600/g" -e '/date.timezon/a\date.timezone = "Europe/Berlin"' /etc/php5/apache2/php.ini
    
    cd /tmp/install/${zbxver}/frontends/php
    
    mkdir -p /var/www/zabbix
    cp -a . /var/www/zabbix
    chown www-data:www-data -R /var/www/zabbix
    cat <<EOF > /etc/apache2/sites-available/zabbix
    <VirtualHost /zabbix>
            ServerAdmin webmaster@localhost
    
            DocumentRoot /var/www/zabbix
            <Directory />
                    Options FollowSymLinks Indexes MultiViews
                    AllowOverride None
            </Directory>
    </VirtualHost>
    EOF
    
    echo '############################################################################'
    echo ''
    echo '$zbxver installation'
    echo ' services  installation agent & server'
    echo ''
    echo '############################################################################'
    sleep 1
    mkdir -p /var/log/zabbix && chown zabbix /var/log/zabbix && chmod 760 /var/log/zabbix
    mkdir -p /var/run/zabbix && chown zabbix /var/run/zabbix && chmod 760 /var/run/zabbix
    
    #cp /tmp/install/${zbxver}/misc/conf/zabbix_server.conf /etc/zabbix
    #cp /tmp/install/${zbxver}/misc/conf/zabbix_agentd.conf /etc/zabbix
    
    sed -i.backup -e "s|DBUser=root|DBUser=zabbix|g" -e "s|# DBPassword=|DBPassword=${dbpw}|g" -e "s|/tmp/zabbix_server.log|/var/log/zabbix/zabbix_server.log|g" -e "s|# PidFile=/tmp/zabbix_server.pid|PidFile=/var/run/zabbix/zabbix_server.pid|g" -e "s|# HousekeepingFrequency=1|HousekeepingFrequency=24|" /etc/zabbix/zabbix_server.conf
    
    sed -i.backup -e "s|/tmp/zabbix_agentd.log|/var/log/zabbix/zabbix_agentd.log|g" -e "s|# PidFile=/tmp/zabbix_agentd.pid|PidFile=/var/run/zabbix/zabbix_agentd.pid|g" /etc/zabbix/zabbix_agentd.conf
    
    chown -R zabbix:zabbix /etc/zabbix
    cp /tmp/install/${zbxver}/misc/init.d/debian/zabbix* /etc/init.d/
    sed -i.backup -e "s|/usr/local/sbin/|/usr/sbin/|" -e "s|PID=/tmp/|PID=/var/run/zabbix/|" /etc/init.d/zabbix-server
    sed -i.backup -e "s|/usr/local/sbin/|/usr/sbin/|" -e "s|PID=/tmp/|PID=/var/run/zabbix/|" /etc/init.d/zabbix-agent
    
    chmod 775 /etc/init.d/zabbix-server
    chmod 775 /etc/init.d/zabbix-agent
    update-rc.d zabbix-server defaults 90
    update-rc.d zabbix-agent defaults  99
    /etc/init.d/zabbix-agent start
    /etc/init.d/zabbix-server start
    
    /etc/init.d/apache2 restart
    
    echo ""
    echo ""
    echo ""
    if [ -e /var/run/zabbix/zabbix_server.pid ]; then echo "  zabbix-server started succesfully"
    else echo " !!  zabbix-server dont start"
    fi
    
    if [ -e /var/run/zabbix/zabbix_agentd.pid ]; then echo "  zabbix-agentd started succsfully"
      else echo " !!  zabbix-agentd dont start"
    fi
    
    echo " look at the zabbix_install.log"
    echo ""
    echo "  please configure you postgresql.conf"
    echo "  the database password for zabbix is: ${dbpw}"
    echo ""
    echo "    now you can configure the zabbix-frontend http://${ipadd}/zabbix"
    ) | tee zabbix_install.log