在AWS Linux上安裝mongo-server

offical Tutorial

主要步驟:

  1. 創建文件/etc/yum.repos.d/mongodb-enterprise.repo。複製下面內容到文件中。
[mongodb-enterprise]
name=MongoDB Enterprise Repository
baseurl=https://repo.mongodb.com/yum/amazon/2013.03/mongodb-enterprise/3.4/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
  1. yum install
sudo yum install -y mongodb-enterprise
  1. Complete. Run service. 開始玩。
sudo service mongod start
  1. 注意,service mongo run時,使用的配置文件位置 /etc/mongod.conf

開啓AUTH

  1. 創建User
mongo
use admin
db.createUser(
  {
    user: "myUserAdmin",
    pwd: "abc123",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)
use test
db.createUser(
  {
    user: "myTester",
    pwd: "xyz123",
    roles: [ { role: "readWrite", db: "test" },
             { role: "read", db: "reporting" } ]
  }
)
  1. enable auth。打開配置文件 /etc/mongod.conf,加入配置(此處是yaml文件):
security:
  authorization: enabled
  1. 重啓mongo server
sudo service mongod restart
  1. 使用user/pwd,兩種方式
  • 連接時驗證
mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"
  • 連接後驗證
use admin
db.auth("myUserAdmin", "abc123" )

開啓遠程訪問

  1. 打開配置文件 /etc/mongod.conf,變更(此處是yaml文件):
net:
 - port: 27017
 - bindIp: 0.0.0.0
  1. 重啓mongo server
sudo service mongod restart
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章