auniverseaway / slick-2

A blogging engine written for Apache Sling 8.
Apache License 2.0
31 stars 14 forks source link

receipe to install and run a slick-2 powered blog site in AWS 24x7 at low costs #24

Open chrismade opened 7 years ago

chrismade commented 7 years ago

Hi Chris, I was trying to find my own route to a blog based on apache sling - IMHO this great software is completely underrated and I dislike the fact that I deal with AEM at work but used then wordpress for my own blog. So I found your project - I guess that is similar to your own story

My first idea (slick-2 without commenting option at that time) was to start an EC2 with java only for the time of writing a blog article (and stop it after publish) and deliver thru a EC2 micro/dispatcher which runs 24x7 maybe use cloud-based commenting (e.g. Disqus) later Now we have commenting built-in - Java has to be up 24x7 So I change my plans accordingly

This is my receipe so far for AWS:

1.) create a keypair (using AWS console)

2.) create a security group (using AWS console) allow inbound from "everywhere" (definitely requires finetung later when dispatcher and SSL termination on Elastic loadbalancer is up)

22/tcp SSH
80/tcp HTTP
8080/tcp HTTP

maybe debug port later

3.) Start an EC2 Instance Launch EC2 instance, type "t2.micro" (1CPU, 1GB RAM, 8GB rootfs) AWS Linux 64bit using security group created in [2] using keypair created in [1]

login via SSH as "ec2-user", testing the key from keypair, execute sudo yum update reboot from AWS console

4.) create an EBS volume of ... 10 GB attach to the instance from [3] check with dmesg what device it is, in my case it is /dev/sdb

So next create a data partition of 100%

sudo bash
fdisk /dev/sdb
O
N
P
1
All sector
W
Q

make it mountable

mkdir /sling
mkfs -t ext4 /dev/sdb1
mount /dev/sdb1 /sling
mkdir /sling/slick21
chown ec2-user /sling/slick21
vi /etc/fstab

add this line at the end of the file /dev/xvdf1 /sling ext4 defaults,nofail 0 2 :x

note: use mount to figure out if the device name has been mapped, like /dev/sdb into /dev/xvdb in this case

exit # root user

now back as "ec2-user" ... download sling-8

cd /sling/slick21
curl -v -k -O http://mirror.23media.de/apache//sling/org.apache.sling.launchpad-8.jar

5.) Install and config required environment

sudo yum install git java-1.8.0-openjdk-devel

Then use the alternatives command to make Java 1.8 the default.

sudo /usr/sbin/alternatives --config java
sudo /usr/sbin/alternatives --config javac

6.) Install Maven - a bit more complicated in AWS Linux

sudo wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
sudo yum install -y apache-maven
mvn --version 

7.) clone slick-2

cd /sling/slick21
git clone https://github.com/auniverseaway/slick-2.git

8.) start sling-8

java -version check if it is really V8

java -jar org.apache.sling.launchpad-8.jar start &

not sure here if there are better suitable parameter(s) I should consider

9.) Install slick-21

cd slick-2
mvn clean install -PautoInstallBundle

10.) Test in browser (from another PC)

http://<ip-of-aws-box>:8080

login as admin/admin

there is a built-in test option in the sling startpage - which fails (error 500, expected 201)

http://<ip-of-aws-box>:8080/author.html

is showing parts of the expected slick-2 blog page but no login

I assume it is a low memory but I don't know java (jre) well enough to fix it

Switching to a larger EC2 box with more RAM would be one option, but this one is already EUR 9 / Month and I also would like to have a Elastic loadbalancer (EUR18/Month) plus SSL certificates (yes, multiple! for free!) and it should NOT go too expensive as this is just a non-commercial hobby site

any hints?

auniverseaway commented 7 years ago

Couple things:

  1. Make sure you're using proper Java (JRE), not OpenJDK. I've never tested Slick on OpenJDK.
  2. I would avoid putting maven on the box. Install from your local or use a CI tool. Your life will be easier.
  3. You won't be able to access slick at http://<ip-of-aws-box>:8080 and expect it to just work. There's various sling mappings that need to be in place if you want to do that. You could basically WebDAV into your Sling instance and change /etc/map values to match your IP, or you can change the values in the Slick source code and install again.
  4. I would make sure Sling is running without issue before installing Slick (maybe you already did)
  5. I would probably put a basic apache proxy in front of Slick initially. You can avoid the etc/map mess (in favor of Apache rewrites), and you can later transition to dispatcher. In the Slick readme, there's a sample.
  6. None of this seems like a RAM problem. You really shouldn't need more than 1024 RAM to get started. However, I have seen Oak run into issues with heap space. This happens after about 2 weeks, it runs out of memory when trying to index. I can comfortably run Slick 2 with 1200MB Heap on a 2GB VM.
  7. I'll see if I can put together a guide to help. I've never run Slick on AWS (my personal projects use Linode), but it should be pretty easy.
  8. LetsEncrypt gets you free certs on any platform, you don't have to be tied to AWS.
  9. LoadBalancing is going to be a problem unless you put Oak on Mongo... and then you're talking a lot more complexity. Slick has only ever been run in TarMK environments.
chrismade commented 7 years ago

Thanks, I guess [3] is the hottest trace, I was unaware of "mappings in slick will become" an issue, but the moment you mentioned it, it makes perfect sense - so, yes, using the dispatcher is already still on my list and will use it instead of my first plan to use the loadbalancer (mainly for SSL termination, not because I expect that much traffic) - give me a weekend or two to incorporate your hints into my plan above . sling internal test always works when starting with -Xmx1g - and for slick, according to your recommendation - it should be -Xmx2g - right?

auniverseaway commented 7 years ago

I would start with -Xmx1g and go from there. I run my Slick instances at 1200m.