AWS EC2 Ubuntu Tomcat PostgreSQL

Goal: to download and get XWiki set up with Apache Tomcat and PostgreSQL in an EC2 instance running Ubuntu

Versions after updates:

Ubuntu 16.04.4
openjdk version 1.8.0_162

Steps taken during installation:

  1. Set up an EC2 instance that’s using Ubuntu
  2. Configured PuTTy to open it
    3.to update the Ubuntu instance, I ran the command:

sudo apt-get update

  1. to download Java, I ran the command:

sudo apt-get install openjdk-8-jdk

  1. Ran the command(s):

wget -q “https://maven.xwiki.org/public.gpg” -O- | sudo apt-key add -

sudo wget “https://maven.xwiki.org/stable/xwiki-stable.list” -P /etc/apt/sources.list.d/

as per tutorial found here: http://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Installation/InstallationViaAPT
6. Ran

sudo apt-get update

  1. Ran

sudo apt-get install xwiki-tomcat8-pgsql

  1. “Setting up xwiki-psql-common (10.2) …” is written to the screen and then a pink/purple package configuration GUI shows up and here’s where I get stuck despite the different combinations of input I’ve provided.

First prompt:

Select a remote hostname to use or select new host to enter a new host.

new host
localhost

Which is best to select and why?

Say I select localhost

Please provide a password for xwiki to register with the database
│ server. If left blank, a random password will be generated.

│ If you are using “ident” authentication, the supplied password will not
│ be used and can be left blank. Otherwise, PostgreSQL access may need to
│ be reconfigured to allow password-authenticated access.

│ PostgreSQL application password for xwiki:

Should I use “ident” authentication? Or type in an application password for xwiki?

I opt to type in an application password and then this prints to screen:

Creating config file /etc/xwiki/hibernate.cfg.xml with new version
creating postgres user xwiki: success.
verifying creation of user: success.
creating database xwiki: success.
verifying database xwiki exists: success.
dbconfig-common: flushing administrative password
allow xwiki user to create new schemas in database xwiki
Setting up xwiki-tomcat8-common (10.2) …
Setting up xwiki-tomcat8-pgsql (10.2) …
Setting up authbind (2.1.1+nmu1) …
Processing triggers for libc-bin (2.23-0ubuntu10) …
Processing triggers for systemd (229-4ubuntu21.1) …
Processing triggers for ureadahead (0.100.0-19) …
W: Operation was interrupted before it could finish

What could’ve interrupted this process?

Since I saw the last line, I ran command:

sudo apt-get install xwiki-tomcat8-pgsql

and this was printed to the screen:

Reading package lists… Done
Building dependency tree
Reading state information… Done
xwiki-tomcat8-pgsql is already the newest version (10.2).
0 upgraded, 0 newly installed, 0 to remove and 41 not upgraded.

does this mean postgresql and tomcat has been set up still?

So since I assumed everything was set up, I ended up following the instructions for the memory allocation for tomcat8 and replaced the current JAVA_OPTS line of code with the recommended line of code:

JAVA_OPTS="-Djava.awt.headless=true -Xmx1024m"

When I tried to point my browser to:

http://localhost:8080/xwiki

and/or

http://myEC2Address.compute.amazonaws.com:8080/xwiki

I got:

HTTP ERROR 500

  • Where did I go wrong here?
  • Is there any resources to walk a new user through this dbconfig-common configuration stage for postgres and tomcat?
  • If not, would any of you mind walking through this process for a new user?

We’re really excited to use XWiki over here and we’re looking forward to getting past this hurdle here. If there’s any additional information you require, feel free to ask!

Thanks in advance!

ERROR 500 just mean “something bad happen”. You should take a look at Tomcat log in {{/var/log/tomcat8/catalina.out}}. Concentrate on the very first error you can find after starting it (most of the following errors are going to be consequences of the first one).

I did not know the host was asked for Postgres. In any case both Postgres and XWiki are supposed to run on the same server with this setup so I guess the best here is localhost.

XWiki is configured to access the database with a user and a password in this package so indeed you need to make sure XWiki can do that.

No idea, the log does not give any kind of error so this is weird. The message feel like something killed dpkg process (you probably get the same kind of message if you do ctrl+c).

Thank you for responding so promptly and answering all of my questions! I’ll go ahead and check the Tomcat logs right now to see what happened.

I ran the command:

cd /var/log/tomcat8

To get the top 5 lines from the the log file, I ran the command:

head -n 5 catalina.out

Got these messages:

Apr 09, 2018 7:10:23 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat8/common/classes], exists: [false], isDirectory: [false], canRead: [false]
Apr 09, 2018 7:10:23 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat8/common], exists: [false], isDirectory: [false], canRead: [false]
Apr 09, 2018 7:10:23 PM org.apache.catalina.startup.ClassLoaderFactory validateFile

To get the last 5 lines of the log file, I then ran the command:

tail -f catalina.out

this error message was the only error printed to screen:

Apr 10, 2018 1:52:30 PM org.apache.tomcat.util.net.NioEndpoint checkParachute
SEVERE: SEVERE:Memory usage is low, parachute is non existent, your system may start failing.
Apr 10, 2018 1:52:40 PM org.apache.tomcat.util.net.NioEndpoint checkParachute
SEVERE: SEVERE:Memory usage is low, parachute is non existent, your system may start failing.
Apr 10, 2018 1:52:50 PM org.apache.tomcat.util.net.NioEndpoint checkParachute

Unfortunately my experience with Apache Tomcat is rather limited, however, when I ran the command:

cd /usr/share/tomcat8

then used “ls” to peek at what was in this directory-- I didn’t see /common or /classes here. Could these two things be requirements for apache tomcat to run that weren’t installed for some reason due to an error during installation?

In the meantime, I’ll wipe my EC2 instance and spin a fresh one up and redownload/install everything and see what happens.

This seems to suggest that your memory setup was not taken into account.

That makes sense, however, I double checked to make sure my changes for the memory allocation were made to the file found at:

/etc/default/tomcat8

Here’s my tomcat8 file from the location in the instructions:

The home directory of the Java development kit (JDK). You need at least

JDK version 7. If JAVA_HOME is not set, some common directories for

OpenJDK and the Oracle JDK are tried.

#JAVA_HOME=/usr/lib/jvm/java-7-openjdk

You may pass JVM startup parameters to Java here. If unset, the default

options will be: -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC

Use “-XX:+UseConcMarkSweepGC” to enable the CMS garbage collector (improved

response time). If you use that option and you run Tomcat on a machine with

exactly one CPU chip that contains one or two cores, you should also add

the “-XX:+CMSIncrementalMode” option.

JAVA_OPTS="-Djava.awt.headless=true -Xmx1024m"

To enable remote debugging uncomment the following line.

You will then be able to use a java debugger on port 8000.

#JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"

Java compiler to use for translating JavaServer Pages (JSPs). You can use all

compilers that are accepted by Ant’s build.compiler property.

#JSP_COMPILER=javac

Use the Java security manager? (yes/no, default: no)

#TOMCAT8_SECURITY=no

Number of days to keep logfiles in /var/log/tomcat8. Default is 14 days.

#LOGFILE_DAYS=14

Whether to compress logfiles older than today’s

#LOGFILE_COMPRESS=1

Location of the JVM temporary directory

WARNING: This directory will be destroyed and recreated at every startup !

#JVM_TMP=/tmp/tomcat8-temp

If you run Tomcat on port numbers that are all higher than 1023, then you

do not need authbind. It is used for binding Tomcat to lower port numbers.

(yes/no, default: no)

#AUTHBIND=no

Also, when I tried to hit the end point while I was running the error logs feed I got this:

Apr 10, 2018 2:11:20 PM org.apache.coyote.http11.AbstractHttp11Processor process
SEVERE: Error processing request
java.lang.NoClassDefFoundError: Could not initialize class org.apache.tomcat.util.buf.B2CConverter
at org.apache.catalina.connector.CoyoteAdapter.parsePathParameters(CoyoteAdapter.java:1102)
at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:816)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:517)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)

One way to really be extra sure your memory setup was take into account is to execute:

ps aux | grep java

and see of you have -Xmx1024m in the result.

I ran the command

ps aux | grep java

and got:

tomcat8 12458 5.6 31.5 2226980 319772 ? Sl Apr09 65:18 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Djava.util.logging.config.file=/var/lib/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC -Djava.endorsed.dirs=/usr/share/tomcat8/endorsed -classpath /usr/share/tomcat8/bin/bootstrap.jar:/usr/share/tomcat8/bin/tomcat-juli.jar -Dcatalina.base=/var/lib/tomcat8 -Dcatalina.home=/usr/share/tomcat8 -Djava.io.tmpdir=/tmp/tomcat8-tomcat8-tmp org.apache.catalina.startup.Bootstrap start
ubuntu 25150 0.0 0.0 12944 988 pts/0 S+ 14:37 0:00 grep --color=auto java

I see the

-Djava.awt.headless=true -Xmx128m

Is there a better way I can implement this memory allocation step?

/etc/default/tomcat8 is the standard way and it always worked for me on Ubuntu or Debian (Including Ubuntu 16.04). If it’s not taken into account that would mean that it’s overwritten some way but not sure what have the priority over /etc/default/tomcat8. Maybe there is some leftover customization directly in /etc/init.d/tomcat8 (this is the one which start by including /etc/default/tomcat8 and then start Tomcat).

Good news!

Since we had the code changed in /etc/default/tomcat8 and it we weren’t getting our page up, I decided to do a fresh Ubuntu instance with the installs and configurations but I also edited the etc/init.d/tomcat8 file with the JAVA_OPTS="-Djava.awt.headless=true -Xmx1024m" line included in the appropriate spot.

After this, I decided to run the command:

sudo /etc/init.d/tomcat8 restart

I then saw the output to the screen:

[…] Restarting tomcat8 (via systemctl): tomcat8.serviceWarning: tomcat8.service changed on disk. Run ‘systemctl daemon-reload’ to reload units.

I checked the DNS:8080 and saw the tomcat default page which is good!
I then checked the DNS:8080/Xwiki which hung around 20%-24% initialization and didn’t move.

I went back to my ubuntu instance and ran the command:

sudo systemctl daemon-reload

which keeps returning:

Failed to execute operation: Connection timed out

again, I appreciate your time and patience in helping me through this matter!

Another update:

I started the process two more times, the next try I got to 95% and it hung again. My instance started lagging greatly. I then tried to run Putty again, got a black window that hung there, solved this by restarting the instance itself in the AWS console.

After reboot:

The instance is not lagging anymore, I ran the command:

sudo systemctl daemon-reload

the command went through fine.

ran the command:

sudo service tomcat8 status

the status looked good.

while pointing my browser to: DNS:8080/wiki, I ran the command:

/var/log/tomcat8$ tail -f catalina.out

Got these logs as the Xwiki intilization hung at 18%:

Apr 11, 2018 4:11:15 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /var/lib/tomcat8/webapps/ROOT
Apr 11, 2018 4:11:16 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Apr 11, 2018 4:11:16 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /var/lib/tomcat8/webapps/ROOT has finished in 977 ms
Apr 11, 2018 4:11:16 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [“http-nio-8080”]
Apr 11, 2018 4:11:16 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 37316 ms
2018-04-11 16:17:13,232 [XWiki initialization] INFO .HibernateDataMigrationManager - Storage schema updates and data migrations are enabled
2018-04-11 16:17:13,784 [XWiki initialization] INFO .HibernateDataMigrationManager - No data migration to apply for wiki [xwiki] currently in version [1001000]
2018-04-11 16:17:13,785 [XWiki initialization] INFO .HibernateDataMigrationManager - Checking Hibernate mapping and updating schema if needed for wiki [xwiki]
ubuntu@ip-172-31-19-117:/var/log/tomcat8$ tail -f catalina.out
Apr 11, 2018 4:11:15 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /var/lib/tomcat8/webapps/ROOT
Apr 11, 2018 4:11:16 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Apr 11, 2018 4:11:16 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /var/lib/tomcat8/webapps/ROOT has finished in 977 ms
Apr 11, 2018 4:11:16 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [“http-nio-8080”]
Apr 11, 2018 4:11:16 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 37316 ms
2018-04-11 16:17:13,232 [XWiki initialization] INFO .HibernateDataMigrationManager - Storage schema updates and data migrations are enabled
2018-04-11 16:17:13,784 [XWiki initialization] INFO .HibernateDataMigrationManager - No data migration to apply for wiki [xwiki] currently in version [1001000]
2018-04-11 16:17:13,785 [XWiki initialization] INFO .HibernateDataMigrationManager - Checking Hibernate mapping and updating schema if needed for wiki [xwiki]
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00007f7cc5c40000, 65536, 1) failed; error=‘Cannot allocate memory’ (errno=12)

There is insufficient memory for the Java Runtime Environment to continue.

Native memory allocation (mmap) failed to map 65536 bytes for committing reserved memory.

An error report file with more information is saved as:

/tmp/hs_err_pid1308.log

Compiler replay data is saved as:

/tmp/replay_pid1308.log

After this, I changed the appropriate file’s memory allocation from 1024 to 2048 then I restarted tomcat so the changes would reflect this.

I went to DNS:8080/Xwiki again and this time it hung at 50%.

I ran the command:

ps aux | grep java

got the output:

tomcat8 1789 17.6 70.4 4396136 714304 ? Sl 17:08 0:52 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Djava.util.logging.config.file=/var/lib/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true -Xmx2048m -Djava.endorsed.dirs=/usr/share/tomcat8/endorsed -classpath /usr/share/tomcat8/bin/bootstrap.jar:/usr/share/tomcat8/bin/tomcat-juli.jar -Dcatalina.base=/var/lib/tomcat8 -Dcatalina.home=/usr/share/tomcat8 -Djava.io.tmpdir=/tmp/tomcat8-tomcat8-tmp org.apache.catalina.startup.Bootstrap start
ubuntu 1884 0.0 0.1 12944 1324 pts/0 S+ 17:12 0:00 grep --color=auto java

I see that the changes I made to tomcat’s memory took effect. Could there not be enough space/memory in my Ubuntu instance for this?

Please post the output of free -h
You should have more than 2GiB memory without swap in the machine for -Xmx2048m.

Ran the free -h command, here’s my output:

         total         used         free          shared      buff/cache    available
     Mem: 990M        889M           63M           3.0M         37M          2.7M
   Swap:  0B          0B             0B

I’m sorry this will not work, you are trying to allow a max of 2000MiB of 990MiB to the Java memory pool alone. For an instance with with Xmx1024m I’d suggest 2048Mib (2GiB) sytem memory at least, for Xmx2048m min. 3GiB. So you need a bigger instance. Remember the operating system and the database need memory too.
Hope that helps.

Tmortagne, Rbr,

After creating a fresh ubuntu instance with 4GiB (3 wasn’t an option), XWiki completed initiliziation and the distribution wizard is now on screen! Thank you both for your patience and guidance through this process! I learned a lot about Ubuntu,Linux, and Tomcat (and how to diagnose and troubleshoot issues). I’m actually almost done with a write up of this process if this would prove useful here on the forums.

Cheers!

Great !

Note that a link in http://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Installation/#HOtherInstallationMethods would be nice too since that’s the reference place to look at to find install tutorials.

Great to hear. Enjoy your wiki.

@tmortagne: Is there any reasonable setup possible, except for development, on a machine with less than 2GiB memory? If not maybe this should be more explicitly stated in the prerequisites? I looked through the docs but I found nothing that states minimum system memory requirements.

http://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Installation/#HHardwareandSoftwarerequirements

This leads to http://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Performances/#HMemory for memory.

I reviewed both of the documents before and, correct me if I’m wrong, nothing tells you the minimum system memory (i.e. size of “plugged-in memory modules”) requirements.
Everything refers to Java memory parameters. While it should be clear that system memory should be bigger than Java memory, why not add sensible defaults for minimum system memory requirements?
Actually that is what I’d expect to find in the documentation of any application.

I updated the docs. Revert if you dislike it. I feel the info on the hardware requirements should be there. Hope that helps anyone in the future to not run through the same hassle that we saw in the above thread.