3.14.23-22.44.amzn1.x86_64(ID_LIKE="rhel fedora")
|-- nodejs 0.10.33,npm
| |-- mongodb_s3_backup
| \-- forever
\-- mongodb-linux-x86_64-enterprise-amzn64-2.6.6
參考:http://docs.mongodb.org/manual/tutorial/install-mongodb-enterprise-on-amazon
必要程式安裝:
sudo yum install openssl net-snmp net-snmp-libs net-snmp-utils cyrus-sasl cyrus-sasl-lib cyrus-sasl-devel cyrus-sasl-gssapi
下載及安裝mongodb:
curl -O http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-amzn64-2.6.6.tgz
tar -zxvf mongodb-linux-x86_64-enterprise-amzn64-2.6.6.tgz
sudo cp -R -n mongodb-linux-x86_64-enterprise-amzn64-2.6.6/ /usr/local/mongodb
設定環境變數:
vim .bashrc
開啟環境變數檔export PATH=$PATH:/usr/local/mongodb/bin
加入mongodbsource .bashrc
重新載入環境變數檔建立mongod.conf設定檔:
sudo mkdir /etc/mongodb
建立資料夾sudo vim /etc/mongodb/mongodb.conf
建立設定檔 # mongod.conf
#where to log
logpath=/var/log/mongodb/mongod.log
logappend=true
# fork and run in background
fork=true
port=27017
dbpath=/db
# location of pidfile
pidfilepath=/var/run/mongodb/mongod.pid
# Listen to local interface only. Comment out to listen on all interfaces.
#bind_ip=0.0.0.0
#bind_ip=127.0.0.1
# Disables write-ahead journaling
# nojournal=true
# Enables periodic logging of CPU utilization and I/O wait
#cpu=true
# Turn on/off security. Off is currently the default
#noauth=true
#auth=true
# Verbose logging output.
#verbose=true
# Inspect all client data for validity on receipt (useful for
# developing drivers)
#objcheck=true
# Enable db quota management
#quota=true
# Set oplogging level where n is
# 0=off (default)
# 1=W
# 2=R
# 3=both
# 7=W+some reads
#diaglog=0
# Ignore query hints
#nohints=true
# Enable the HTTP interface (Defaults to port 28017).
#httpinterface=true
# Turns off server-side scripting. This will result in greatly limited
# functionality
#noscripting=true
# Turns off table scans. Any query that would do a table scan fails.
#notablescan=true
# Disable data file preallocation.
#noprealloc=true
# Specify .ns file size for new databases.
# nssize=<size>
# Replication Options
# in replicated mongo databases, specify the replica set name here
#replSet=setname
# maximum size in megabytes for replication operation log
#oplogSize=1024
# path to a key file storing authentication info for connections
# between replica set members
#keyFile=/path/to/keyfile
dbpath=/db
指定資料庫儲存位置#bind_ip=127.0.0.1
取消IP限制,否則只有localhost連得到#auth=true
不啟用帳號管理sudo mkdir /var/run/mongodb
sudo chown ec2-user /var/run/mongodb
sudo mkdir /var/log/mongodb
sudo chown ec2-user /var/log/mongodb
sudo mkdir /db
sudo chown ec2-user /db
/db對應dbpath路徑mongod --config /etc/mongodb/mongodb.conf
使用設定檔設定啟動資料庫(初次啟動執行較久)mongodb測試:
netstat -ndlp |grep 27017
檢視PORT開啟參考:
建立管理者帳號:
mongo
進入資料庫use admin
db.createUser( { user: "superuser", pwd: "passwd", roles: ["root"] } )
新增最高權限用戶ctrl+c
離開關閉資料庫:
mongod --config /etc/mongodb/mongodb.conf --shutdown
停止資料庫mongo
進入資料庫use admin
切換至admin dbdb.shutdownServer()
關閉資料庫ctrl+c
離開測試管理者帳號:
mongod -–auth
驗證模式啟動資料庫(未啟用帳號管理啟動的資料庫,不會進行任何帳號驗證,任何人都可以登進去!!!)mongo -u username -p passwd --authenticationDatabase admin
使用帳號密碼進入資料庫use admin
切換至admin dbdb.shutdownServer()
關閉資料庫ctrl+c
離開啟用帳號管理:
sudo vim /etc/mongodb/mongodb.conf
開啟設定檔 #auth=true
>>auth=true
啟用帳號管理mongod --config /etc/mongodb/mongodb.conf
啟動資料庫為application建立專用帳號:
mongo -u username -p passwd --authenticationDatabase admin
use admin
db.createUser( { user: "application_user", pwd: "passwd", roles: [ { role: "dbAdmin", db: "applicationDB" }, { role: "readWrite", db: "applicationDB" } ] } )
use applicationDB
切換資料庫db.createUser( { user: "application_user", pwd: "passwd", roles: [ { role: "dbAdmin", db: "applicationDB" }, { role: "readWrite", db: "applicationDB" } ] } )
sudo vim /etc/rc.d/rc.local
mongod --config /etc/mongodb/mongodb.conf