Changes to Argoweb
Installation of MySQL Database and Apache Tomcat was accomplished using a custom bash shell script to download, unzip, compile the applications from source. The following changes were made to argoweb:- added groups 'argoweb', 'mysql', and 'tomcat'
- added users 'argoweb', 'mysql', and 'tomcat'
- removed:
- apache2 (replaced by Tomcat)
- installed:
- vim
- openjdk 6
- g++ 4.4
- MySQL 5.1
Apache Tomcat 6Apache Tomcat 7- Note: Tomcat 6 does not support the latest version of Java. Tomcat 7, however, is not natively supported by Debian so it must be installed from source.
- used iptables to route incoming traffic on port 80 to the Tomcat server:
root@argoweb:/etc/tomcat6# iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
root@argoweb:/etc/tomcat6# iptables-save
# Generated by iptables-save v1.4.8 on Thu May 3 05:31:30 2012
*nat
:PREROUTING ACCEPT [53:7910]
:POSTROUTING ACCEPT [2:191]
:OUTPUT ACCEPT [2:191]
-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
COMMIT
# Completed on Thu May 3 05:31:30 2012
- performed dump of previous database :
- used sql file to populate Argoweb database
- deployed the Argo Database application on the Tomcat server
- created a script to mirror some directories from Ursa to ArgoWeb (/usr/local/bin/ursa-volume-sync):
- ursa:/Volumes/U1/argo -> argoweb:/data/Volumes/U1/argo
- ursa:/Volumes/U2 -> argoweb:/data/Volumes/U2
- cron'd to run twice daily. After the initial transfer, this script has completed in under 10 minutes, without any major changes to files on Ursa. After an update to the GDAC, it may take significantly longer.
- #!/bin/bash
- ##########################################
- # MYSQL AND APACHE TOMCAT INSTALL SCRIPT #
- ##########################################
- #
- # AUTHOR
- # Alex Ekholm, aekholm@whoi.edu, Woods Hole Oceanographic Institution
- #
- # CREATED
- # Fri Apr 27, 2012
- #
- # NOTES
- # - This script can be used to automate installation of the following applications from source:
- # 1) MySQL 5.1.62
- # 2) Apache Tomcat 7.0.27
- # - Will attempt to download source code automatically if not present.
- #
- # REQUIREMENTS
- # - Must be run as root user
- # - wget, getopts, gcc, g++, make, ant
- #
- #
- ##########################################
- # CONFIGURATION #
- ##########################################
- #
- # Relevent files, directories, and other misc. install options are specified here.
- #
- # MySQL configuration
- mysql_home="/home/mysql"
- mysql_prefix="/usr/share/mysql"
- mysql_dir="$mysql_prefix/mysql-5.1.62"
- mysql_tar="$mysql_dir.tar.gz"
- mysql_config_opts="--prefix=$mysql_prefix"
- # Apache Tomcat configuration
- tomcat_home="/home/tomcat"
- tomcat_dir="./tomcat/apache-tomcat-7.0.27-src"
- tomcat_tar="$tomcat_dir.tar.gz"
- tomcat_prefix="/usr/share/tomcat7"
- tomcat_config_opts="base.path=$tomcat_prefix"
- # tar options
- TAROPTS="-xzf"
- # debug - set DEBUG=1 to display debug info
- _DEBUG=0
- # verbose operation
- VERBOSE=$_DEBUG
- # working dir - default is current dir
- src_dir="/usr/local/src"
- # mirrors
- mysql_mirrors=(
- "http://mysql.he.net/Downloads/MySQL-5.1/mysql-5.1.62.tar.gz"
- "http://mysql.mirrors.hoobly.com/Downloads/MySQL-5.1/mysql-5.1.62.tar.gz"
- "http://mirror.services.wisc.edu/mysql/Downloads/MySQL-5.1/mysql-5.1.62.tar.gz")
- tomcat_mirrors=(
- "http://www.fightrice.com/mirrors/apache/tomcat/tomcat-7/v7.0.27/src/apache-tomcat-7.0.27-src.tar.gz"
- "http://mirrors.ibiblio.org/apache/tomcat/tomcat-7/v7.0.27/src/apache-tomcat-7.0.27-src.tar.gz"
- "http://mirror.candidhosting.com/pub/apache/tomcat/tomcat-7/v7.0.27/src/apache-tomcat-7.0.27-src.tar.gz")
- ##########################################
- # INSTALL MYSQL DATABASE #
- ##########################################
- function install_mysql {
- # check directory
- if [ ! -d "mysql" ]; then
- mkdir mysql
- fi
- # download source if necessary
- ask "Download MySQL source?" Y && if [ ! -f "$mysql_tar" ]; then
- # try each mirror until success
- for mirror in "${mysql_mirrors[@]}"; do
- # download source
- WGETOPTS="-P mysql $mirror"
- dbg "executing wget: 'wget $WGETOPTS'"
- wget $VOPT $WGETOPTS
- if [ -f "$mysql_tar" ]; then break; fi
- done
- # check
- if [ ! -f "$mysql_tar" ]; then
- echo "Failed to download MySQL source: $mysql_tar"
- exit 1
- fi
- fi
- # create group
- ask "Create group 'mysql'?" Y && groupadd mysql
- # create user
- ask "Create user 'mysql'?" Y && useradd -b $mysql_home \
- -d $mysql_home \
- -g mysql \
- mysql
- # unzip
- ask "Unzip MySQL database?" Y && tar $TAROPTS $mysql_tar -C mysql
- # change to mysql dir
- chdir $mysql_dir
- # configure
- verbose "MySQL Configuration options: '$mysql_config_opts'"
- ask "Configure MySQL?" Y && ./configure $mysql_config_opts
- # compile
- ask "Make clean?" Y && make clean
- ask "Compile MySQL?" Y && make
- ask "Compile MySQL installation modules?" Y && make install
- # postinstallation setup
- chdir $mysql_prefix
- chown -R mysql .
- chgrp -R mysql .
- ask "Install MySQL?" Y && ./bin/mysql_install_db --user=mysql --basedir=$mysql_prefix
- chown -R root .
- chown -R mysql var
- # optional
- ask "Copy support files?" N && cp support-files/my-medium.cnf /etc/my.cnf
- # start mysql daemon
- if ask "Start MySQL daemon?" Y ; then
- ./bin/mysqld_safe --user=mysql --basedir=$mysql_prefix &
- fi
- # return to root dir
- chdir $src_dir
- } # install_mysql
- ##########################################
- # INSTALL APACHE TOMCAT #
- ##########################################
- function install_tomcat {
- # check directory
- if [ ! -d "tomcat" ]; then
- mkdir tomcat
- fi
- # download source if necessary
- ask "Download Apache Tomcat source?" Y && if [ ! -f "$tomcat_tar" ]; then
- # try each mirror until success
- for mirror in "${tomcat_mirrors[@]}"; do
- # download source
- WGETOPTS="$VOPT -P tomcat $mirror"
- dbg "wget $WGETOPTS"
- wget $WGETOPTS
- if [ -f "$tomcat_tar" ]; then break; fi
- done
- # check
- if [ ! -f "$tomcat_tar" ]; then
- echo "Failed to download Apache Tomcat source: $tomcat_tar"
- exit 1
- fi
- fi
- # create group
- ask "Create group 'tomcat'?" Y && groupadd tomcat
- # create user
- ask "Create user 'tomcat'?" Y && useradd -b $tomcat_home \
- -d $tomcat_home \
- -g tomcat \
- tomcat
- # unzip
- ask "Unzip Apache Tomcat Server?" Y && tar $TAROPTS $tomcat_tar -C tomcat
- # change to tomcat dir
- chdir $tomcat_dir
- # configure tomcat
- # cd echo "$tomcat_config_opts" > build.properties
- # compile tomcat
- ask "Compile Apache Tomcat Server from source?" Y && ant
- # create directories
- if ask "Create directory structure?" Y ; then
- # /var/lib
- if [ ! -d /var/lib/tomcat7 ] ; then
- mkdir -p /var/lib/tomcat7/common/classes \
- /var/lib/tomcat7/server/classes \
- /var/lib/tomcat7/shared/classes
- fi
- # /var/log
- if [ ! -d /var/log/tomcat7 ] ; then
- mkdir /var/log/tomcat7
- fi
- # /var/cache
- if [ ! -d /var/cache/tomcat7 ] ; then
- mkdir /var/cache/tomcat7
- fi
- # /etc - conf
- if [ ! -d /etc/tomcat7 ] ; then
- mkdir /etc/tomcat7
- fi
- fi
- # copy compiled files
- if ask "Copy compiled files to install directory?" Y ; then
- # /usr/share/
- cp -r output/build/bin $tomcat_prefix/
- cp -r output/build/lib $tomcat_prefix/
- # /etc
- cp -r output/build/conf/* /etc/tomcat7
- # /var/lib
- cp -r output/build/webapps /var/lib/tomcat7/webapps
- ln -s /etc/tomcat7 /var/lib/tomcat7/conf
- ln -s /var/log/tomcat7 /var/lib/tomcat7/logs
- ln -s /var/cache/tomcat7 /var/lib/tomcat7/work
- # permissions
- chown tomcat /var/log/tomcat7 -R
- chgrp tomcat /var/log/tomcat7 -R
- chown tomcat /var/lib/tomcat7 -R
- chgrp tomcat /var/lib/tomcat7 -R
- chown tomcat /var/cache/tomcat7 -R
- chgrp tomcat /var/cache/tomcat7 -R
- chown tomcat /etc/tomcat7 -R
- chgrp tomcat /etc/tomcat7 -R
- chown tomcat /usr/share/tomcat7 -R
- chgrp tomcat /usr/share/tomcat7 -R
- fi
- # return
- chdir $src_dir
- } # install_tomcat
- ##########################################
- # PROMPT FUNCTION #
- ##########################################
- #
- # USAGE
- # (long version)
- # if [ ask "<prompt>" <optional-default> ]; then
- # # Control will enter here if yes
- # fi
- #
- # (short version)
- # ask "<prompt>" && <command-to-exec-if-yes>
- # ask "<prompt>" <default> && <command-to-exec-if-yes>
- # ask "<prompt>" <default> || <command-to-exec-if-no>
- #
- # EXAMPLE
- # ask "Install MySQL database?" Y && install_mysql
- #
- # RETURN VALUE
- # 0 if user responds YES
- # 1 if user responds NO
- #
- function ask {
- while true; do
- # Assign prompt and default
- if [ "${2:-}" = "Y" ]; then
- prompt="Y/n"
- default=Y
- elif [ "${2:-}" = "N" ]; then
- prompt="y/N"
- default=N
- else
- prompt="y/n"
- default=
- fi
- # Ask the question
- read -p "$1 [$prompt] " REPLY
- # Default
- if [ -z "$REPLY" ]; then
- REPLY=$default
- fi
- # Return only if the reply is valid
- case "$REPLY" in
- Y*|y*) return 0 ;;
- N*|n*) return 1 ;;
- esac
- done
- } # ask
- ##########################################
- # CHANGE DIRECTORY #
- ##########################################
- function chdir {
- verbose "Changing to directory: $@"
- cd $@
- } # err
- ##########################################
- # DEBUG FUNCTION #
- ##########################################
- #
- # Like 'echo', but prints only if debug operation is specified.
- function dbg {
- [ "$_DEBUG" == 1 ] && echo "[DEBUG] $@"
- } # dbg
- ##########################################
- # ERROR FUNCTION #
- ##########################################
- #
- # Like 'echo', but prints to error stream
- function err {
- echo "[ERROR] $@" 1>&2
- } # err
- ##########################################
- # VERBOSE FUNCTION #
- ##########################################
- #
- # Like 'echo', but prints only if verbose operation is specified.
- function verbose {
- [ "$VERBOSE" == 1 ] && echo "$@"
- } # verbose
- ##########################################
- # INSTALL ARGOWEB APPS #
- ##########################################
- dbg "Running in debug mode..."
- # Make sure user is root
- if [ "$(id -u)" != "0" ]; then
- err "This script must be run as root"
- exit 1
- fi
- # Get command line arguments
- while getopts ":cd:v" opt; do
- dbg "processing command-line argument: -$opt"
- case $opt in
- c)
- # clean working directory.
- rm -rf mysql tomcat
- ;;
- d)
- # Specify working directory. This is the directory to which all files will be downloaded and unzipped.
- src_dir=$OPTARG
- chdir $src_dir
- ;;
- v)
- # Verbose operation
- VERBOSE=1
- VOPT="-v"
- TAROPTS="-xzvf"
- verbose "Operating in verbose mode."
- ;;
- \?)
- err "Invalid option: -$opt"
- exit 1
- ;;
- :)
- err "Option -$OPTARG requires an argument."
- exit 1
- ;;
- esac
- done
- dbg "VERBOSE=$VERBOSE"
- dbg "src_dir=$src_dir"
- verbose "Working directory: $src_dir"
- chdir $src_dir
- # Prompt and install MySQL database
- ask "Install MySQL database?" Y && install_mysql
- # Prompt and install Apache Tomcat Server
- ask "Install Apache Tomcat Server?" Y && install_tomcat
No comments:
Post a Comment