解析服务器是一个开放源代码,就像移动后端一样。自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 ............................................................................
要安装节点脚本,请使用以下命令–
$ 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. .........................................................................................
要下载解析服务器文件,请使用以下命令-
$ 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://localhost:27017/dev', cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', appId: process.env.APP_ID || 'nhooosample', masterKey: process.env.MASTER_KEY || 'samplecreatedbysairam', //Add your mast$ serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't$ liveQuery: { classNames: ["Posts", "Comments"] // List of classes to support for query s$ } });
现在保存并关闭文件。要启动解析服务器,请使用以下命令–
$ 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的技巧。继续阅读!。