Difference between revisions of "Knowledge:Cloud"

From OpenKM Documentation
Jump to: navigation, search
(Install)
(Install)
Line 128: Line 128:
 
$DEBUG cp $SKELETON/okm.conf /etc/apache2/sites-available/$INSTANCE.conf
 
$DEBUG cp $SKELETON/okm.conf /etc/apache2/sites-available/$INSTANCE.conf
 
$DEBUG sed -i 's/okmXX/'$INSTANCE'/g' /etc/apache2/sites-available/$INSTANCE.conf
 
$DEBUG sed -i 's/okmXX/'$INSTANCE'/g' /etc/apache2/sites-available/$INSTANCE.conf
 +
$DEBUG sed -i 's/ajpPort/'$AJP_PORT'/g' /etc/apache2/sites-available/$INSTANCE.conf
 
$DEBUG a2ensite $INSTANCE.conf
 
$DEBUG a2ensite $INSTANCE.conf
  

Revision as of 19:39, 29 January 2013

User

 $ adduser --disabled-password okmXX

MySQL

Now create database and user:

 $ mysql -h localhost -u root -p
 mysql> CREATE USER okmXX@localhost IDENTIFIED BY '*secret*';
 mysql> CREATE DATABASE okmXX_app DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;
 mysql> GRANT ALL ON okmXX_app.* TO okmXX@localhost WITH GRANT OPTION;

Tomcat

 $ cp -r /home/openkm/skel/tomcat-7.0.27 /home/okmXX

Ahora hay que estableder el id de la instancia de cloud:

 $ vim /home/okmXX/tomcat-7.0.27/conf/server.xml

Service

 $ cp /home/openkm/skel/tomcat_okm /etc/init.d/tomcat-okmXX
 $ chmod 755 /etc/init.d/tomcat-okmXX
 $ update-rc.d tomcat-okmXX defaults

Ahora hay que estableder el id de la instancia de cloud:

 $ vim /etc/init.d/tomcat-okmXX

Apache

 $ cp /home/openkm/skel/okm.conf /etc/apache2/sites-available/okmXX.conf

Ahora hay que estableder el id de la instancia de cloud:

 $ vim /etc/apache2/sites-available/okmXX.conf

Y activa la configuración:

 $ a2ensite okmXX.conf

Backup

 $ cp /home/openkm/skel/backup_okm.sh /root/backup_okmXX.sh
 $ mkdir /root/okmXX

Ahora hay que estableder el id de la instancia de cloud:

 $ vim /root/backup_okmXX.sh


Install

#!/bin/bash
#
# apt-get install makepasswd
#
YELLOW='\e[1;33m'
BLUE='\e[1;34m'
RED='\e[1;31m'
RESET='\e[0m'
DB_PASSWD=$(makepasswd -minchars=10 -maxchars=10)
MYSQL_PASSWD="zCxAmGq1EM"
SKELETON="/home/openkm/skel"
DEBUG=
LAST_INSTANCE=$(ls /home | grep "okm[0-9]\{2\}" | tail -1)

if [ "$LAST_INSTANCE" == "" ]; then
  SERIAL=00
else
  SERIAL=$(printf "%02d" $((${LAST_INSTANCE:3} + 1)))
fi

SHUTDOWN_PORT=$((8005 + $SERIAL * 100))
HTTP_PORT=$((8080 + $SERIAL * 100))
AJP_PORT=$((8009 + $SERIAL * 100))
INSTANCE="okm$SERIAL"

if [ -d /home/$INSTANCE ]; then
  echo -e ${RED} "Path already exists '/home/$INSTANCE'" ${RESET}
  exit
fi

if [ "$(netstat -tln | grep :$SHUTDOWN_PORT)" != "" ]; then
  echo -e ${RED} "Shutdown port $SHUTDOWN_PORT already in use" ${RESET}
  exit
fi

if [ "$(netstat -tln | grep :$HTTP_PORT)" != "" ]; then
  echo -e ${RED} "HTTP port $HTTP_PORT already in use" ${RESET}
  exit
fi

if [ "$(netstat -tln | grep :$AJP_PORT)" != "" ]; then
  echo -e ${RED} "AJP port $AJP_PORT already in use" ${RESET}
  exit
fi

# Create system user
echo -e ${YELLOW} "\nCreate system user '$INSTANCE'" ${RESET}
$DEBUG adduser --disabled-password $INSTANCE

# Create MySQL user
echo -e ${YELLOW} "\nCreate database & user '$INSTANCE' with password '$DB_PASSWD'" ${RESET}
$DEBUG mysql -h localhost -u root -p$MYSQL_PASSWD -e "CREATE USER $INSTANCE@localhost IDENTIFIED BY '$DB_PASSWD';
    CREATE DATABASE ${INSTANCE}_app DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;
    GRANT ALL ON ${INSTANCE}_app.* TO $INSTANCE@localhost WITH GRANT OPTION;"

# Create Tomcat instance
echo -e ${YELLOW} "\nCreate Tomcat '$INSTANCE'" ${RESET}
$DEBUG cp -r $SKELETON/tomcat-7.0.27 /home/$INSTANCE
$DEBUG sed -i 's/okmXX/'$INSTANCE'/g' /home/$INSTANCE/tomcat-7.0.27/OpenKM.cfg
$DEBUG sed -i 's/okmXX/'$INSTANCE'/g' /home/$INSTANCE/tomcat-7.0.27/conf/server.xml
$DEBUG sed -i 's/dbPasswd/'$DB_PASSWD'/g' /home/$INSTANCE/tomcat-7.0.27/conf/server.xml
$DEBUG sed -i 's/shutdownPort/'$SHUTDOWN_PORT'/g' /home/$INSTANCE/tomcat-7.0.27/conf/server.xml
$DEBUG sed -i 's/httpPort/'$HTTP_PORT'/g' /home/$INSTANCE/tomcat-7.0.27/conf/server.xml
$DEBUG sed -i 's/ajpPort/'$AJP_PORT'/g' /home/$INSTANCE/tomcat-7.0.27/conf/server.xml
$DEBUG chown $INSTANCE:$INSTANCE /home/$INSTANCE -R

# Configure Tomcat service
echo -e ${YELLOW} "\nConfigure Tomcat" ${RESET}
$DEBUG cp $SKELETON/tomcat-okm /etc/init.d/tomcat-$INSTANCE
$DEBUG sed -i 's/okmXX/'$INSTANCE'/g' /etc/init.d/tomcat-$INSTANCE
$DEBUG chmod 755 /etc/init.d/tomcat-$INSTANCE
$DEBUG update-rc.d tomcat-$INSTANCE defaults

# Create Apache VirtualHost
echo -e ${YELLOW} "\nCreate Apache VirtualHost" ${RESET}
$DEBUG cp $SKELETON/okm.conf /etc/apache2/sites-available/$INSTANCE.conf
$DEBUG sed -i 's/okmXX/'$INSTANCE'/g' /etc/apache2/sites-available/$INSTANCE.conf
$DEBUG sed -i 's/ajpPort/'$AJP_PORT'/g' /etc/apache2/sites-available/$INSTANCE.conf
$DEBUG a2ensite $INSTANCE.conf

# Configure backup
echo -e ${YELLOW} "\nConfigure backup" ${RESET}
$DEBUG cp $SKELETON/backup_okm.sh /root/backup_$INSTANCE.sh
$DEBUG sed -i 's/okmXX/'$INSTANCE'/g' /root/backup_$INSTANCE.sh
$DEBUG mkdir /root/$INSTANCE

Uninstall

#!/bin/bash
YELLOW='\e[1;33m'
RESET='\e[0m'
DEBUG=echo
INSTANCE="okmXX"

# Remove backup
echo -e ${YELLOW} "\nConfigure backup" ${RESET}
$DEBUG rm -f /root/backup_$INSTANCE.sh
$DEBUG rm -rf /root/$INSTANCE

# Remove Apache VirtualHost
echo -e ${YELLOW} "\nRemove Apache VirtualHost" ${RESET}
$DEBUG a2dissite $INSTANCE.conf
$DEBUG rm -f /etc/apache2/sites-available/$INSTANCE.conf

# Remove Tomcat service
echo -e ${YELLOW} "\nRemove Tomcat" ${RESET}
$DEBUG update-rc.d -f tomcat-$INSTANCE remove
$DEBUG rm -f /etc/init.d/tomcat-$INSTANCE

# Remove Tomcat instance
echo -e ${YELLOW} "\nRemove Tomcat '$INSTANCE'" ${RESET}
$DEBUG rm -rf /home/$INSTANCE/tomcat-7.0.27

# Remove MySQL user
echo -e ${YELLOW} "\nRemove database & user '$INSTANCE'" ${RESET}
$DEBUG mysql -h localhost -u root -p -e "DROP USER $INSTANCE@localhost;
    DROP DATABASE ${INSTANCE}_app;"

# Create system user
echo -e ${YELLOW} "\nCreate system user '$INSTANCE'" ${RESET}
$DEBUG deluser --remove-home $INSTANCE $INSTANCE