使用本地的Ubuntu上的mongo-express来查看在EC2上的MongoDB
环境
<本地>
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
备战

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

以上