LoginSignup
1
2

More than 5 years have passed since last update.

Linuxでparse-serverを立てる一連の流れ

Last updated at Posted at 2017-08-30

Ubuntu16.04の場合

nodeを入れる

#最新のnodeとnpmを入れる
sudo apt-get update -y
sudo apt-get install -y nodejs npm
sudo npm cache clean
sudo npm install n -g
sudo n stable
sudo apt-get purge -y nodejs npm
sudo npm update -g npm
sudo chown -R $USER:$(id -gn $USER) /home/ubuntu/.config

Parse関係を入れる

sudo npm install -g parse-server parse-dashboard

MongoDBを入れる

参考: https://docs.mongodb.com/master/tutorial/install-mongodb-on-ubuntu/
2017/06/22の時点で最新

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org

Amazon Linuxの場合

nvmを入れる

最新バージョンは https://github.com/creationix/nvm#installation を参照

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash

nodeを入れる

v8.1.2は2017/06/22の時点で最新

nvm install v8.1.2

Parse関係を入れる

npm install -g parse-server parse-dashboard

MongoDBを入れる

参考: https://docs.mongodb.com/master/tutorial/install-mongodb-on-amazon/#configure-the-package-management-system-yum

2017/08/31の時点で最新
変更するならバージョン番号あたりを

sudo sh -c "echo '[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc' > /etc/yum.repos.d/mongodb-org-3.4.repo"

sudo yum install -y mongodb-org

MongoDBとりあえず起動確認してみる

serviceで起動させる場合には 777 にしておく必要がある

mkdir -m 777 -p /media/volume0/mongodb/log
mkdir -m 777 -p /media/volume0/mongodb/db
mongod --config mongod.conf

mongod.conf

公式を参考にYAMLで書く
デフォルトでは/etc/mongod.confを読みに行くので書き換える

storage:
    dbPath: /media/volume0/mongodb/db
    journal:
    enabled: true
    engine: "wiredTiger"
    wiredTiger:
    engineConfig:
        directoryForIndexes: true
        cacheSizeGB: 1
processManagement:
   fork: true
net:
    port: 27017
    bindIp: 127.0.0.1

systemLog:
    destination: file
    path: /media/volume0/mongodb/log/mongodb.log
    logAppend: true

mongodをserviceで起動する

sudo service mongod start

自動起動

Ubuntu16.04の場合

sudo systemctl enable mongod.service 

マシンを再起動したら起動しなくなる場合がある

/data/dbが無いとか言われる場合があり、その場合は mongod -f /etcmongod.conf

Amazon Linuxの場合

sudo ntsysvで確認できるように、勝手に自動起動するようになっている?

Volumeをマウント

Ubuntu16.04の場合

ext4でフォーマットしてマウントして所有者変更

sudo mkdir -m 775 -p media/volume0 #好きなmount場所
sudo chown ubuntu /media/volume0/
sudo mkfs.ext4 /dev/vdc #vdcは場合による
sudo mount /dev/vdc /media/volume0/

自動マウント

sudo blkid /dev/vdcで取得したUUIDを/etc/fstabに追記

UUID=<YOUR_UUID>       /media/volume0  ext4    user_xattr      0       1

parse-serverとparse-dashboardの起動

この記事を参考にする。Parse Serverの死活管理と設定変更したらすぐ自動で反映されるようにする

apache2でリバースプロキシ

/etc/apache2/conf-enabled/*.confの例

ProxyPass        /parse http://localhost:4040/parse
ProxyPassReverse /parse http://localhost:4040/parse
ProxyRequests    off

ProxyPass        /your_parse_mountPath http://localhost:1340/your_parse_mountPath
ProxyPassReverse /your_parse_mountPath http://localhost:1340/your_parse_mountPath
ProxyRequests    off

localhost:4040はparse-dashboard
localhost:1340はparse-server

/parseはparse-dashboardのパラメータが --mountPath /parse だったのでそれに合わせている。
すると、http://localhost:4040/parse/apps でdashboardにアクセスできる。

Amazon Linuxの場合

sudo yum install httpd
sudo service httpd start
sudo chkconfig httpd on

chkconfig --list httpdで確認
実行レベル2、3、4、5でonなら良い
参考: チュートリアル: Amazon Linux への LAMP ウェブサーバーのインストール

設定ファイルは
/etc/httpd/conf.d/YOUR.conf

restartはこれ
sudo /etc/init.d/httpd restart

Ubuntu16.04の場合

sudo apt-get install apache2

自動起動は勝手になってる?

設定ファイルは
/etc/apache2/conf-enabled/YOUR.conf

restartはこれ
sudo /etc/init.d/apache2 restart

tips

VSCodeでサーバ上のファイルを編集したい

ext install remote-vscodeをインストールして、>Remote: Start Serverしておく
remote-vscode

.ssh/configを

Host parse
     hostname xxx.xxx.xxx.xxx
     user your_user
     ForwardAgent yes
     RemoteForward 52698 localhost:52698

サーバ側にrmateを入れる

sudo wget -O /usr/local/bin/rmate https://raw.github.com/aurora/rmate/master/rmate
sudo chmod a+x /usr/local/bin/rmate

rmate hogehoge.txtでvscodeが起動する

sudoするときにsudo: unable to resolve hostが出たら

sudo sh -c 'echo 127.0.1.1 $(hostname) >> /etc/hosts'
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2