Instruction about how to install Nodebb with Mongodb in AWS EC2?
-
Hi Nodebb heroes,
I was struggling to figure out how to set up and install nodebb with Mongodb in AWS EC2, searching everything in google, but unable to find a detailed and helpful instruction telling me how to implement this. I saw in nodebb docs there are some but related to cloud9 or heroku, etc. It would be awesome to add AWS EC2 chapter specifically. I plan to have a community forum for local. Hope receive help from you guys and here show my thanks in advance. -
Thanks for your real time reply, @julian.
Not sure about that, I was trying to follow the instruction of AWS EC2 about deploy node app and configure database of Mongodb, that was pretty confusing for me as newbie of node app. I will continue that way but would be great if someone share the experience and show some shortcut to me. -
Hi, @julian, as you say, I follow the instruction of Ubuntu to set up nodebb in EC2, everything looks good finally. I run ./nodebb dev, all stuff loads correctly and showing "NodeBB is now listening on: 0.0.0.0:4567". But with my EC2 public IP:4567, I cannot get the page, seems I set wrong hostname in ./nodebb setup or whatever? Thanks.
-
@flyinghawker Check that your AWS EC2 security zone allows traffic to port 4567.
As an aside, you should consider putting a reverse webserver (such as Nginx but it can be done with Apache) in front of your NodeBB instance. The reverse webserver can handle your SSL connections, provide logging, etc.
-
@flyinghawker If you need details they can be found here:
https://docs.nodebb.org/en/latest/configuring/proxies.html
-
@rod really, I set TCP port available in security group, now get it work. will list all steps I used to try hard to make all things work together here and let all other newbies like me can have better start in AWS ec2 for nodebb. Still look at the reverse webserver idea. Thanks, man.
-
Ok, finally with 4 or 5 nights' piece of time I get nodebb working in AWS EC2 free tier. Here I will list some painful steps for me as newbie.
Firstly, I was confused about the difference b/w EB and EC2 of AWS as well as their CLI: EB cli and EC2 CL tool. EB is like stupid tool of EC2, while EC2 allows you have more free space to configure your server. For people who want to use Mongodb instead of DB recommended by AWS, seems EC2 is only choice.
Then I follow this instructions:
https://docs.mongodb.com/ecosystem/platforms/amazon-ec2/- set up EC2 command line tools,
- Generate an EC2 key pair,
- Create a security group
For step 1, download the tool, and scroll down to find link:
Amazon EC2 Command Line Reference -> Setting Up the CLI Tools (Linux and Mac OS X) -> Setting Up the Amazon EC2 CLI Tools on RHEL, Ubuntu, or Mac OS X -> Download and Install the CLI Tools.
Over there, I got confused b/w AWS_ACCESS_KEY/AWS_SECRET_KEY and EC2 key pair, former one is access key which allows you to use ec2 command line tool, latter one will allow you connect to your instance of AWS EC2.For step 2, remember to do
chmod 400 my-key-pair.pemFor step3, remember to add proper rule there, for example, we need 4567 port available, what I do is set 'all TCP' range including 4567(be default it is included), maybe not good but temporarily work now, will improve later.
And then, thing became disgusting for me. You have to have ami which is Amazon machine images, just like a prototype which you can use it to create an instance with some property, if you want to create it from scratch, it may require manifest file which is WTH for me. So I use my existing EC2 instance to create an image and use that to continue.
In above link, you will see this command to create instance
ec2-run-instances ami-05355a6c -t m1.large -g [SECURITY-GROUP] -k [KEY-PAIR] -b "/dev/xvdf=:200:false:io1:1000" -b "/dev/xvdg=:25:false:io1:250" -b "/dev/xvdh=:10:false:io1:100" --ebs-optimized true
For simplicity, I simplify it as
ec2-run-instances ami-05355a6c -t m1.large -g [SECURITY-GROUP] -k [KEY-PAIR]
And here is one tricky thing you have to do, check link of 'ec2-run-instances':
http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-RunInstances.html
add--region region
in above command when create instance, that tell where your ami locates, California beach or Tokyo oSakeYa.
Also pay attention to either ID or name of group name/key-pair.
And yeah, if you want to check your instance byec2-describe-instances [INSTANCE-ID]
Don't forget to have ''--region'' parameter.
Once you successfully create ec2 instance and smoothly connecte with it through SSH, I would suggest to check this link to continue:
https://github.com/SIB-Colombia/dataportal-explorer/wiki/How-to-install-node-and-mongodb-on-Amazon-EC2
This is perfect for me, no error totally. Unless one thing need to point out, whencd node git checkout tags/<NODE_VERSION> ./configure make sudo make install
when do 'make', many people said it may take 10 ~ 15 or 30 mins at most, but it waste me over 2 hour to compile, I redid several times because I thought it was somewhere wrong when I always saw deprecation warning over console. It really sucks!
Afterwards, thanks to @julian suggestion, I follow some steps of Ubuntu install from link: https://docs.nodebb.org/en/latest/installing/os/ubuntu.html.
When do ./nodebb setup,
URL used to access this NodeBB, I use my instance public IP,
Host IP or address of your MongoDB instance (127.0.0.1), as you seeNext, finally I get it up and running, but unable to get page in my page, and thanks to @rod , I add rule in my security group which allow port 4567 accessible.
Also thanks to @rod, I simply set reverse proxy server Nginx based on these two links:
http://devblog.daniel.gs/2014/01/deploying-node-apps-on-aws-ec2-with.html
This gives some idea about what it is.
https://docs.nodebb.org/en/latest/configuring/proxies/nginx.html
You can copy and paste first example.server { listen 8080; server_name 21.13.14.99; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:4567/; proxy_redirect off; # Socket.IO Support proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }
}
I leave all things by default except change "listen" to 8080 and "server_name" with my ec2 instance public IP(here is just example number).
Reason: here still is problem that listen port 80 seems not work for me, my domain display 502 bad gateway error, so I randomly change it to 8080 and boom!Don't want to waste much time on server setup, prefer to have more fun time in coding. Going to enjoy that soon. Haha. Thanks!
-
@flyinghawker It is nice to see that you have your NodeBB up and running. Great job!