Original works, allow reprint, please be sure to use hyperlinks in the form of the original source of the article, author information and this statement. Otherwise, the legal liability will be investigated. http://suifu.blog.51cto.com/9167728/1853478
Environment Introduction:
192.168.1.250 Main port=27408
192.168.1.250 arbitration port=27409
192.168.1.251 Preparation port=27408
[Email protected] ~]# tar xvf mongodb-linux-x86_64-2.6.10.tgz
[Email protected] ~]# mkdir-p/export/mongodb
[Email protected] ~]# mkdir-p/export/mongodb/bin
[Email protected] ~]# mkdir-p/export/mongodb/conf
[Email protected] ~]# mkdir-p/export/mongodb/log
[Email protected] ~]# mkdir-p/export/mongodb/data
[Email protected] bin]# Cd/root/mongodb-linux-x86_64-2.6.10/bin
[Email protected] bin]# cp/root/mongodb-linux-x86_64-2.6.10/bin/*/export/mongodb/bin/
[Email protected] bin]# vi/export/mongodb/conf/mongod.conf
1234567891011121314151617 |
port=27408
dbpath=
/export/mongodb/data
logpath=
/export/mongodb/log/mongod
.log
fork=
true
logappend=
true
keyFile=
/export/mongodb/key/mongod
nohttpinterface=
true
replSet=shard1
[[email protected] bin]
# vi /export/mongodb/conf/arbiter.conf
port=27409
dbpath=
/export/mongodb/arbiter
logpath=
/export/mongodb/log/arbiter
.log
fork=
true
logappend=
true
keyFile=
/export/mongodb/key/arbiter
nohttpinterface=
true
replSet=shard1
|
keyfile files include:
Mongod,arbiter
Create a script that generates keyfile
VI create_key.sh
12345 |
cat
/dev/urandom
| LC_ALL=C
tr
-
dc
"[:alnum:]" |
fold
-w 10 |
head
-1 >
/tmp/key
.txt
keystring=`
cat
/tmp/key
.txt`
echo
$keystring >
/export/mongodb/key/mongod
echo
$keystring >
/export/mongodb/key/arbiter
chmod
600
/export/mongodb/key/
*
|
Start the server in the main
[Email protected] ~]#/export/mongodb/bin/mongod-f/export/mongodb/conf/mongod.conf
[Email protected] ~]#/export/mongodb/bin/mongod-f/export/mongodb/conf/arbiter.conf
In from
[Email protected] ~]#/export/mongodb/bin/mongod-f/export/mongodb/conf/mongod.conf
>config={_id: ' Shard1 ', members:[{_id:0,host: ' 192.168.1.248:27408 '},{_id:1,host: ' 192.168.1.249:27408 '},{_id:2 , host: ' 192.168.1.248:27409 ', Arbiteronly:true}]}
>rs.initiate (config)
Initialize Rs.initiate (config), config is the name defined previously
When the master and standby library is configured, the standby library is queried.
1234567 |
shard1:SECONDARY> use test
switched
to
db test
shard1:SECONDARY> db.t1.find()
error: {
"$err"
:
"not master and slaveOk=false"
,
"code" : 13435 }
shard1:SECONDARY> rs.slaveOk()
shard1:SECONDARY> db.t1.find()
{
"_id"
: ObjectId(
"5704c11d3e0651733bfdea23"
),
"x"
: 1 }
|
Rs.stauts () can look at the state, Health:1 stands for health, statestr who is our arbitration
Want to downgrade the main library to from the Library, Rs.stepdown ()
This article is from the "Age volt" blog, please make sure to keep this source http://suifu.blog.51cto.com/9167728/1853478
MongoDB Replica set Environment construction