使用雲伺服器搭建nodejs開發環境
根據自己的需要申請一臺雲伺服器
使用root賬號登入雲伺服器,新增新sudo組賬號nodejs
#adduser nodejs
#usermod -a -G sudo nodejs
windows下使用putty與nodejs賬號登入
輸入公網IP
winscp sftp登入
使用ssh登入
Ubuntu下ssh-keygen生成的私鑰無法在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
sudoapt-keyadv--keyserverhkp://keyserver.ubuntu.com:80--recv7F0CEB10 echo'debhttp://downloads-distro.mongodb.org/repo/ubuntu-upstartdist10gen'|sudotee/etc/apt/sources.list.d/mongodb.list sudoapt-getupdate sudoapt-getinstallmongodb-org
8.使用MongoDB:
sudoservicemongodstart sudoservicemongodstop sudoservicemongodrestart
$ 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