So you want to run nodejs on a linux image on Azure, easy right? Well.. kinda..
NodeJS on the Windows Azure Cloud, Start to Finish
The first step to setting up your nodejs application is to remote into your linux image. I’ve taken the following steps from the great guide on windowsazure.com
For a virtual machine that is running the Linux operating system, you use a Secure Shell (SSH) client to logon.
You must install an SSH client on your computer that you want to use to log on to the virtual machine. There are many SSH client programs that you can choose from. The following are possible choices:
- If you are using a computer that is running a Windows operating system, you might want to use an SSH client such as PuTTY. For more information, see the PuTTY Download Page.
- If you are using a computer that is running a Linux operating system, you might want to use an SSH client such as OpenSSH. For more information, see OpenSSH.
This procedure shows you how to use the PuTTY program to access the virtual machine.
- Find the Host Name and Port information from the Management Portal. You can find the information that you need from the dashboard of the virtual machine. Click the virtual machine name and look for the SSH Details in the Quick Glance section of the dashboard.
- Open the PuTTY program.
- Enter the Host Name and the Port information that you collected from the dashboard, and then click Open.
- Log on to the virtual machine using the account that you specified when the machine was created.
Configuration + Prerequisites
If your coming from a non-unix background some of the following commands might be new to you.
Setup your new
sudo passwd root # Changing password for user root. # New password:
Change to the root account, enter the password you created for the
su - # Password:
Update installed packages
yum -y update
Install development packages
yum install kernel-headers --disableexcludes=all yum install gcc yum install gcc-c++ yum -y groupinstall "Development Tools"
Trying to install
development toolswithout installing the kernel-headers package will result in the helpful
gcc (updates) Requires: kernel-headerserror. Note the
development toolscommand produced a single error for me, but everything else still worked.
yum install openssl-devel
Download and extract NodeJS
cd /usr/src wget http://nodejs.org/dist/node-latest.tar.gz tar zxvf node-latest.tar.gz
Change working directory into the extracted folder:
./configure make make install
node -v npm -v
Install git. Unfortunately the version of git accessible by
yumis out of date. So you can’t do:
yum install git
Its ok though, we can just build it from source. I’ve tried few methods, most of them from this SO question but most of them failed on my CentOs, either because of the wrong repos or missing files.
yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel wget http://git-core.googlecode.com/files/git-1.8.4.tar.gz tar -xzvf ./git-1.8.4.tar.gz cd ./git-1.8.4 ./configure make make install
You may want to download a different version from here: http://code.google.com/p/git-core/downloads/list
Setup Github SSH Key
The following instructions were taken from the Generating SSH Keys page on Github
Check for existing SSH keys
cd ~/.ssh ls # Lists the files in your .ssh directory
Check the directory listing to see if you have a file named either
id_dsa.pub. If you don’t have either of those files go to step 2. Otherwise, you already have an existing keypair, and you can skip to step 3.
Generate a new SSH key
To generate a new SSH key, enter the code below. We want the default settings so when asked to enter a file in which to save the key, just press enter.
ssh-keygen -t rsa -C "firstname.lastname@example.org" // Creates a new ssh key, using the provided email as a label # Generating public/private rsa key pair. # Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter] ssh-add id_rsa
Now you need to enter a passphrase.
# Enter passphrase (empty for no passphrase): [Type a passphrase] # Enter same passphrase again: [Type passphrase again]
Which should give you something like this:
# Your identification has been saved in /c/Users/you/.ssh/id_rsa. # Your public key has been saved in /c/Users/you/.ssh/id_rsa.pub. # The key fingerprint is: # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db email@example.com
Add your SSH key to GitHub
Run the following code to view your public key.
Copy and paste the output of the cat command into the Add SSH Key window.
Test your key on Github
ssh -T firstname.lastname@example.org // Attempts to ssh to github # The authenticity of host 'github.com (126.96.36.199)' can't be established. # RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. # Are you sure you want to continue connecting (yes/no)? # yes # Hi AnalogJ! You've successfully authenticated, but GitHub does not provide shell access.
Clone your Git(Hub) Repo
Create your (web) application directory and clone project
cd /srv mkdir www cd www git clone email@example.com:AnalogJ/docker-node-hello.git hello cd hello make install make run
Open up Firewall
Firewalled ports can only be opened by configuring them in the management console in Azure. You can click find the full guide on setting up your azure endpoints
If you have not already done so, sign in to the Windows Azure Management Portal.
Click Virtual Machines, and then select the virtual machine that you want to configure.
Click Endpoints. The Endpoints page lists all endpoints for the virtual machine.
The Add Endpoint dialog box appears. Choose whether to add the endpoint to a load-balanced set and then click the arrow to continue.
In Name, type a name for the endpoint.
In protocol, specify either TCP or UDP.
In Public Port and Private Port, type port numbers that you want to use. These port numbers can be different. The public port is the entry point for communication from outside of Windows Azure and is used by the Windows Azure load balancer. You can use the private port and firewall rules on the virtual machine to redirect traffic in a way that is appropriate for your application.
Click Create a load-balancing set if this endpoint will be the first one in a load-balanced set. Then, on the Configure the load-balanced set page, specify a name, protocol, and probe details. Load-balanced sets require a probe so the health of the set can be monitored. For more information, see Load Balancing Virtual Machines.
Click the check mark to create the endpoint.
You will now see the endpoint listed on the Endpoints page.