LoginSignup
2
0

More than 5 years have passed since last update.

EC2上のMongoDBをローカルのubutnuのmongo-expressで眺める

Last updated at Posted at 2018-02-08

環境

<ローカル>
ubuntu 16.04
mongo-express@0.44.0

<EC2>
Ubuntu Server 16.04 LTS (HVM), SSD Volume Type - ami-79873901
MongoDB version v3.4.11

準備

AWSコンソールでEC2のsshのポートとmongodbのポートを開けておく
aws_setting.png
 
 
ローカルのubuntuのmongo-expressの設定を以下のように変更(一部抜粋)
※portは他で使っていないものならなんでもok。ここでは27027としたので以下もそうした前提で記述。
※usernameとpasswordはhogehogeと書きましたが、自分の環境に合わせて読み替えてください。
※dbとurlのdbname部分も自分の環境に合わせてください。

~/node_modules/mongo-express/config.js
  mongo = {
    // setting the connection string will only give access to that database
    // to see more databases you need to set mongodb.admin to true or add databases to the mongodb.auth list
    db:       'dbname',
    host:     '127.0.0.1',
    password: 'hogehoge',
    port:     27027,
    ssl:      false,
    url:      'mongodb://localhost/dbname',
    username: 'hogehoge',
    connectionString: process.env.ME_CONFIG_MONGODB_SERVER ? '' : process.env.ME_CONFIG_MONGODB_URL,
  };

手順

ローカルのubuntuの端末からssh接続(ポート転送)
※~/work/aws/MyKeyPair.pemは接続先のec2の認証キーが置いてあるpath
※-Lの後の27027は~/node_modules/mongo-express/config.jsで設定したport番号
※ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.coの部分はec2インスタンスのパブリックDNS

ubuntu@local$ sudo ssh -i ~/work/aws/MyKeyPair.pem -L 27027:127.0.0.1:27017 ubuntu@ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.co

ec2インスタンス上でmongodbが起動しているか確認

ubuntu@ec2$ mongo

 
ログインできればok
起動していなければ起動
MongoDBをsupervisorでプロセス監視する手順メモも参考にしてみてください。

ubuntu@ec2$ mongod

  
ローカルのubuntuでmongo-expressを起動

ubuntu@local$ cd ~/node_modules/mongo-express
ubuntu@local$ sudo node app.js

 
ローカルのubuntuからブラウザでhttp://localhost:8081に接続
mongo-express.png

以上

2
0
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
2
0