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.pem
For 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 by
ec2-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, when
cd 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 see
Next, 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!