用脚本更新Zabbix

时间:2016-02-02 10:28:11

标签: zabbix

我需要制作一个可以在Ubuntu上更新Zabbix的脚本。它需要更新所有内容,如日志文件等。但我不知道如何制作一个可以执行此操作的脚本。我一直试图查找有关此主题的信息,但无法找到任何内容。

1 个答案:

答案 0 :(得分:0)

以下是一个旧脚本,用于自动安装Zabbix-server,但仅限第一次,我认为您必须只编辑应用程序中所需的东西

#!/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