### 開啟auth認證的mongodb的復制集
創(chuàng)新互聯(lián)公司專注于企業(yè)
網(wǎng)絡(luò)營銷推廣、網(wǎng)站重做改版、馬山網(wǎng)站定制設(shè)計、自適應品牌網(wǎng)站建設(shè)、
H5技術(shù)、
成都做商城網(wǎng)站、集團公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為馬山等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
### 注意點
-服務(wù)器節(jié)點之前時間要同步
-開啟防火墻的一定要允許通過
-開啟selinux的也要進行設(shè)置
-建立雙擊互信模式最好不過
### 提前要做的事情
[root@redis journal]# openssl rand -base64 753
3LC/EZGPOLXdVBQInqeKVglqNNWo2Et93ib51BQJZRAUB2gRUovi4b6ZkAeNAQxc
vu3UEOLWA9IyWvHy6g3rAQ8lAWqVX+dIJ52Lf5EKiUp9uTwqlzGd6FKgtheN6hNL
HV1YhwdzHLN7itmUgcTSe5qCSNJJijQh+OtKipkPH3laE+UxvC4rafPqNtzcBBjU
7P2GOAq7zyHqT68IBysNzcdribb9qVQ35Q+kFG3sB4ne26pgk2qjnUYAK2r42BLm
ec6VfKw0LnemJsSCB1d2M+5fLMvBe8w59lOL7/n8IHeeT4jiTmFhrWcgyTATK7D3
16Zbf8DJOkHobfnW7v0eUJINAS7BrVLjItSR51qQ4nqQAQpWd5DyNCsycDcNIzQj
u9pGO2OzBiroOlo/tz/tLjS8jPHaa7GamOI+L+OF1sn9ytpSq0T0BswItbaNIFjr
g97Nj6iwL86zblDY1U2380qBqKZdBP/yZdYi9Mj05328PdjPvF32vPt3wAHmkxTW
zHXMELO6AO4q4LxTPUbIGuLzbeGoLF/ZZia5ndXWzJxVaLNUxxdzrCtcoCXvfwXw
NXiN6Gg2Ep/IwkVZtNILtmbUZG51q45bb7afvS7p27P89WTk0TZ4rWNdnpNNJ1ry
Nwz8jMUFe9DdAY50KYUqYiIEDFltICYycnXwtmKYTpaun/6gXLKKp6PwHtfdid1t
v6dkv1FHB0fU0bReOBTTSfaFkwbdKcxHcLV2p6xiFdRKLMGDrgCQNXlJN0SaUUgP
U55DrScsWT3A6Pzx2Ga6yl/xnGaJpXBHb+g2gWFhSL64oo58KB4e1TQT5z/pkI0Y
Ow+GLv8m82K2epU7hpTB6ks0PZcalGlGPy4OBxu7tNQqJIY/pLa60Gtqbs5KBCIX
p7MV9JxCnOML68JU3ZKqlZUIkZeNSLpFXbnHNsuRtXWRuARdb3WM6BxsNS6uOfjA
/iYa0dsUtz5w8z6CQOEJ0bPo5GjpA95WSjXnwiCY8Hvf
[root@redis journal]#
[root@redis mongodb]# ll
total 72
drwxr-xr-x 2 mongodb mongodb 4096 Jul 19 12:58 bin
-rw-r--r-- 1 mongodb mongodb 34520 Jun 19 22:41 GNU-AGPL-3.0
-rw-r--r-- 1 root root 1020 Jul 21 08:26 key
-rw-r--r-- 1 mongodb mongodb 5 Jul 21 07:54 mongo.pid
-rw-r--r-- 1 mongodb mongodb 1359 Jun 19 22:41 README
-rw-r--r-- 1 mongodb mongodb 17793 Jun 19 22:41 THIRD-PARTY-NOTICES
[root@redis mongodb]# chmod 600 key
[root@redis mongodb]# ll
total 72
drwxr-xr-x 2 mongodb mongodb 4096 Jul 19 12:58 bin
-rw-r--r-- 1 mongodb mongodb 34520 Jun 19 22:41 GNU-AGPL-3.0
-rw------- 1
mongodb mongodb
1020 Jul 21 08:26 key
-rw-r--r-- 1 mongodb mongodb 5 Jul 21 07:54 mongo.pid
-rw-r--r-- 1 mongodb mongodb 1359 Jun 19 22:41 README
-rw-r--r-- 1 mongodb mongodb 17793 Jun 19 22:41 THIRD-PARTY-NOTICES
[root@redis mongodb]#
### 把key文件復制到另外一個節(jié)點上去
- 注意屬組屬主
- 創(chuàng)建一個全局賬戶
>
> show dbs
admin (empty)
local 1.078GB
test (empty)
> use admin
switched to db admin
> db.addUser("zhuima","zhuima")
WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
Successfully added user: { "user" : "zhuima", "roles" : [ "root" ] }
>
### 主服務(wù)器配置文件
[root@redis mongodb]# sed -e '/^$/d;/^#/d' /etc/mongod.conf
port=27017
dbpath=/mongo/data/mongodb_data/
logpath=/mongo/data/mongodb_log/mongodb.log
pidfilepath=/usr/local/mongodb/mongo.pid
fork=true
logappend=true
shardsvr=true
directoryperdb=true
replSet=zhuima
keyFile=/usr/local/mongodb/key
bind_ip=192.168.58.30
### 從服務(wù)器上配置文件
[root@mongo1 data]# vim /etc/mongod.conf
[root@mongo1 data]# sed -e '/^$/d;/^#/d' /etc/mongod.conf
logpath=/var/log/mongodb/mongod.log
logappend=true
fork=true
dbpath=/mongo/data
pidfilepath=/var/run/mongodb/mongod.pid
bind_ip=192.168.58.10
replSet = zhuima
keyFile = /mongo/data/key
### 重啟mongodb服務(wù)觀察結(jié)果
> rs.initiate()
zhuima:SECONDARY> show dbs
2014-07-21T08:52:44.617+0200 listDatabases failed:{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
"code" : 13
} at src/mongo/shell/mongo.js:47
zhuima:SECONDARY>
### 驗證信息
zhuima:PRIMARY> show dbs
admin 0.078GB
local 1.078GB
zhuima:PRIMARY> use zhuima
switched to db zhuima
zhuima:PRIMARY> info = {Name:"zhuima",Age:26,Gender:"F",Address:"Beijing China"}
{
"Name" : "zhuima",
"Age" : 26,
"Gender" : "F",
"Address" : "Beijing China"
}
zhuima:PRIMARY> db.person.insert(info)
WriteResult({ "nInserted" : 1 })
zhuima:PRIMARY> db.person.find()
{ "_id" : ObjectId("53ccb955f09dbb6f5a213faf"), "Name" : "zhuima", "Age" : 26, "Gender" : "F", "Address" : "Beijing China" }
zhuima:PRIMARY>
zhuima:SECONDARY> show dbs
admin 0.078GB
local 1.078GB
zhuima 0.078GB
zhuima:SECONDARY> use zhuima
switched to db zhuima
zhuima:SECONDARY> show collections
2014-07-21T08:55:40.267+0200 error: { "$err" : "not master and slaveOk=false", "code" : 13435 } at src/mongo/shell/query.js:131
zhuima:SECONDARY> rs.slaveOk()
zhuima:SECONDARY> rs.slaveOk()
zhuima:SECONDARY> show collections
person
system.indexes
zhuima:SECONDARY> db.person.find()
{ "_id" : ObjectId("53ccb955f09dbb6f5a213faf"), "Name" : "zhuima", "Age" : 26, "Gender" : "F", "Address" : "Beijing China" }
zhuima:SECONDARY>
### 關(guān)于mongodb 復制集 + auth的配置要感謝燦哥的指點
燦哥博客:http://www.shencan.net/
### 后記:
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
網(wǎng)站標題:mongodb之replSet復制集+auth-創(chuàng)新互聯(lián)
文章轉(zhuǎn)載:http://aaarwkj.com/article8/ccdhip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗、手機網(wǎng)站建設(shè)、網(wǎng)站營銷、網(wǎng)頁設(shè)計公司、企業(yè)網(wǎng)站制作、網(wǎng)站設(shè)計
廣告
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源:
創(chuàng)新互聯(lián)