One, configuration file/etc/mongod.conf
[[email protected] ~]# egrep-v "^ (#|$)"/etc/mongod.conf
Systemlog:
Destination:file
Logappend:true
Path:/data/mongodb/log/rs1.log
Storage
DbPath:/data/mongodb/data
Directoryperdb:true
Journal
Enabled:true
Processmanagement:
Fork:true # Fork and run in background
Pidfilepath:/data/mongodb/conf/mongod.pid # Location of Pidfile
Net
port:27027
Replication
oplogsizemb:50000
Replsetname:rs1
[Email protected] ~]#
[Email protected] ~]# ls/data/mongodb/
Arbiter Conf Data log startaribiter.sh
[Email protected] ~]# ls/data/mongodb/arbiter/
ARBITER.CONF conf Data log
[[email protected] ~]# egrep-v "^ (#|$)"/data/mongodb/arbiter/arbiter.conf
Systemlog:
Destination:file
Logappend:true
Path:/data/mongodb/arbiter/log/rs1.log
Storage
DbPath:/data/mongodb/arbiter/data
Directoryperdb:true
Journal
Enabled:true
Processmanagement:
Fork:true # Fork and run in background
Pidfilepath:/data/mongodb/arbiter/conf/mongod.pid # Location of Pidfile
Net
port:27029
Replication
oplogsizemb:50000
Replsetname:rs1
[Email protected] ~]# cat/data/mongodb/startarbiter.sh
#!/bin/sh
. /etc/rc.d/init.d/functions
CD ${0%/*}/arbiter
Daemon--user mongod "Mongod--config arbiter.conf"
[Email protected] ~]#
Note: The owner of the arbiter.conf file, the genus Group is Mongod
Second, start the service, configure the replica set
Service Mongod Start
/data/mongodb/startaribiter.sh
Start a second node
then: in Primary on,
Rs.initiate ()
Rs.add ("Mongodb2.example.net")
Rs.add ("Mongodb3.example.net")
Rs.addarb ("mongodb1.example.net: 27029")
If you want to reduce Primary The priority level:
CFG = rs.conf ()
cfg.members[2].priority = 0.5
Rs.reconfig (CFG)
Rs.status ()
After the replication is implemented, view the data on the slave node as follows:
Secondary> Rs.slaveok ()
Secondary> Rs.slaveok ()
Secondary> Show Collections
Iii. using KeyFile for replication verification
Create the cluster user and password on the master node as follows:
admin = db.getsiblingdb ("admin")
Admin.createuser (
{
User: "Clusteradmin",
PWD: "Clusterpwd",
Roles: [
{role: "Useradminanydatabase", DB: "Admin"},
{role: "Clusteradmin", DB: "Admin"},
{role: "root", DB: "Admin"}
]
}
)
Test User:
Db.getsiblingdb ("admin"). Auth ("Clusteradmin", "Clusterpwd")
To shut down the service on each slave node:
Use admin
Db.shutdownserver ()
include Arbiter the node also shuts down the service, and finally shuts down Primary node's services.
then in each configuration file mongdb.conf To Add the authentication file:
Security
KeyFile:/data/mongodb/conf/keyfile.key
[Email protected] ~]# Cat/data/mongodb/conf/keyfile.key
Abcdefgh
the permissions for the file must be - or - , and copy the file to each node (keeping the content the same), and the file can be generated using the following command: OpenSSL rand-base64 755 > Path-to-keyfile
Finally, start the new node MongoDB service, and re- Login , Test.
Reference: https://docs.mongodb.com/manual/tutorial/deploy-replica-set/
https://docs.mongodb.com/manual/tutorial/enforce-keyfile-access-control-in-existing-replica-set/
This article is from the "11462293" blog, please be sure to keep this source http://11472293.blog.51cto.com/11462293/1790862
mongodb3.2 Replica Sets