Parse Server(含Dashboard)部署於Centos7.6 64位

1、安裝配置Nginx

1.1安裝編譯工具及庫文件

yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
複製代碼

1.2安裝 PCRE

PCRE 做用是讓 Ngnix 支持 Rewrite 功能 
javascript

一、下載PCRE安裝包html

cd /usr/local/src複製代碼

wget https://sourceforge.net/projects/pcre/files/pcre/8.43/pcre-8.43.tar.gz/複製代碼

如若提示沒有wget,則先安裝wgetjava

yum -y install wget複製代碼

二、解壓安裝包node

tar zxvf pcre-8.43.tar.gz複製代碼

注意將文件名替換成你下載下來的安裝包的文件名linux

三、進入安裝包目錄nginx

cd perc-8.43複製代碼

四、編譯安裝c++

./configure 複製代碼

make && make install複製代碼

五、查看PCRE版本git

pcre-config –version複製代碼

1.3安裝nginx

一、下載Nginxgithub

cd /usr/local/src 複製代碼

wget http://nginx.org/download/nginx-1.15.9.tar.gz 複製代碼

二、解壓安裝包web

tar zxvf nginx-1.15.9.tar.gz 複製代碼

三、進入安裝包目錄

cd nginx-1.15.9複製代碼

四、編譯安裝

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.43複製代碼

make && make install複製代碼

五、查看nginx版本

/usr/local/nginx/sbin/nginx -v複製代碼

六、啓動nginx

/usr/local/nginx/sbin/nginx複製代碼

七、nginx其餘命令

/usr/local/nginx/sbin/nginx -s reload     # 從新載入配置文件 
/usr/local/nginx/sbin/nginx -s reopen    # 重啓 Nginx /usr/local/nginx/sbin/nginx -s stop # 中止 Nginx
複製代碼

2、安裝MongoDB

2.1安裝Vim及其依賴

yum install -y vim*複製代碼

2.2.進入網址

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/複製代碼

2.3建立文件

vim /etc/yum.repos.d/mongodb-org-4.0.repo複製代碼

2.4.在mongodb-org-4.0.repo中鍵入如下內容

[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc複製代碼

2.5.安裝配置

yum install -y mongodb-org複製代碼

2.6.修改配置文件

vim /etc/mongod.conf複製代碼

將net:bindIp: 127.0.0.1 改成 0.0.0.0

2.7.開放27017端口

1.SElinux

semanage port -a -t mongod_port_t -p tcp 27017複製代碼

2.防火牆(先打開防火牆,而後打開27017端口,最後從新載入配置)

systemctl start firewalld複製代碼
firewall-cmd --zone=public --add-port=27017/tcp --permanent複製代碼

firewall-cmd --reload複製代碼

2.8開啓服務 mongod

service mongod start
#或者
systemctl start mongod複製代碼

關閉 service mongod stop 或者 systemctl stop mongod

重啓 service mongod restart 或者 systemctl restart mongod

2.9開機自啓動

chkconfig mongod on
#或者
systemctl ennable mongod複製代碼

2.10啓動客戶端

mongo --host 127.0.0.1:27017複製代碼

3、配置MongoDB

3.1建立一個root用戶,並賦予超級管理員權限(root);超級管理員能夠管理MongoDB下的全部庫以及權限、備份及集羣等操做。

mongo --host 127.0.0.1:27017
use admin
db.createUser({user:"root",pwd:"root_password",roles:["root"]})複製代碼

這裏的root_password改爲你本身想要的密碼,最好設置的難一點

3.2爲admin庫建立一個admin用戶,並賦予管理員權限。

use admin
db.createUser({user:"admin",pwd:"admin_password",roles:[{role:"userAdminAnyDatabase",db:"admin"}]})複製代碼

一樣,這裏的admin_password也改爲你本身的密碼

3.3新建一個數據庫foo,給這個庫添加一個用戶admin,並賦予讀寫及管理員權限。

use foo
db.createUser({user:"admin", pwd:"admin_password", roles:["readWrite", "dbAdmin"]})
複製代碼

foo能夠改爲任何你本身想要的數據庫名

3.4認證建立的用戶,此步驟很是重要。認證完成以後,退出shell。

db.auth('admin', 'admin_password')
1 # 1 - 表示認證成功,0 - 表示失敗
exit
bye複製代碼

4、下載安裝最新版的Nodejs與npm

4.1在CentOS 7中安裝Node.js 10 LTS的方法,使用NodeSource方式:

curl -sL https://rpm.nodesource.com/setup_10.x | bash -複製代碼

上面命令將配置Node.js RPM存儲庫

4.2下面你須要作的就是安裝nodejs包:

sudo yum clean all && sudo yum makecache fastsudo yum install -y gcc-c++ makesudo yum install -y nodejs複製代碼

4.3經過以上命令安裝的Node.js的版本爲v10.13.0,運行如下命令查驗:

node -v複製代碼

4.4設置鏡像源爲淘寶鏡像

npm config set registry https://registry.npm.taobao.org複製代碼

4.5查看鏡像源

npm config get registry複製代碼

5、安裝最新版git,wget組件

5.1什麼是EPEL 及 Centos上安裝EPEL

什麼是EPEL 及 Centos上安裝EPEL

RHEL以及他的衍生髮行版如CentOS、Scientific Linux爲了穩定,官方的rpm repository提供的rpm包每每是很滯後的,固然了,這樣作這是無可厚非的,畢竟這是服務器版本,安全穩定是重點,官方的rpm repository提供的rpm包也不夠豐富,不少時候須要本身編譯那太辛苦了,而EPEL偏偏能夠解決這兩方面的問題。

5.2在CentOS 7 使用IUS第三方源安裝git2

先輸入git --version查看是否已經安裝了git,若是已經安裝了就先yum remove git 再執行下面的步驟

curl https://setup.ius.io | sh
yum install -y git2u
git --version複製代碼

5.3安裝wget

yum install -y wget複製代碼

6、安裝parse-server

6.1進入opt目錄下

cd opt/複製代碼

我我的喜歡把軟件安裝到這個目錄,你要是不喜歡就跳下一步

6.2從GitHub下載源碼

git clone https://github.com/ParsePlatform/parse-server-example.git複製代碼

6.3進入項目文件夾並修改配置文件

cd parse-server-example/
vim index.js複製代碼

6.4編輯index.js(經整合的index.js的文件內容以下)

// Example express application adding the parse-server module to expose Parse
// compatible API routes.

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var ParseDashboard = require('parse-dashboard');
var path = require('path');

var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;

//Parse服務的域名
var parseDomain = process.env.PARSE_DOMAIN;

if (!databaseUri) {
  console.log('DATABASE_URI not specified, falling back to localhost.');
}

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/meetwish',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'myAppId',
  masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
  serverURL: `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 } }); var dashboard = new ParseDashboard({ 'apps': [ { 'serverURL': `https://${parseDomain}/parse`, 'appId': process.env.APP_ID || 'myAppId', 'masterKey': process.env.MASTER_KEY || '', 'appName': 'meetwish' } ], 'users': [ { 'user': process.env.USER_NAME || 'username', 'pass': process.env.PASSWORD || 'password' } ] }, false); // Client-keys like the javascript 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: // javascriptKey, restAPIKey, dotNetKey, clientKey var app = express(); // Serve static assets from the /public folder app.use('/public', express.static(path.join(__dirname, '/public'))); // make the Parse Dashboard available at /dashboard app.use('/dashboard', dashboard); // 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 running on port ' + port + '.'); }); // This will enable the Live Query real-time server ParseServer.createLiveQueryServer(httpServer); 複製代碼

啓動時需指定APP_ID,MASTER_KEY,USER_NAME,PASSWORD,PARSE_DOMAIN等環境變量。

  • APP_ID:應用的ID,全部的接口中都會用到該參數
  • MASTER_KEY:應用的密鑰,需妥善保管,避免泄露,經過該key能夠忽略全部的訪問權限控制。
  • USER_NAME:訪問Dashboard的用戶名
  • PASSWORD:訪問Dashboard的密碼
  • PARSE_DOMAIN:部署Parse Server的域名或公網IP

6.5進入package.json中,添加parse-dashboard的依賴,版本本身去npm看

"parse-dashboard":"*"複製代碼

6.6退出vim,開始安裝依賴

npm install
npm audit fix #提示修復就修復一下,不提示就無論了複製代碼

6.7而後安裝mongodb的啓動組件

npm install -g mongodb-runner複製代碼

6.8啓動項目

node index.js複製代碼

7、配置nginx反向代理Parse Server及Parse Dashboard

7.1配置nginx.conf文件

假設Parse Server服務器的域名是:api.example.com

新版的nginx語法有些不同

server {
    listen 443;
    server_name api.example.com;
    ssl on;
    ssl_certificate  cert/312431314412324.pem;
    ssl_certificate_key cert/312431314412324.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    location / {
        proxy_pass http://127.0.0.1:1337;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
複製代碼

7.2修改完配置之後,重啓nginx

service nginx restart複製代碼

8、開放服務端口

8.1開放80、44三、133七、4040、27017端口

firewall-cmd --add-port=80/tcp --permanent
複製代碼

firewall-cmd --add-port=443/tcp --permanent複製代碼

firewall-cmd --add-port=1337/tcp --permanent複製代碼

firewall-cmd --add-port=4040/tcp --permanent複製代碼

firewall-cmd --add-port=27017/tcp --permanent複製代碼

這步要是不作,你只能從localhost訪問,以前我就被坑了,總之你最後只要保證服務運行且能在遠程端口訪問到就OK了

1.查看已打開的端口  # netstat -anp
2.查看想開的端口是否已開 # firewall-cmd --query-port=4040/tcp
  若此提示 FirewallD is not running 
  表示爲不可知的防火牆 須要查看狀態並開啓防火牆

3. 查看防火牆狀態  # systemctl status firewalld
 running 狀態即防火牆已經開啓
 dead 狀態即防火牆未開啓
4. 開啓防火牆,# systemctl start firewalld 沒有任何提示即開啓成功
5. 開啓防火牆 # service firewalld start 
   關閉防火牆 # systemctl stop firewalld
   centos7.3 上述方式可能沒法開啓,能夠先#systemctl unmask firewalld.service 而後 # systemctl start firewalld.service

6. 查看想開的端口是否已開 # firewall-cmd --query-port=4040/tcp 提示no表示未開
7. 開永久端口號 firewall-cmd --add-port=4040/tcp --permanent   提示    success 表示成功
8. 從新載入配置  # firewall-cmd --reload 好比添加規則以後,須要執行此命令
9. 再次查看想開的端口是否已開  # firewall-cmd --query-port=4040/tcp 提示yes表示成功
10. 若移除端口 # firewall-cmd --permanent --remove-port=4040/tcp複製代碼
相關文章
相關標籤/搜索