如何在Ubuntu上安裝Parse Server
Parse Server是一個開源的移動後端服務,自2013年起歸Facebook所有。該伺服器可以部署到任何可以執行Node.js和MongoDB的基礎設施上。本文介紹如何在Ubuntu上安裝Parse Server。
先決條件
- python-software-properties包
- Node.js
- MongoDB
要新增python-software-properties包,請使用以下命令:
$ sudo apt-get install build-essential git python-software-properties
示例輸出應如下所示:
Reading package lists... Done Building dependency tree Reading state information... Done build-essential is already the newest version (12.1ubuntu2). build-essential set to manually installed. The following packages were automatically installed and are no longer required: linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic linux-image-4.4.0-31-generic linux-image-extra-4.4.0-31-generic linux-signed-image-4.4.0-31-generic Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: git-man liberror-perl python-apt python-pycurl Suggested packages: git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-arch git-cvs git-mediawiki git-svn python-apt-dbg python-apt-doc libcurl4-gnutls-dev python-pycurl-dbg python-pycurl-doc ............................................................................
要安裝node指令碼,請使用以下命令:
$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
示例輸出應如下所示:
## Installing the NodeSource Node.js v6.x repo... ## Populating apt-get cache... + apt-get update Ign:1 http://dl.google.com/linux/chrome/deb stable InRelease Hit:2 http://dl.google.com/linux/chrome/deb stable Release Hit:3 http://in.archive.ubuntu.com/ubuntu xenial InRelease Get:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB] Get:5 http://ppa.launchpad.net/linuxgndu/sqlitebrowser-testing/ubuntu xenial InRelease [17.6 kB] Get:7 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB] Hit:8 http://archive.canonical.com/ubuntu xenial InRelease Hit:9 http://ppa.launchpad.net/webupd8team/sublime-text-2/ubuntu xenial InRelease Hit:10 http://archive.canonical.com xenial InRelease Hit:11 http://ppa.launchpad.net/webupd8team/sublime-text-3/ubuntu xenial InRelease Get:12 http://security.ubuntu.com/ubuntu xenial-security/main amd64 DEP-11 Metadata [68.3 kB] Get:13 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB] Get:14 http://security.ubuntu.com/ubuntu xenial-security/main DEP-11 64x64 Icons [39.2 kB] Get:15 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 DEP-11 Metadata [19.4 kB] Get:16 http://security.ubuntu.com/ubuntu xenial-security/universe DEP-11 64x64 Icons [25.6 kB] .............................................................................................
要安裝Node.js,請使用以下命令:
$ sudo apt-get install nodejs
示例輸出應如下所示:
Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic linux-image-4.4.0-31-generic linux-image-extra-4.4.0-31-generic linux-signed-image-4.4.0-31-generic Use 'sudo apt autoremove' to remove them. The following NEW packages will be installed: nodejs 0 upgraded, 1 newly installed, 0 to remove and 19 not upgraded. Need to get 10.1 MB of archives. After this operation, 50.8 MB of additional disk space will be used. Get:1 https://deb.nodesource.com/node_6.x xenial/main amd64 nodejs amd64 6.9.2-1nodesource1~xenial1 [10.1 MB] Fetched 10.1 MB in 7s (1,412 kB/s) Selecting previously unselected package nodejs. (Reading database ... 242052 files and directories currently installed.) Preparing to unpack .../nodejs_6.9.2-1nodesource1~xenial1_amd64.deb ... Unpacking nodejs (6.9.2-1nodesource1~xenial1) ... Processing triggers for man-db (2.7.5-1) ... Setting up nodejs (6.9.2-1nodesource1~xenial1) ...
要新增金鑰伺服器,請使用以下命令:
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
示例輸出應如下所示:
Executing: /tmp/tmp.IagxypDbAy/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 gpg: requesting key EA312927 from hkp server keyserver.ubuntu.com gpg: key EA312927: public key "MongoDB 3.2 Release Signing Key " imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1)
要新增MongoDB PPA,請使用以下命令:
$ echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb.list
現在更新已新增的包,請使用以下命令:
$ sudo apt-get update
要安裝MongoDB,請使用以下命令:
$ sudo apt-get install mongodb-org
示例輸出應如下所示:
Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic linux-image-4.4.0-31-generic linux-image-extra-4.4.0-31-generic linux-signed-image-4.4.0-31-generic Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools The following NEW packages will be installed: mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools 0 upgraded, 5 newly installed, 0 to remove and 19 not upgraded. .........................................................................................
下載和設定Parse Server
要下載Parse Server檔案,請使用以下命令:
$ sudo git clone https://github.com/ParsePlatform/parse-server-example.git
示例輸出應如下所示:
Cloning into 'parse-server-example'... remote: Counting objects: 312, done. remote: Total 312 (delta 0), reused 0 (delta 0), pack-reused 312 Receiving objects: 100% (312/312), 77.77 KiB | 0 bytes/s, done. Resolving deltas: 100% (144/144), done. Checking connectivity... done.
要進入parse-server-example目錄,請使用以下命令:
$ cd parse-server-example
使用`npm`安裝parse-server,如下所示:
/parse-server-example$ sudo npm install
示例輸出應如下所示:
parse-server-example@1.4.0 /opt/parse-server-example +-- express@4.11.2 | +-- accepts@1.2.13 | | +-- mime-types@2.1.13 | | | `-- mime-db@1.25.0 | | `-- negotiator@0.5.3 | +-- content-disposition@0.5.0 | +-- cookie@0.1.2 | +-- cookie-signature@1.0.5 | +-- debug@2.1.3 | | `-- ms@0.7.0 | +-- depd@1.0.1 | +-- escape-html@1.0.1 | +-- etag@1.5.1 | | `-- crc@3.2.1 | +-- finalhandler@0.3.3 | +-- fresh@0.2.4 | +-- media-typer@0.3.0 | +-- merge-descriptors@0.0.2 | +-- methods@1.1.2 | +-- on-finished@2.2.1 | | `-- ee-first@1.1.0 | +-- parseurl@1.3.1 | +-- path-to-regexp@0.1.3 ..............................................................................
現在開啟index.js檔案,新增APP_ID和MASTER_KEY,如下所示:
$ sudo nano index.js
使用任何隨機字串作為APP_ID和MASTER_KEY,如下所示:
var api = new ParseServer({ databaseURI: databaseUri || 'mongodb://:27017/dev', cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', appId: process.env.APP_ID || 'tutorialspointsample', masterKey: process.env.MASTER_KEY || 'samplecreatedbysairam', //Add your mast$ serverURL: process.env.SERVER_URL || 'https://:1337/parse', // Don't$ liveQuery: { classNames: ["Posts", "Comments"] // List of classes to support for query s$ } });
現在儲存並關閉檔案。要啟動Parse Server,請使用以下命令:
$ sudo npm start
示例輸出應如下所示:
> parse-server-example@1.4.0 start /opt/parse-server-example > node index.js DATABASE_URI not specified, falling back to localhost. parse-server-example running on port 1337. info: Parse LiveQuery Server starts running ....................................................................
在本文中,我們學習瞭如何在Ubuntu上安裝Parse Server。在我們的後續文章中,我們將分享更多基於Linux的技巧和提示。敬請關注!
廣告