Friday, May 31, 2019

Installing BotLibre Enterprise Bot Platform on Amazon Lightsail

Amazon Lightsail is a lightweight cloud website hosting framework based on the Amazon Web Services (AWS) platform. Lightsail can help to quickly jumpstart your project  with a virtual machine, SSD-based storage, data transfer, DNS management, and a static IP for an affordable price.

This guide is to work through the steps to install Bot Libre Enterprise Bot Platform to the AMS Lightsail.

Step 1. Create an Amazon Lightsail instance

Go to Amazon Lightsail website and register a new AWS account if you do not have one yet.

https://lightsail.aws.amazon.com/ls/webapp/home

then login and start to create an instance. Choose a OS Only instance using CentOS 7 Linux system:

Bot Libre requires a Tomcat Web Server, Python Server, and a database to run. To host Bot Libre system you require a dedicated server or VM with minimum 8gb of RAM.  For demonstration purpose, we are using the basic 512MB configuration as following:

After the service is being created, click ‘Connect using SSH’ to connect to it.

Lightsail assigns a public IP (e.g. 35.183.67.175) to the instance, and we need the IP to config the web server later on.

After connecting to the instance via ssh, from the terminal, you may start to setup the Java, Ant, Tomcat, Postgres, Python and finally deploy the botlibre web app to Tomcat.

$ sudo su root
$ yum install wget  (install wget tool)

Step 2 - install Java and Ant

Install the Java JDK 1.8 (latest dot release).

$ cd /opt
$ wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http://www.oracle.com; oraclelicense=accept-securebackup-cookie"
"
https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz"
$ tar xzf jdk-8u201-linux-x64.tar.gz
$ cd /opt/jdk1.8.0_201
$ alternatives --install /usr/bin/java java /opt/jdk1.8.0_201/bin/java 2
$ export JAVA_HOME=/opt/jdk1.8.0_201

Install ant

$ cd /opt
$ wget https://www-eu.apache.org/dist//ant/binaries/apache-ant-1.10.5-bin.tar.gz
$ tar xfv apache-ant-1.10.5-bin.tar.gz
$ export ANT_HOME=/opt/apache-ant-1.10.5
$ export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH

Step 3 – Tomcat Install the Tomcat 8 web server.  

$ cd /opt
$ wget https://www-us.apache.org/dist/tomcat/tomcat-8/v8.5.39/bin/apache-tomcat-8.5.39.tar.gz
$ tar xzf apache-tomcat-8.5.39.tar.gz
$ export TOMCAT_HOME=/usr/local/tomcat8
$ mv apache-tomcat-8.5.39 $TOMCAT_HOME
$ vi $TOMCAT_HOME/bin/setenv.sh  (create a new setenv.sh file)

>> add the following JVM option to increase the max memory size in your setenv.sh export JAVA_OPTS="-server -Xmx8g"

$ vi $TOMCAT_HOME/conf/web.xml

>> insert the following XML in your web.xml to enable cors filters (required for JavaScript access)

     <filter>
     <filter-name>CorsFilter</filter-name>
        <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
        <init-param>
         <param-name>cors.support.credentials</param-name>
            <param-value>false</param-value>
        </init-param>
    </filter>
<filter-mapping>
     <filter-name>CorsFilter</filter-name>
        <url-pattern>/rest/*</url-pattern>
     </filter-mapping>
     <error-page>
        <error-code>404</error-code>
        <location>/404.jsp</location>
     </error-page>
$ vi $TOMCAT_HOME/conf/server.xml
>> update connector port 8080->80, 8433->433
>> add to connector, URIEncoding="UTF-8"
>> update host- <public ip> > autoDeploy=”false”

Start tomcat web server:

$ $TOMCAT_HOME/bin/startup.sh

Go to a browser and check if the server is up and running at http://<public-ip> (e.g. http://35.183.67.175)

Troubleshooting: If you do not see the server running, check the server log at $TOMCAT_HOME/logs/catalina.out

Then shutdown the server:

$ $TOMCAT_HOME/bin/shutdown.sh

Step 4 Install PostgreSQL database

>> install postgres database and init it
$ cd /otp
$ rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-3.noarch.rpm
$ yum install postgresql94 postgresql94-server postgresql94-contrib
$ /usr/pgsql-9.4/bin/initdb /var/lib/pgsql/9.4/data
>> Verify database starts/stops/restart:
$ service postgresql-9.4 start
$ service postgresql-9.4 stop
$ chkconfig --levels 235 postgresql-9.4 on
>> Set database password:
$ service postgresql-9.4 start
$ sudo -u postgres psql postgres
\# \password
>> enter new password “postgres” twice
\# \q  (exit)
Step 5. Install Python (Optional)

Bot Libre uses a separate Python web server to support deep learning analytics. Python is not required for bots or NLP, only deep learning analytics such as image classification. If you do not require deep learning you can skip this step.

Run the following commands to install Python, Pop, Tensorflow, Flask and Psycopy2.

$ yum update
$ yum install yum-utils
$ yum groupinstall development
$ yum -y install https://centos7.iuscommunity.org/ius-release.rpm yum -y install python36u
$ yum -y install python36u-pip
$ yum -y install python36u-devel
$ pip3.6 install tensorflow==1.7
$ pip3.6 install flask
$ pip3.6 install psycopg2
$ pip3.6 install pillow
$ pip3.6 install lxml
$ pip3.6 install Cython
$ pip3.6 install jupyter
$ pip3.6 install matplotlib
$ pip3.6 install pandas
$ pip3.6 install opencv-python

Then you may copy the /python from the BotLibre install to /usr/local/python

$ mv <BotLibreInstallRoot>/python /usr/local/python
>> start the python server
$ nohup python3.6 /usr/local/pythonn/app.py &

Step 6. Install BotLibre

The Bot Libre application is a Java “war” file. A war file is a zip file that contains a website and Java libraries.

There are several installation steps:

  • Copy library jars to /usr/local/tomcat8/lib (from bot libre lib sub directories, do not copy botlibre-ai.jar, do not copy botlibreplatform.jar, do not overwrite any files already in tomcat lib)
  • Copy speech voice files to /usr/local/tomcat8/bin/lib (unzip speech voice zip into lib voices directory)
  • Ensure war file is configured with correct database password, domain name, and this must be set in the Site.java file, and the war must be recompiled using the build.xml ant task in Eclipse)
  • Shutdown Tomcat server: $TOMCAT_HOME/bin/shutdown.sh
  • Deploy war file by emptying the $TOMCAT_HOME/webapps/ directory, and copying the botlibreplatform.war to $TOMCAT_HOME/webapps/ROOT.war.
  • Start Tomcat Server: $TOMCAT_HOME/bin/startup.sh
  • Open http://<public-ip> e.g. http://35.183.67.175/

Then you may refer to the generic BotLibre install guide to login as admin user (default password is password), and create workspace, create bot, config bot and train bot.

 

No comments:

Post a Comment