1. 程式人生 > 實用技巧 >使用雲伺服器搭建nodejs開發環境

使用雲伺服器搭建nodejs開發環境

  1. 根據自己的需要申請一臺雲伺服器

    阿里雲 華為雲 等等

  2. 使用root賬號登入雲伺服器,新增新sudo組賬號nodejs

    #adduser nodejs

    #usermod -a -G sudo nodejs

    wKiom1PxxfzyhlNOAAC7g2Z7Qs0305.jpg

    Linux新增使用者(user)到使用者組(group)

    useradd 與adduser的區別

  3. windows下使用putty與nodejs賬號登入

    輸入公網IP

    wKioL1PxyBmBjOd5AAHhX9JbegQ796.jpg

  4. winscp sftp登入

    wKioL1PxyLfxAA2DAAO_YK0LvwM542.jpg

  5. 使用ssh登入

    Ubuntu下ssh-keygen生成的私鑰無法在windows的putty中使用,最好採用PuTTY Key Generator產生金鑰對;

    然後將公鑰複製到Ubuntu下 ~/.ssh/authorized_keys

    檔案中;

    Load前面登入時儲存的Session,在PuTTY->Connection->SSH->Auth載入前面產生的私鑰.ppk檔案,在Session中點選Save,然後Open

    wKioL1PxzcSj0ScPAAFgaofvJyE251.jpg

    注意公鑰複製到Linux伺服器中的檔名。

    在WinSCP中新增私鑰檔案,同樣可以不需要密碼以指定賬戶登入伺服器。

    wKioL1PxzoazLKK4AAG6GB7_OVQ847.jpg

  6. 安裝nodejs

    下載最新原始碼

    $ wget http://nodejs.org/dist/v0.10.30/node-v0.10.30.tar.gz

    安裝

    wKiom1Px0KCyd6sSAACoI4GwObM594.jpg

    經過測試知道,華為雲託管中申請的虛擬主機僅僅開放了80埠供web訪問,其他埠如9000等無法再瀏覽器端訪問;阿里雲不存在這個問題。

  7. 安裝MongoDB

Install MongoDB on Ubuntu

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

wKioL1Px2pyQ2_r2AADWaMudvqM378.jpg

8.使用MongoDB:

sudoservicemongodstart
sudoservicemongodstop
sudoservicemongodrestart

Getting Started with MongoDB

mongodb資料庫命令操作

$ 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