Centos系统搭建Parse Server后端系统,准备工作

前言

什么是Parse Server
  1. Parse是一个移动后端,最初由提供商Parse Inc开发。该公司于2013年被Facebook收购,并于2017年1月关闭。继2016年宣布即将关闭后,该平台随后开源。 由于托管服务被关闭,Parse Platform已经发展成为一个开源社区,拥有自己的博客,文档和社区论坛。 
  2. Parse是一个基于云端的后端管理平台。对于开发者而言,Parse提供后端的一站式和一揽子服务:服务器配置、数据库管理、API、影音文件存储,实时消息推送、客户数据分析统计、等等。这样,开发者只需要处理好前端/客户端/手机端的开发,将后端放心的交给Parse即可。目前Parse支持超过50万个App。 
  3. Parse可以让一个作为Android/IOS开发的你,不用后台开发人员配合就可以处理后台数据,并且其有专门的用户系统,消息推送功功能等等,而且API简单易用,虽然坑还是有,但是还是一个很值得Android开发者入手的一个框架。
想详细了解的可以在:https://www.jianshu.com/p/d92c5b2380ea 

官网:https://parseplatform.org/

Github:https://github.com/parse-community

搭建准备

首相你得配置好Parse Server环境

如果你是宝塔搭建可以选择在:软件商店 > 运行环境,找到 PM2管理器 和 MongoDB

默认选择最新版本就像,MongoDB 你可以新建一个“Parse”的数据库

不是宝塔那么就需要安装:nodejsMongoDB,其实和宝塔差不多,都是环境,还需要git环境

准备好之后就可以开始了

环境安装

Nodejs安装

下载

wget https://npm.taobao.org/mirrors/node/v12.4.0/node-v12.4.0-linux-x64.tar.xz

解压

tar -xvf node-v12.4.0-linux-x64.tar.xz

进入bin目录,执行ls命令

cd node-v12.4.0-linux-x64/bin && ls
./node -v

显示:v12.4.0,就安装成功了

全局使用

ln -s /www/node-v12.4.0-linux-x64/bin/node /usr/local/bin/node
    
ln -s /node-v12.4.0-linux-x64/bin/npm /usr/local/bin/npm

这样就可以在任何目录下执行 node 和 npm 命令。

Mongodb安装

下载

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.0.tgz

解压

tar -zxvf  mongodb-linux-x86_64-4.0.0.tgz

移动到 /usr/local 下

mv mongodb-linux-x86_64-4.0.0  ../mongodb

创建数据、日志文件夹:

cd /usr/local/mongodb
mkdir db
mkdir  logs
touch logs/mongodb.log

创建配置文件

cd /usr/local/mongodb
touch mongodb.conf

配置配置文件

cd /usr/local/mongodb
vim mongodb.conf

添加以下内容

port=27017  #端口

bind_ip=0.0.0.0 #默认是127.0.0.1

dbpath=/usr/local/mongodb/db  #数据库存放

logpath=/usr/local/mongodb/logs/mongodb.log #日志文件

fork=true #设置后台运行

#auth=true #开启认证

运行

/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongodb.conf

开机自启动

vim /etc/rc.d/rc.local
/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongodb.conf

以上准备完毕,环境这方便比较苛刻。以上都是来自网络,教程如有错误请指正。

Parse安装

安装Parse Server

npm install -g parse-server

安装Parse管理面板

npm install -g parse-dashboard

进入parse-server目录检查,

有没有cloud文件夹,没有创建一个

然后进入改文件夹创建main.js文件,写入如下

Parse.Cloud.define("sayHelloWorld", async (request) => {
  return "hi!";
});

如果有 index.js 则修改,没有就创建一个

检查有没有cloud文件夹,没有创建一个

写入如下

// compatible API routes.
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
var ParseDashboard = require('parse-dashboard');
 
 
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
 
if (!databaseUri) {
  console.log('DATABASE_URI not specified, falling back to localhost.');
}
 
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 || 'myAppId',
  masterKey: process.env.MASTER_KEY || 'myMasterKey', //Add your master key here. Keep it secret!
  serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',  // Don't forget to change to https if needed
  liveQuery: {
    classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
  }
});
// Client-keys like the jаvascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// jаvascriptKey, restAPIKey, dotNetKey, clientKey
 
 
var dashboard = new ParseDashboard({
    "apps": [
        {
            "serverURL": "http://localhost:1337/parse",
            "appId": "myAppId",
            "masterKey": "myMasterKey",
            "appName": "MyApp"
        }
    ],
    "users": [
        {
            "user": "user1",
            "pass": "pass"
        }
    ]
});
 
var app = express();
 
// make the Parse Dashboard available at /dashboard
app.use('/dashboard', dashboard);
 
// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));
 
// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
 
// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
  res.status(200).send('I dream of being a website.  Please star the parse-server repo on GitHub!');
});
 
// There will be a test page available on the /test path of your server url
// Remove this before launching your app
app.get('/test', function(req, res) {
  res.sendFile(path.join(__dirname, '/public/test.html'));
});
 
var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
    console.log('parse-server-example running on port ' + port + '.');
});
 
// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);

执行

node index.js

成功之后,可以试试 npm start,浏览器里输入http://localhost:1337/ 页面上输出 I dream of being a website. Please star the parse-server repo on GitHub! 则表示成功了 (如果没有请检查端口是否开启)

然后浏览器输入:服务器ip:1337/dashboard

如果面板没有设置 https 可能会进不去需要修改 var dashboard = new ParseDashboard 函数

var dashboard = new ParseDashboard({
    //

}, {"allowInsecureHTTP": true});

即可进入管理界面

如果你对此教程还是不会安装,随后我会发布更简单的安装方式,尽情期待!

News article is edited by: Caesar - 2020-09-9, 15:09
Reason: Parse Dashboard 的安装命令修改,解决http不能进入面板

文章作者: Caesar
文章链接: https://pcnto.com/daily-learning/8-centos-system-building-parse-server.html
版权声明: 本博客所有文章除特别声明外,转载请注明来自 Peng blog

如果您喜欢本站,你可以点击主页广告以示支持,谢谢。

广告是本站收益的来源希望您能够谅解。