直裝mongodb複製集配置

mongod.conf

# for documentation of all options, see:

# http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.

systemLog:

destination: file

logAppend: true

path: /data/mongodb/log/mongod.log

# Where and how to store data.

storage:

dbPath: /data/mongodb/data

journal:

enabled: true

# engine:

# mmapv1:

# wiredTiger:

# how the process runs

processManagement:

fork: true # fork and run in background

pidFilePath: /data/mongodb/run/mongod.pid # location of pidfile

timeZoneInfo: /usr/share/zoneinfo

# network interfaces

net:

port: 27017

bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

setParameter:

enableLocalhostAuthBypass: false

#security:

# clusterAuthMode: keyFile

# keyFile: /data/mongodb/key/repl_set.key

# authorization: enabled

#operationProfiling:

replication:

replSetName: llRepSet

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

 

先啓動不帶參數 --auth

 

主庫配置集羣(3個節點,才能保證關閉一個節點後仍然能夠使用,因爲兩個節點才能保證選舉成功)

config = { _id: "llRepSet", members: [

{_id: 0, host: "192.168.0.83:27017"},

{_id: 1, host: "192.168.0.80:27017"},

{_id: 2, host: "192.168.0.80:37017"}]

}

rs.initiate(config)

rs.status();

以上命令只要在一臺服務器上運行即可

 

再設置賬號

use admin

db.createUser({user:'root',pwd:'********,roles:['root']})

db.auth('root','********')

再關掉主庫

db.shutdownServer()

再修改複製集配置

再啓動主庫帶參數 --auth

 

從庫1再關掉從庫

db.shutdownServer()

再啓動從庫1帶參數 --auth

 

從庫2再關掉從庫

db.shutdownServer()

再啓動從庫2帶參數 --auth

 

再創建數據庫

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章