Installing the mongodb Cluster

1. Prepare the deployment installation package

(Place all packages in /usr/local/page, pape is a self-named directory.)

Mongo – Linux – x86_64 – rule 3.4.3. TGZ

2. The installation starts

1. Execute this script on each machine

cd /usr/local/page

Tar – ZXVF mongo – Linux – x86_64 – rule 3.4.3. TGZ

Mv mongo – Linux – x86_64 – rule 3.4.3 / usr/local/mongo

mkdir -p /hxdata/mongodb/data

mkdir -p /hxdata/mongodb/log

2. Start three machines without keys

/usr/local/mongodb/bin/mongod \

–dbpath=/hxdata/mongodb/data \

–logpath=/hxdata/mongodb/log/server.log \

–logappend \

–fork \

–port=12700 \

– bind_ip = 192.168.191 \

–replSet=hxrs

/usr/local/mongodb/bin/mongod \

–dbpath=/hxdata/mongodb/data \

–logpath=/hxdata/mongodb/log/server.log \

–logappend \

–fork \

–port=12700 \

– bind_ip = 192.168.192 \

–replSet=hxrs

/usr/local/mongodb/bin/mongod \

–dbpath=/hxdata/mongodb/data \

–logpath=/hxdata/mongodb/log/server.log \

–logappend \

–fork \

–port=12700 \

– bind_ip = 192.168.193 \

–replSet=hxrs

3. Select one of them and go to the console to create users and clusters

/ usr/local/mongo/bin/mongo 192.168.1.191:12700

use admin

CFG = {_id: “HXRS members: [{_id: 0, host: ‘192.168.1.191:12700}, {_id: 1, host:’ 192.168.1.192:12700}, {_id: 2. Host: ‘192.168.1.193:12700, arbiterOnly: true}}]

rs.initiate(cfg)

rs.status()

use admin

db.createUser({user:”root”,pwd:”123456″,roles:[“root”]})

db.auth(“root”,”123456″)

exit

4. Select one machine to produce the key and copy it to the corresponding directory of other machines

openssl rand -base64 741 > /usr/local/mongodb/bin/mongo-keyfile

Five, start three machines, with key form

/usr/local/mongodb/bin/mongod \

–dbpath=/hxdata/mongodb/data \

–logpath=/hxdata/mongodb/log/server.log \

–logappend \

–fork \

–port=12700 \

– bind_ip = 192.168.1.191 \

–replSet=hxrs \

–auth –keyFile=/usr/local/mongodb/bin/mongo-keyfile

/usr/local/mongodb/bin/mongod \

–dbpath=/hxdata/mongodb/data \

–logpath=/hxdata/mongodb/log/server.log \

–logappend \

–fork \

–port=12700 \

– bind_ip = 192.168.1.192 \

–replSet=hxrs \

–auth –keyFile=/usr/local/mongodb/bin/mongo-keyfile

/usr/local/mongodb/bin/mongod \

–dbpath=/hxdata/mongodb/data \

–logpath=/hxdata/mongodb/log/server.log \

–logappend \

–fork \

–port=12700 \

– bind_ip = 192.168.1.193 \

–replSet=hxrs \

–auth –keyFile=/usr/local/mongodb/bin/mongo-keyfile

4, Select one of them, go to the console, create a dedicated library

/ usr/local/mongo/bin/mongo 192.168.1.191:12700

use admin

db.auth(“root”,”10jqka”)

use dbtest

db.test.insert({_id:1,name:”test”})

db.createUser({user:”chen”,pwd:”123456″,roles:[“dbOwner”]})

db.auth(“chen”,”123456″)

## backup script

/ usr/local/mongo/bin/mongodump -h 127.0.0.1:12701 – u Chen – 123456 – d dbtest – o/p root/mongobak

### Restore script

/usr/local/mongodb/bin/mongorestore -h 192.168.1.191:12700 -u chen -p 123456 -d dbtest –dir /root/mongobak/dbtest