使用云服务器搭建nodejs开发环境
-
根据自己的需要申请一台云服务器
-
使用root账号登录云服务器,添加新sudo组账号nodejs
#adduser nodejs
#usermod -a -G sudo nodejs
-
windows下使用putty与nodejs账号登录
输入公网IP
-
winscp sftp登录
-
使用ssh登录
Ubuntu下ssh-******生成的私钥无法在windows的putty中使用,最好采用PuTTY Key Generator产生**对;
然后将公钥复制到Ubuntu下 ~/.ssh/authorized_keys 文件中;
Load前面登录时保存的Session,在PuTTY->Connection->SSH->Auth载入前面产生的私钥.ppk文件,在Session中点击Save,然后Open
注意公钥复制到Linux服务器中的文件名。
在WinSCP中添加私钥文件,同样可以不需要密码以指定账户登录服务器。
-
安装nodejs
下载最新源码
$ wget http://nodejs.org/dist/v0.10.30/node-v0.10.30.tar.gz
经过测试知道,华为云托管中申请的虚拟主机仅仅开放了80端口供web访问,其他端口如9000等无法再浏览器端访问;阿里云不存在这个问题。
安装MongoDB
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list sudo apt-get update sudo apt-get install mongodb-org
8.使用MongoDB:
sudo service mongod start sudo service mongod stop sudo service mongod restart
$ mongo
MongoDB shell version: 2.6.3
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
> db
test
> use mydb
switched to db mydb
> j = { name : "mongo" }
{ "name" : "mongo" }
> k = { x : 3 }
{ "x" : 3 }
> db.testData.insert(j)
WriteResult({ "nInserted" : 1 })
> db.testData.insert(k)
WriteResult({ "nInserted" : 1 })
> show collections
system.indexes
testData
> db.testData.find()
{ "_id" : ObjectId("53e2d30731135599384021cd"), "name" : "mongo" }
{ "_id" : ObjectId("53e2d31231135599384021ce"), "x" : 3 }
> var c = db.testData.find()
> while ( c.hasNext() ) printjson( c.next())
{ "_id" : ObjectId("53e2d30731135599384021cd"), "name" : "mongo" }
{ "_id" : ObjectId("53e2d31231135599384021ce"), "x" : 3 }
{ "_id" : ObjectId("53e2d48a31135599384021cf"), "x" : 1 }
{ "_id" : ObjectId("53e2d48a31135599384021d0"), "x" : 2 }
...
> var c = db.testData.find()
> printjson( c [ 4] )
{ "_id" : ObjectId("53e2d48a31135599384021d1"), "x" : 3 }
转载于:https://blog.51cto.com/xjhznick/1541711