In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
I. Environmental information
CentOS release 6.7 (Final)
Mongo version: 3.2.6
192.168.1.173 primary
192.168.1.174 secondary
192.168.1.172 secondary or arbiter
Second, install mongo
1. Yum source configuration (which version of enable=1 to use)
# cat / etc/yum.repos.d/mongodb-org-3.2.repo
[mongodb-org-3.2]
Name=MongoDB Repository
Baseurl= https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
Gpgcheck=1
Enabled=1
Gpgkey= https://www.mongodb.org/static/pgp/server-3.2.asc
[mongodb-org-2.6]
Name=MongoDB 2.6 Repository
Baseurl= http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
Gpgcheck=0
Enabled=0
2. Yum install-y mongodb-org
III. Replicat set configuration
1. Modify the configuration file (the three servers are different except ip):
Cat / etc/mongod.conf
# 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: / var/log/mongodb/mongod.log
# Where and how to store data.
Storage:
DbPath: / data/mongo
# dbPath: / var/lib/mongo
Journal:
Enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
ProcessManagement:
Fork: true # fork and run in background
PidFilePath: / var/run/mongodb/mongod.pid # location of pidfile
# network interfaces
Net:
Port: 27017
BindIp: 192.168.1.173 # Listen to local interface only, comment to listen on all interfaces.
# security:
Security: # Security authentication cannot be opened until the replica set is configured successfully
Authorization: enabled # enable authentication
KeyFile: / data/mongo/mongodb-keyfile # replica set uses keyFile for mutual authentication
# operationProfiling:
# replication:
Replication:
OplogSizeMB: size M of 2000 # oplog
ReplSetName: name of the rongyi # replica set
# sharding:
# # Enterprise-Only Options
# auditLog:
# snmp:
2. Configure the replicat set process
# start the mongod service
# / usr/bin/mongod-f / etc/mongod.conf
After starting successfully, because auth authentication has not been enabled, you can log in directly on the command line.
# mongo 192.168.1.173
Use admin
Admin > config = {_ id: "rongyi", members: [
... {_ id:172,host: "192.168.1.172 27017", arbiterOnly:true}
... {_ id:173,host: "192.168.1.173purl 27017"}
... {_ id:174,host: "192.168.1.174purl 27017"}]
...}
{
"_ id": "rongyi"
"members": [
{
"_ id": 172
"host": "192.168.1.172 purl 27017"
"arbiterOnly": true
}
{
"_ id": 173
"host": "192.168.1.173purl 27017"
}
{
"_ id": 174
"host": "192.168.1.174purl 27017"
}
]
}
Admin > rs.initiate (config)
{"ok": 1}
Or use the
Config = {_ id: "rongyi", members: [{_ id:172,host: "192.168.1.172config 27017"}, {_ id:173,host: "192.168.1.173virtual 27017"}, {_ id:174,host: "192.168.1.174virtual 27017"}]}
Note: the former is a backup node, the latter is two backup nodes, the mongo election process must conform to the majority, if it is an even number of nodes, you can use arbiter (arbitration node), this node is only to participate in the election
Use rs.status () to view the status of replicat set
3. Create an administrator account (this account needs to use root role or an error will be reported):
Admin > db.createUser ({user: "admin", pwd: "*", roles: [{role: "root", db: "admin"}]})
Successfully added user: {
"user": "admin"
"roles": [
{
"role": "root"
"db": "admin"
}
]
}
4. Configure keyfile authentication
Execute on 192.168.1.173
Openssl rand-base64 741 > / data/mongo/mongodb-keyfile
Chmod 600 / data/mongo/mongodb-keyfile
Scp mongodb-keyfile 192.168.1.174:/data/mongo/
Scp mongodb-keyfile 192.168.1.172:/data/mongo/
Turn on authentication in the configuration file:
Security:
Authorization: enabled
KeyFile: / data/mongo/mongodb-keyfile
5. Restart the mongod service
/ etc/init.d/mongod stop & & / usr/bin/mongod-f / etc/mongod.conf
IV. Login verification
Mongo 192.168.1.173:27017/admin-uadmin-p *
Admin > rs.status ()
{
"set": "rongyi"
"date": ISODate ("2016-06-24T08:31:28.549Z")
"myState": 1
"term": NumberLong (7)
"heartbeatIntervalMillis": NumberLong (2000)
"members": [
{
"_ id": 172
"name": "192.168.1.172 purl 27017"
"health": 1
"state": 7
"stateStr": "ARBITER", # using arbitration
"uptime": 19572
"lastHeartbeat": ISODate ("2016-06-24T08:31:26.604Z")
"lastHeartbeatRecv": ISODate ("2016-06-24T08:31:24.145Z")
"pingMs": NumberLong (0)
"configVersion": 3
}
{
"_ id": 173
"name": "192.168.1.173purl 27017"
"health": 1
"state": 1
"stateStr": "PRIMARY"
"uptime": 19573
"optime": {
Ts: Timestamp (1466740497, 1)
"t": NumberLong (7)
}
"optimeDate": ISODate ("2016-06-24T03:54:57Z")
ElectionTime: Timestamp (1466737527, 1)
"electionDate": ISODate ("2016-06-24T03:05:27Z")
"configVersion": 3
"self": true
}
{
"_ id": 174
"name": "192.168.1.174purl 27017"
"health": 1
"state": 2
"stateStr": "SECONDARY"
"uptime": 19567
"optime": {
Ts: Timestamp (1466740497, 1)
"t": NumberLong (7)
}
"optimeDate": ISODate ("2016-06-24T03:54:57Z")
"lastHeartbeat": ISODate ("2016-06-24T08:31:26.604Z")
"lastHeartbeatRecv": ISODate ("2016-06-24T08:31:26.604Z")
"pingMs": NumberLong (0)
"syncingTo": "192.168.1.173purl 27017"
"configVersion": 3
}
]
"ok": 1
}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.