Techy Findings

Just another Geek trying to be special

Posts tagged install

0 notes

Virtual ubuntu Reminder

As an aide de memoire, on the initial install screen press F4 and select Minimal Install.

After booting in and performing the normal apt-get update.

install the package that adds in the missing utilities such as nano.

apt-get install -y  ubuntu-standard

add sudo as a prefix if you are not the root user.

Filed under ubuntu install tips

5 notes

Zabbix install on Ubuntu 11.10

I have put a script together that allows me to install a specified version of Zabbix on a Ubuntu server, if you choose not to install the server the script assumes you want to install the Zabbix agent. It also provides an option to compile with IPv6 support.

Although there is some error checking, they can always be more added. If you decide to improve the script further please leave a comment with a link to the new improved version.

It is possibly that the CODE section of this blog provider mucks up some of the special formatting characters, if you have problems check what you see on this page to what has been copied into your script file.

As usual make sure you chmod +x the script file and I suggest you run this with root privelidges.

#!/bin/bash

#TODO
# error checking always needs improving


#Adapted from script found online
# CHANGES by Paul Miller:
#enhanced to offer IPv6 support
#Changed to support mysql
#added option for version support
#server or agent install
#added some error checking
####################################################


#Set Default script variables here before running

DATABASE=”mysql” # option ONLY mysql at present
IPv6=true # options true or false
VERSION=”1.8.8”
DB_USER=”zabbix”
DB_PASS=”zabb1x”
DB_HOST=”localhost”
SERVER_IP=”192.168.0.9” # IP of zabbix server for agents to communicate with.
SERVER_INSTALL=true # if false assumed to be agent only install

#====END of User Varables==================
IPv4_ADDR=`ifconfig  | grep ‘inet addr:’| grep -v ‘127.0.0.1’ | cut -d: -f2 | awk ‘{ print $1}’`
MYSQL=”$(which mysql)”
HOSTNAME=$(hostname -f)
clear

# Get Input from Users
echo “Capture User Options:”
echo “=====================”
echo “Please answer the following questions.”
echo “Hitting return will continue with the default option”
echo
echo
# Get_Server - Do they require a Server Install?
read -p “Install Zabbix Server? true/false [$SERVER_INSTALL]: ” -e t1
if [ -n “$t1” ]
then
  SERVER_INSTALL=”false”
  #Now we ASSUME that this is a Agent ONLY install
  # Get_Server_IP - What Version of Zabbix do they require?
  read -p “What is the Zabbix Server IP Address? [$SERVER_IP]: ” -e t1
  if [ -n “$t1” ]
  then
     SERVER_IP=”$t1”
  else
     SERVER_IP=”192.168.0.9”
  fi
  #====END Get_Server_IP
else
  SERVER_INSTALL=”true”
fi
#====END Get_Server

# Get_Version - What Version of Zabbix do they require?
read -p “Which version? [$VERSION]: ” -e t1
if [ -n “$t1” ]
then
  VERSION=”$t1”
else
  VERSION=”1.8.8”
fi
#====END Get_Version
 
# Get_IPv6 - Do they require IPv6 support?
read -p “Is support for IPv6 required? true/false [$IPv6]: ” -e t1
if [ -n “$t1” ]
then
  IPv6=”false”
else
  IPv6=”true”
fi
#====END Get_IPv6

# Step 1 ================================
# nothing to do for agent only installs
echo
echo “Installation Step 1 Started”

################
#updating system
################

apt-get -qq update
if [ $? -eq 0 ]; then
   echo “Step 1 completed successfully!”
else
   echo “Step 1 FAILED!”  
   exit
fi

# Step 2 ================================

if $SERVER_INSTALL ; then
   #####################
   #install requirements
   #####################
   echo
   echo “Installation Step 2 Started”

   if ! dpkg-query -W fping; then apt-get install -qq -y fping; fi
   if ! dpkg-query -W apache2; then apt-get install -qq -y apache2; fi
   if ! dpkg-query -W php5; then apt-get install -qq -y php5; fi
   if ! dpkg-query -W php5-gd; then apt-get install -qq -y php5-gd; fi
   if ! dpkg-query -W libsnmp-dev; then apt-get install -qq -y libsnmp-dev; fi
   if ! dpkg-query -W libcurl4-openssl-dev; then apt-get install -qq -y libcurl4-openssl-dev; fi
   if ! dpkg-query -W libapache2-mod-php5; then apt-get install -qq -y libapache2-mod-php5; fi
   if ! dpkg-query -W libiksemel-dev; then apt-get install -qq -y libiksemel-dev; fi
   if ! dpkg-query -W libssh2-1-dev; then apt-get install -qq -y libssh2-1-dev; fi
   if ! dpkg-query -W libopenipmi-dev; then apt-get install -qq -y libopenipmi-dev; fi
   if ! dpkg-query -W libmysqlclient-dev; then apt-get install -qq -y libmysqlclient-dev; fi
   if ! dpkg-query -W mysql-server; then apt-get install -qq -y mysql-server; fi
   if ! dpkg-query -W libapache2-mod-auth-mysql; then apt-get install -qq -y libapache2-mod-auth-mysql; fi
   if ! dpkg-query -W php5-mysql; then apt-get install -qq -y php5-mysql; fi

fi
if ! dpkg-query -W build-essential; then apt-get install -qq -y build-essential; fi

echo “Step 2 completed successfully!”

# Step 3 ================================

#######################
#Initial Database setup
#######################
echo
echo “Installation Step 3 Started”

# create zabbix system user
adduser zabbix —no-create-home —system —group —disabled-password —shell /bin/false —quiet
if [ $? -eq 0 ]; then
   echo “   User zabbix created”
else
   echo “   FAILED to create User zabbix”
   exit 1
fi

if $SERVER_INSTALL ; then

   if [ “$DATABASE” == “mysql” ]; then
      echo -n “   Input the MySQL admin user name: “
      read -e MySQLADMIN

      echo -n “   Input the MySQL admin user password: “
      read -e MySQLADMINPASS

      $MYSQL -u$MySQLADMIN -p$MySQLADMINPASS -Bse ‘CREATE DATABASE zabbix;’
      $MYSQL -u$MySQLADMIN -p$MySQLADMINPASS -Bse “GRANT ALL ON zabbix.* TO zabbix@localhost;”
      echo “   mysql database and user created”
    
   else
      echo “postgresql initial DB setup”
      #postgresql initial DB setup

      echo -n “Input the postgre user name for this database: “
      read -e DB_USER

      echo -n “Input the MySQL admin user password: “
      read -e MySQLADMINPASS

   fi

   echo “Step 3 completed successfully!”
fi



# Step 4 ================================
################
#Zabbix download
################
echo
echo “Installation Step 4 Started”

cd /tmp/

DIRECTORY=/tmp/install
if [ ! -d “$DIRECTORY” ]; then
    mkdir /tmp/install
fi

cd /tmp/install
echo ” temporary install directory created”
echo ” downloading zabbix source”

if ! [ -e “zabbix-$VERSION.tar.gz” ]
then
  wget -nv http://prdownloads.sourceforge.net/zabbix/zabbix-$VERSION.tar.gz
  echo “   downloaded zabbix source”
else
  echo “   zabbix source of correct version already exists”
fi

echo ” untar zabbix source”
tar zxf zabbix-$VERSION.tar.gz

echo ” prepare directory and file permissions”
chmod -R 777 /tmp/install/*
cd /tmp/install/zabbix-$VERSION
chmod +x ./configure

if $SERVER_INSTALL ; then
   # DB integration
   echo ” load mysql with provided schemas”
   cd /tmp/install/zabbix-$VERSION/create/schema
   cat mysql.sql | mysql -u$MySQLADMIN -p$MySQLADMINPASS zabbix
   cd ../data
   cat data.sql | mysql -u$MySQLADMIN -p$MySQLADMINPASS zabbix
   cat images_mysql.sql | mysql -u$MySQLADMIN -p$MySQLADMINPASS zabbix
fi

echo ” prepare compile build options”
if $SERVER_INSTALL ; then
   #Server DB and other build options
   build_opts=” —prefix=/usr —mandir=\${prefix}/share/man —infodir=\${prefix}/share/info “

   if $IPv6 ; then
      build_opts=” —enable-ipv6 $build_opts”
   fi

   # —with-mysql
   build_opts=” —with-mysql $build_opts”

   cd /tmp/install/zabbix-$VERSION
   echo “Using configure set like this: “
   echo “configure —quiet —enable-server —with-net-snmp —with-libcurl —with-openipmi —with-jabber —with-ssh2 —enable-agent $build_opts”

   echo “”
   ./configure —quiet —enable-server —with-net-snmp —with-libcurl —with-openipmi —with-jabber —with-ssh2 —enable-agent $build_opts
else
   #Agents only build options
   build_opts=” —prefix=/usr —mandir=\${prefix}/share/man —infodir=\${prefix}/share/info “

   if $IPv6 ; then
      build_opts=” —enable-ipv6 $build_opts”
   fi
   cd /tmp/install/zabbix-$VERSION
   echo “Using configure set like this: “
   echo “configure —quiet —enable-agent $build_opts”

   echo “”
   ./configure —quiet —enable-agent $build_opts

fi


echo “   Ready to compile”
cd /tmp/install/zabbix-$VERSION

make -s install
if [ $? -eq 0 ]; then
   echo “Step 4 completed successfully!”
else
   echo “Step 4 Compile FAILED!”
   exit
fi

sleep 5

#step 5 for Server installations
if $SERVER_INSTALL ; then
   #############################
   #Zabbix $VERSION installation
   #FRONTEND installation
   #############################
   echo “Step 5 FRONTEND installation”

   sed -i.backup -e “s/post_max_size = 8M/post_max_size = 32M/g” /etc/php5/apache2/php.ini
   sed -i.backup -e “s/max_execution_time = 30/max_execution_time = 600/g” /etc/php5/apache2/php.ini
   sed -i.backup -e “s/max_input_time = 60/max_input_time = 600/g” /etc/php5/apache2/php.ini
   sed -i,backup -e ‘/date.timezon/a\date.timezone = “Pacific/Auckland”’ /etc/php5/apache2/php.ini
   cd /tmp/install/zabbix-$VERSION/frontends/php
   sleep 5
   echo “   Make web directory”
   DIRECTORY=/var/www/zabbix
   if [ ! -d “$DIRECTORY” ]; then
      mkdir /var/www/zabbix
   fi
   echo “   Copy zabbix web frontend to web directory”
   cp -a . /var/www/zabbix
   echo “   Change the permissions to default apache2”
   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 “   Zabbix $VERSION installation”
fi

#step 5 for agents only they join here…

ln -s /usr/bin/fping /usr/sbin/fping
if $IPv6 ; then
   ln -s /usr/bin/fping6 /usr/sbin/fping6
fi

DIRECTORY=/etc/zabbix
if [ ! -d “$DIRECTORY” ]; then
   mkdir $DIRECTORY
fi

DIRECTORY=/var/log/zabbix
if [ ! -d “$DIRECTORY” ]; then
   mkdir $DIRECTORY
   chown zabbix:zabbix -R $DIRECTORY
   chmod 766 $DIRECTORY
fi

DIRECTORY=/var/run/zabbix
if [ ! -d “$DIRECTORY” ]; then
    mkdir $DIRECTORY
    chown zabbix:zabbix -R $DIRECTORY
    chmod 766 $DIRECTORY
fi

cp /tmp/install/zabbix-$VERSION/misc/conf/zabbix_agentd.conf /etc/zabbix

#check for server install
if $SERVER_INSTALL ; then
   cp /tmp/install/zabbix-$VERSION/misc/conf/zabbix_server.conf /etc/zabbix
   sed -i.backup -e “s/DBUser=root/DBUser=$DB_USER/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” /etc/zabbix/zabbix_server.conf
fi
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 zabbix:zabbix -R /etc/zabbix

cp /tmp/install/zabbix-$VERSION/misc/init.d/debian/zabbix* /etc/init.d/

#check for server install
if $SERVER_INSTALL ; then
   sed -i.backup -e “s|/usr/local/sbin/|/usr/sbin/|” /etc/init.d/zabbix-server
   chmod 775 /etc/init.d/zabbix-server
   update-rc.d zabbix-server defaults
   echo “   Starting the zabbix server”
   /etc/init.d/zabbix-server start
   echo “   Restarting Apache for changes to take effect”
   /etc/init.d/apache2 restart
   sleep 5
   if [ “$(pidof zabbix_server)” ]
   then
      echo “Server Installation Complete!”
      echo “zabbix can be found at: “
      echo “http://$IPv4_ADDR/zabbix”
      echo “  Login:  admin”
      echo “  Passwd: zabbix”
   else
      echo “Installation FAILED!”
      echo “zabbix server process is NOT running.”
      echo “Not sure what went wrong.”
   fi
else
   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” -e “s|Server=127.0.0.1|Server=$SERVER_IP|g” -e “s|Hostname=Zabbix server|Hostname=$HOSTNAME|g” /etc/zabbix/zabbix_agentd.conf

fi

sed -i.backup -e “s|/usr/local/sbin/|/usr/sbin/|” /etc/init.d/zabbix-agent
chmod 775 /etc/init.d/zabbix-agent
update-rc.d zabbix-agent defaults
echo “   Starting the zabbix agent”
/etc/init.d/zabbix-agent start
sleep 5

if [ “$(pidof zabbix_agentd)” ]
   then
      #cleaning up
      rm -rf /tmp/install
      echo “Agent Installation Complete!”
   else
      echo “Agent Installation FAILED!”
      echo “zabbix agent process is NOT running.”
      echo “Not sure what went wrong.”
   fi

exit

Revision History

  • First release 30/12/2011

Filed under Bash Script ubuntu zabbix zabbix-agent zabbix_agent install howto 11.10

7 notes

Webmin installation script for Ubuntu 11.10

Ok, so its not rocket science to install webmin on Ubuntu, however as I spend a reasonable amount of time building up servers to try new applications or test particular versions of applications that I already use, I find I spend a fair amount of time repeating the same boring tasks; one of them being installing Webmin.

To use this script sudo in root using

sudo su

Make sure the script has the execute permision flag set you can simply ‘cd’ to the directory where you copied the script and type:

chmod +x webmin_install.sh

run the script by typing

./webmin_install.sh

This script will install the latest version of webmin on your machine.

Hmm… I cannot see how to attach the script file to this post, so instead I have copied the contents below, the details above assume you copy the script below into a file called webmin_install.sh

#!/bin/bash
#
# webmin install


# update system

echo ‘###############’
echo ‘update system’
echo ‘###############’
apt-get update

# install requirements
echo ‘###############’
echo ‘install requirements’
echo ‘###############’

apt-get install -y perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python

#update repo
echo ‘###############’
echo ‘   Repo setup  ‘
echo ‘###############’

echo “deb http://download.webmin.com/download/repository sarge contrib” » /etc/apt/sources.list
echo “deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib” » /etc/apt/sources.list

#Install GPG key
echo ‘###############’
echo ‘  Install GPG  ‘
echo ‘###############’
cd /root
wget http://www.webmin.com/jcameron-key.asc
apt-key add jcameron-key.asc

#Download and Install webmin
echo ‘###############’
echo ‘Install Webmin ‘
echo ‘###############’
apt-get update
apt-get install -y webmin


Filed under ubuntu webmin install script bash