How to install and run Node.js on Alibaba Cloud

Reprinted from: https://bbs.aliyun.com/read/146189.html


Step 1 Select a cloud server 

- Because Node.js is single-threaded, and a single-core cloud server with 512MB memory costs 69 yuan, and a dual-core cloud server costs 222 yuan (although there is more memory, but my application does not need it, it is better to buy 3 single-core ones if necessary), so of course the menu Core 
- 20GB free for linux, 0GB for data disk 
- Bandwidth 5Mbps, you can compare the prices for 6Mbps separately:) 
- OS: CentOS6.3 64-bit security hardened version 
- Region: Hangzhou node 
- Unit price 171 yuan/month
 
 
Step 2 Install the server 1. Start the cloud server in the management console 2. Log in to the server with Putty 3. Update the software to the latest version: yum -y update 4. We will use the latest source code to build Node.js, and we need to install the software installation requires a set of development tools for compiling source code: yum -y groupinstall "Development Tools"  
 
 
 
 
 
 
 
 
 
5. Now you can start installing Node.js, first you need to enter the /usr/src folder, which is usually used to store software source code: cd /usr/src  
 
 
6. Get the latest compressed file source code from the Node.js site, the version is (v0.10.18) at the time of writing this article, the URL is: http://nodejs.org/download wget http://nodejs.org/ dist/v0.10.18/node-v0.10.18.tar.gz 7. Unzip the source file and enter the compressed folder. tar zxf node-v0.10.18.tar.gz cd node-v0.10.18  
 
 
 
 
 
 
 
8. Execute the configuration script for compilation preprocessing. ./configure 9. Start compiling the source code make 10. When the compilation is complete, we need to make it available system-wide, the compiled binary file will be placed in the system path, by default, the Node binary file should be placed in / make install under the user/local/bin/node folder  
 
 
 
 
 
 
 
 
 
 
11. Now that Node.js has been installed, start deploying the application immediately. First, use the Node.js module manager npm to install Express middleware and forever (a very useful module used to ensure that the application starts and restarts when needed ). npm -g install express forever  
 
 
12. For security reasons, it is best to create a regular system user and an unprivileged user running Node. You must first add a user. You can replace nodeadmin in the following command with your favorite name user add nodeadmin  
 
 
13. Once you have a new user, you need to assign a suitable password for the new user: passwd nodeadmin  
 
 
14. 修改sudo的设定:  
vi/etc/sudousers  
在最後一行加入  
nodeadmin ALL=(ALL:ALL) ALL  
 
15. 建立超级链接, 不然 sudo node 时会报 "command not found"  
sudo ln -s/usr/local/bin/node /usr/bin/node  
sudo ln -s/usr/local/lib/node /usr/lib/node  
sudo ln -s/usr/local/bin/npm /usr/bin/npm  
sudo ln -s/usr/local/bin/node-waf /usr/bin/node-waf  
sudo ln -s/usr/local/bin/forever /usr/bin/forever  
 
16. 现在已经完成安装服务器, 你可以把应用通过sftp上传到/home/nodeadm, 退出并使用新的用户登入系统, 启动你的应用  
sudo forever start server.js  
 
- 检视运行中的应用:  
sudo forever list  
 
- 关闭应用  
sudo forever stop 0  
 
    
用後总结:  
1. 真的很方便, 不用半天, 我的应用已经上线,如果再做一遍, 应该不用一小时。  
2. 真的便宜, 我的设置如下, 总价 $407/月
 
- 云服务器 x 2 (单核, 512MB内存,5Mbps带宽) = $342/月 
- 关系型数据库服务 RDS = $65/月 
- 负载均衡 SLB (开通, 免费) 
- 云盾 (开通, 免费) 
- 云监控(开通, 免费) 
- 内容分发网络 CDN (未开通) 
- 开放缓存服务 OCS (未开通)
 
3. 云服务器升级快捷, 可监控使用情况, 按需要升级  
4. 本人身在香港, 可能因为great firewall问题, 网络连线时快时慢, 但整体可以接受。  
5. 最後, 欢迎大家到访 http://www.wisone.com   

Guess you like

Origin blog.csdn.net/dongtinghong/article/details/78363360