LoginSignup
26
26

More than 5 years have passed since last update.

CentOSにMongoDBをインストールして外部から接続できるようにする

Last updated at Posted at 2014-10-15

まぁ正確にはScientificLinuxなんですけど。

cat /etc/redhat-release
Scientific Linux release 6.5 (Carbon)

インストール

/etc/yum.repos.d/mongodb.repo
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
grpcheck=0
enabled=1
yum install mongodb

外部からの接続を許可する

/etc/mongodb.conf
# コメントアウト
#bind_ip=127.0.0.1 

# Webインターフェースを有効化
httpinterface=true
rest=true

ファイアウォール設定

ポート27017、28017からの接続を許可します。

iptables.sh
iptables -A INPUT -p tcp --dport 27017 -j ACCEPT
iptables -A INPUT -p tcp --dport 28017 -j ACCEPT

最後にサービス再起動

service mongod restart

手元のPCから接続確認。

mongo {サーバーのホスト名}:27017
>

OK!

同じく、サーバーの28017ポートにアクセスするとWebインターフェースが表示されます。

参考

mongodbでREST APIを使ってみる - RESTを有効にする、iptables変更、使ってみる、まで

26
26
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
26
26