This post is all about my first hello world to Node.js runs on Amazon EC2. I will note down the steps on how to get through Amazon EC2, start an instance, and how to download and build Node.js on Amazon EC2, and runs a Hello World Example!
This post includes nearly complete steps from how to setup Amazon EC2 and setup Node.js, it is recommended for all level of readers who don’t know Node.js and Amazon EC2, but at least you need to know how to use Linux and have basic programming skills.
First of all, you need a credit card to apply Amazon EC2, assume you are using Windows, you need a Putty to access Amazon EC2 Linux Server instance, and Puttygen, to generate your private key files.
Next, navigate to https://console.aws.amazon.com, login with your Amazon EC2 account, sign in to AWS Management Console, and navigate to EC2 Tab.
Steps:
1. To launch an Amazon EC2 instance.
Click on “Launch Instance” on the top left just under My Instances panel.
Then select “Community AMIs”, type “nodejs” on the keyword box, an AMI with ID ami-a8ca37c1 is shown, and click “Select”.
Then for “Instance type”, choose “Micro” for free tier (not need to pay for 1 year), or you can use Small instance (1 hour $0.087), I chose Small instance.
Click “Continue” at the bottom to navigate to next steps. For “Advanced Instance Options”, we not need to choose, just click “Continue” again. And then you will come to a screen with key – value pairs. Normally we not need to bother also, but for convenience you can type key (name) value (nodejs) to help you organize, browse your created instances, like a Tag.
Click “Continue” you will come to screen to create keypair. OK, choose “Create a new Key Pair” if there is no existing key pairs created before. As shown below, you can enter a easy-remembered name for your key pair, for example, I write “fyhaokey2”, and then click “Create & Download your Key Pair”, you should get a “.pem” file. Save it at some convenient location.
Now, open your Puttygen, click on Load, remember to choose (All File Types), and then select your “.pem” file. And then, click “Save private key”, you will get your “.ppk” file. “.ppk” file will be used with Putty later which used in authentication when you log in to Amazon EC2.
Back to your AWS browser, click on “Continue”, you will come to the screen to configure a firewall. You can select “default” OR, to ensure port 22 and port 80 is enabled, and then click “Continue” further to finish the process create the instance.
Once back to the main screen, you will see your instance’s status is in pending mode, wait a minute, it will become running mode.
Next step, we need to apply for “Elastic IPs”, click on “Elastic IPs” at the bottom left of the screen.
Let’s allocate a new address, and associated with your just created EC2 instance. Once done, back to main screen by click on “Instances” on the left menu bar. Click on your instance, see below, you will got something like this:
Let’s ping your elastic IP see whether it is on or not. By the time you reading this post, my elastic IP (50.19.125.189) had been released, so that this IP address is disabled, you may try your own.
2. To use Putty to access our EC2 instance.
At host name, write your elastic IP address, port remained 22.
Then, click on left side under “Category”, click “SSH” and expand and click “Auth”. Then, at right side, for “Private key file for authentication”, you browse your “.ppk” file, and then click “Open” to open the session.
And then, login as “ec2-user”, then “sudo bash” to execute command on behalf of “ec2-user”.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl http://npmjs.org/install.sh | sh
Copy the contents, and execute it on your putty.
Wait for about 10 to 20 minutes, the nodejs will be installed completely.
4. To test our Hello World Nodejs !!!
OK, now we create a file called hello.js, with the content:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World Nodejs run on Amazon EC2 by fyhao\n');
}).listen(80);
console.log('Server running on Amazon EC2');
and then,
we execute this, by type:
node hello.js
Then, you should see the Putty console with the text “Server running on Amazon EC2”.
OK, last step, open your favorite browser (for me Google Chrome), navigate to your created Elastic IP address, you should see the plain text you have made in hello.js !!!
Recently my Facebook Iphone Apps news Feed is not responding, it always show “No Internet Connection” while I am in Internet Conection. I can use Facebook Messages, Place, Chat, Friends, but can’t use news feed feature.
I just found the workarounds by blog.dk.sg, the method is simple:
1) Go to Facebook app’s main page
2) Go to Account on the top left corner
3) Select Help Center
4) Login to your account (Remember to check “Keep me logged in”)
In this post, I will write what technical stuff, work related I experienced, and my in-heart feeling throughout today. Today I will use English to touch about work related, but use Chinese to express my thoughts.
WOW, first hour in this morning I had implemented an interesting stuff, that is to build a simple cache manager in front of Dao (Dao Access Object) class. It is an in-memory model, the data will be kept in the server’s memory. Every cached data will have expired time, it will be automatically refreshed when the time is expired, moreover, when the insert / update / delete operation of specific Dao class is executed, the cache data associated with it will be refreshed automatically. The best thing is in current system framework can easily migrate to use this cache manager without having a big changes. The next step I should do is to create custom configuration setting for cache manager, or by using Annotation to realize auto configuration. OK, the benefits of Cache Manager is, the system is able to not query database everytime when need it but read from the cache directly, it should be able to increase application performance since database operation always eat up more resources. I just have make cache for certain parts of system that need cache, and any other places is not affected. I should continually to test it to know the real performance had brought by this changes.
At the time I feel boring in front of computer, I had researched Asynchronous Servlet 3.0 Proposal, it added some additional methods to existing Servlet 2.5 to handle asynchronous use cases, such as Ajax, or Comet (Reverse Ajax), or Streaming. I also thought if current system framework is able to integrate with this feature, and I need more research in order to make conclusion. In our company we use Tomcat, and I know Tomcat 6 had its own Comet Servlet implementation, but I am not sure if it is a standard or not, the better for us is following standard in order our system can be migrated to any type of web server. Now, Java EE 6 had supported Asynchronous Servlet 3.0 and had been released last year, and the best supporting web server is Glassfish, by using Glassfish you can easily deploy Java EE 6 and EJB 3.1 applications, furthermore, it supports what "modern browser" had supported, HTML5 WebSocket (bi-directional socket connection between server and browser client). Let’s try it if you interested.
For information, I had also briefly introduced cloud computing service I had used to my colleagues. But I am sorry I have no convey clear information when I am introducing. Now, here, to all readers, why cloud is your better choice?
I had used Google Appengine and Amazon Web Service before, even in my final year project during degree study, these two are the leading cloud computing service provider in the world. If you don’t know what is cloud computing, many information online had told you what this is. Many advantages brought from cloud, to enterprise and to individuals. In simple, the main advantage is to cut cost, pay on what you use; easy to scale up to more server instances in short time when your application needs it, and scale down when your application don’t need it; more secure (somebody may not agreed this, but theoritically to hack cloud is very hard in this stage).
In short, Google Appengine provides full stack infrastructure framework includes everything what you needs such as Google Datastore (a BigTable key-value data store implementation) that you can used to store data (like database) using JPA or JDO that you familiar or low-level API if you want to. It also provides Memcache, Image Service, Task Scheduling Service, Queue, Channel API (to make Comet Application). It provides free to use at first, you don’t need to pay single cent to run your first Hello World Google Appengine application, and only the time your application had brought in more bandwidth, meant that is the time you start to earn money, then you have to pay, just pay on what you use.
Amazon Web Service is another cloud computing service provider besides from Google Appengine. AWS provides many types of cloud service, such as Amazon EC2, Amazon Simple Storage Service, Amazon RDS, and many more. It provides lower level cloud infrastructure, therefore you need more knowledge to operate on.
By using Amazon EC2, it virtualizes a blank server for you, and you are able to install anything you want, just like a normal server you get from data centre. Second, it is pay on what you use, one hour just 0.085 US Dollar. You can run it in, say 3 hours, and closed it when you don’t want. Sometimes I want to test my web application, I just click click click in the user interface (or you can also use window command prompt) to access a Linux server instance and upload my applications and test, from my home, very convenient. I really not need to buy a Linux server keep in my home, waste my money, when I don’t want it, I can close it and return back, it will not charge me afterwards. EC2 has also provides an important feature called AMI (Amazon Machine Image). Meant, when you had headache to build up your web server, your database, and your applications, you can store the current setting into AMI, and then you close the EC2 server instance, AMI will be stored on Amazon S3. When you need it, you can just restart your application based on AMI you have made last time, you don’t need even to have another headache time to rebuild up your web server and cumbersome database. Some people had also created some setup and saves as public AMI and you can directly use their AMI to continue your own setup. You can also sell your created AMI in marketplace, or make it private, use by yourself. WOW… Additional information, EC2 provides full stack of real time monitoring feature, you can always easily know the performance or health of every part of your server.
EC2 is for computation, it cannot keep data last long. You should use Amazon S3, to store your static files. You are able to upload any static files, video, images, create folders on Amazon S3, and it provides a public URL for your friend to download. You can set different access permission to different folders, files, you had created. Same, pay based on what you use. Currently, I had used Amazon S3 for more than 700MB, and charged me 10 cents US Dollar each month. WOW, amazingly, so cheap. I used it to backup my company program code (I had backup in many places in case any accidents occurred) every days. I used it for private usage, and it should not be able for publicly viewed.
Who use Amazon Web Services? The fact is that part of the Facebook Photos using Amazon S3 to store their photos because Amazon S3 provides more stable and easy to use feature. Secondly, Second Life used Amazon EC2 to run their virtual 3D world instance. They can just focus on development of application logic but leaves the lower infrastructure to Amazon EC2.
Maybe our company should try cloud computing service (or maybe had already tried), but I am not sure if it is suitable, still need more research to make conclusion. Because I know the manager should have many problems regarding this: is it safe? is it really cut cost? is it suitable for us and customers and I can’t answer it clearly at this time.
Heard Twitter had recently changed their back end structure, by changing into Java server called Blender, and changing MYSQL database into real time search database called Lucene, and as a result Twitter search is 3 times faster than former. Ruby is still a good programming language for faster development for small and medium web application, however, traditional Java still bring benefits for larger web applications for its well-structured, higher scalability.
James Gosling Joined Google
Father of Java, James Gosling, recently left from Oracle, formerly Sun Microsystems, and joined Google in 28 May 2011.
Most people from industry thought the action of Oracle taken over Sun Microsystems is not clever, although they had succeeded for the process of taken over, but they lost some leaders from open source world, such as James Gosling (Father of Java), Tim Bray and Simon Phipps (Father of XML). They thought that the objective of Oracle taken over Sun Microsystems is to sue Google which violates Oracle’s Java patent, Google Android Dalvik VM. No doubt, Java is very important to Google, added Father of Java had joined Google, not only he can extend Java features and contribute his talents, but also helps Google to fight with Oracle on the Java patent war. Added James’s joining to Google will be also benefiting the continually opening of Java.
Java be the First on Tiobe Rank
Java is still be the first on Tiobe Rank for 10 years. C, always be the second popular than Java. People believed in long term, C#.net maybe the only programming language can fight with Java, what do you think? I am so opening and I loved C# also, same as how I love Java. People compared C#.net over Java, where C#.net had built in modern and advanced language features such as Lambda, or we said functional programming (although Java introduced Lambda on Java 7, but still cumbersome if compared with C#.net, maybe try Scala if you intend to.)
OK, why, Java always be the first? 8 reasons.
It is free.
It is cross-platform.
It got strong supports from academic field.
It is simpler language compared with C++, and C.
Mature enterprise platform.
Wireless mobile application.
Java Community Process (JCP), an open organization for exchange information and comments for Java.
Supports from open source organization and non-profit organization.
还有一个朋友,才18岁。网友,没见过他,但他发表过许多很出名的 Discuz 插件,我的站也用了他的插件。好了,他才18岁,但是网页设计也是很强,编写PHP Back End也是不错,都很有创意。他写的插件我很喜欢。他也是一个有干劲的人,看得出他一直在努力,做得更好。他现在也是一个 Web Hosting Provider,做得不错,大家可以去支持哦!