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--
1. Build a single instance of mongodb
1. Download package address
1. Download address https://www.mongodb.org/downloads2 of each version, and install the latest version of 3.6.5wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.5.tgz in this article.
2. Installation
1. Decompress tar xf mongodb-linux-x86_64-3.6.5.tgz & & mv mongodb-linux-x86_64-3.6.5 / usr/local/mongodb-3.6.52, create related directory mkdir-p / data/mongodb27017/ {data,log,conf} 3, parameter file configuration Vim / data/mongodb27017/conf/mongodb-27017.cnfport=27017bind_ip=192.168.142.48127.0.0.1dbpath=/data/mongodb27017/datalogpath=/data/mongodb27017/log/mongodb.logpidfilepath=/data/mongodb27017/mongodb.pidlogappend=truefork=trueauth=true
3. Start and shut down
1. Start mongodb/usr/local/mongodb-3.6.5/bin/mongod-f / data/mongodb27017/conf/mongodb-27017.cnf2, enter / usr/local/mongodb-3.6.5/bin/mongo-- port=270173 on the client command line for the first time, and create supermanaged user db.createUser ({user: "admin", pwd: "123456", roles: [{role: "root") Db: "admin"}]}) 4. Enter the client command line again / usr/local/mongodb-3.6.5/bin/mongo 192.168.142.48:27017/admin-u admin-p123456 > db.getCollectionNames () ["system.users", "system.version"] 5, close mongodb/usr/local/mongodb-3.6.5/bin/mongo 192.168.142.48:27017/admin-u admin-p123456 > db.shutdownServer () 2. Build the replication set of mongodb
Create a replication set based on a single instance (supermanaged users have been configured)
192.168.142.48:27017192.168.142.48:27018192.168.142.48:27019
1. Add keyfile file
1. Vim keyfile123456all2, set permissions chmod 600keyfile
2. Configuration file, which is added on the basis of single instance
# / data/mongodb27017/conf/mongodb-27017.cnfkeyFile=/data/mongodb27017/keyfileoplogSize=1024replSet=rs_one# / data/mongodb27018/conf/mongodb-27018.cnfkeyFile=/data/mongodb27018/keyfileoplogSize=1024replSet=rs_one# / data/mongodb27019/conf/mongodb-27019.cnfkeyFile=/data/mongodb27019/keyfileoplogSize=1024replSet=rs_one
3. Start the instance
/ usr/local/mongodb-3.6.5/bin/mongod-f / data/mongodb27017/conf/mongodb-27017.cnf/usr/local/mongodb-3.6.5/bin/mongod-f / data/mongodb27018/conf/mongodb-27018.cnf/usr/local/mongodb-3.6.5/bin/mongod-f / data/mongodb27019/conf/mongodb-27019.cnf
4. Configure replication sets
1. Log in to any command line / usr/local/mongodb-3.6.5/bin/mongo 192.168.142.48:27017/admin-u admin-p1234562, configure replica set member config = {"_ id": "rs_one", members: [{"_ id": 0Magnehost: "192.168.142.48 config 27017"}, {"_ id": 1Lyric host: "192.168.142.48 config 27018"}, {"_ id": 2 Host: "192.168.142.48 rs.initiate 27019", arbiterOnly:true}]} 3, initialize the replication set rs.initiate (config) 4, view the replication set status rs.conf () View the configuration of the replica set rs.status (), view the status of the replica set rs.printSlaveReplicationInfo (), view the synchronization status of each node rs.printReplicationInfo (), view the synchronization event overview db.isMaster (), view the current replication set overview
5. Management of replication sets
1. Add replica set members use rs.add (HOST_NAME:PORT) to add new replica set machines, for example: rs.add ("192.168.142.48 rs.add 27019") 2, delete replica set members use rs.remove (HOST_NAME:PORT) to delete replica set machines, for example: rs.remove ("192.168.142.48 HOST_NAME:PORT 27019") 3, replica set parameter configuration for complex replica set configuration Rs.reconfig function modification is more useful than rs.add and rs.remove to var a = rs.config () rs.reconfig (a) 4, to solve the error "not master and slaveOk=false" 1). This time effective rs.slaveOk (); 2). Permanently effective vim ~ / .mongorc.js, add a line rs.slaveOk () In this way, every time you enter the slave library through the mongo command, you can query 5, for the arbitration node to be changed to a normal member of the copy set 1, delete the arbitration node, rs.remove ("192.168.142.48 27019") 2, restart the instance of the arbitration node (must) 3, and add the member again. Rs.add ("192.168.142.48 rs.stepDown 27019") 6. Manually downgrade the primary node to a normal node PRIMARY > rs.stepDown ()
6. The principle of replica set election node
When a backup node is unable to connect with the primary node, he contacts and requests other members to elect himself as the primary node, and other members do several rational checks
1. Whether you can connect with the primary node 2, whether the data of the backup node that wants to be elected as the primary node is up to date, 3. Are there any other higher priority members who can be elected as the primary node?
When the primary node election occurs, the backup node with the highest priority priority, if the data is not up to date, must use replication to update its data to the latest or one of the latest in order to become the new primary node.
Third, the construction of mongodb sub-album
The principle of fragment set
Create a shard set on the basis of replication set construction
Replication set rs_one192.168.142.48:27017192.168.142.48:27018192.168.142.48:27019 replication set rs_two192.168.142.49:27017192.168.142.49:27018192.168.142.49:27019 replication set rs_three192.168.142.50:27017192.168.142.50:27018192.168.142.50:27019 configuration server config server replication set replication set rs_cfg192.168.142.48:40011192.168.142.48:40012192.168.142.48:40013
1. Configuration file
1 、 rs_one,rs_two The instance configuration files involved in rs_three need to add additional shardsvr=true2 (on the basis of the replication set), and the instance configuration files involved in rs_cfg need to add additional configsvr=true3, Configuration file port=20000bind_ip=192.168.142.48127.0.0.1logpath=/data/mongodb20000/log/mongodb.logpidfilepath=/data/mongodb20000/mongodb.pidkeyFile=/data/mongodb20000/keyfilelogappend=truefork=trueconfigdb=rs_cfg/192.168.142.48:40011192.168.142.48:40012192.168.142.48:40013note for mongos: where rs_cfg/192.168.142.48:40011192.168.142.48:40012192.168.142.48:40013 is the config server replication set
2. The contents of keyfile files are consistent.
Replication set keyfile file content config server replication set rs_cfg keyfile file content mongos keyfile file content file content (but more complex settings) 123456all
3. Start
1 、 Start replication set rs_one 192.168.142.48rs_two 192.168.142.49rs_three 192.168.142.50 start replication set / usr/local/mongodb-3.6.5/bin/mongod-f / data/mongodb27017/conf/mongodb-27017.cnf/usr/local/mongodb-3.6.5/bin/mongod-f / data/mongodb27018/conf/mongodb-27018.cnf/usr/local/mongodb-3.6.5/bin/mongod-f / data/mongodb27019/conf/mongodb-27019.cnf2, respectively. Start the config server replication set rs_cfgrs_cfg 192.168.142.48/usr/local/mongodb-3.6.5/bin/mongod-f / data/mongodb40011/conf/mongodb-40011.cnf/usr/local/mongodb-3.6.5/bin/mongod-f / data/mongodb40012/conf/mongodb-40012.cnf/usr/local/mongodb-3.6.5/bin/mongod-f / data/mongodb40013/conf/mongodb-40013.cnf3, Start mongos192.168.142.48/usr/local/mongodb-3.6.5/bin/mongos-f / data/mongodb20000/conf/mongodb-20000.cnf
4. Configure slicing
1. Enter mongos/usr/local/mongodb-3.6.5/bin/mongo 192.168.142.48:20000/admin-u admin-p123456note on the command line: although mongos password-free auth authentication is built here, you must log in with password authentication to add shards. Keep the password consistent with config server 2, add the replica set to the cluster sh.addShard ("rs_one/192.168.142.48:27017192.168.142.48:27018192.168.142.48:27019") sh.addShard ("rs_two/192.168.142.49:27017192.168.142.49:27018192.168.142.49:27019") sh.addShard ("rs_three/192.168.142.50:27017192.168.142.50:27018192.168.142.50:27019") 3, View the cluster status sh.status () 4 and the sharding policy db.runCommand ({enablesharding: "wang"}) db.runCommand ({shardcollection: "wang.t1") of the configuration table Key: {id:1}}) 5. View table status use wangfor (var item0) I sh.addShard ("rs_one/192.168.142.48:27017192.168.142.48:27018192.168.142.48:27019") {"ok": 0, "errmsg": "E11000 duplicate key error collection: admin.system.version index: _ id_ dup key: {:\" shardIdentity\ "}", "code": 11000, "codeName": "DuplicateKey",.} 2. Connect the rs_one master node Delete records rs_one:PRIMARY > db.system.version.remove ({"_ id": "shardIdentity"}) WriteResult ({"writeError": {"code": 13, "errmsg": "not authorized on admin to execute command {delete:\" system.version\ ", ordered: true, $clusterTime: {clusterTime: Timestamp (1528280178, 1), signature: {hash: BinData (0, 914ECCE14D194F41251247EAB282E1F346D4C7D0), keyId: 6563852648502525972}} $db:\ "admin\"}}) reported an error because the role of the admin user is root Do not have permission to modify admin.system.version Add corresponding permission db.grantRolesToUser ("admin", [{role: "_ system", db: "admin"}]) 3. Delete rs_one:PRIMARY > db.system.version.remove ({"_ id": "shardIdentity"}) WriteResult ({"nRemoved": 0, "writeError": {"code": 40070) again. "errmsg": "cannot delete shardIdentity document while in-- shardsvr mode"}}) error deleting Times It means that the record in this table cannot be deleted in sharding mode, and then we close rs_one and start it in a non-shardsvr mode. After deleting the record, we start it in shardsvr mode. 4. Start it in a non-shardsvr mode, delete the record, and then start it in shardsvr mode. 1) comment out the configuration file # shardsvr=true 2) restart instance 3) delete the corresponding system.version record Db.system.version.remove ({"_ id": "shardIdentity"}) 4) configuration file opens shardsvr=true 5) restart instance 5, restart addShardongos > sh.addShard ("rs_one/192.168.142.48:27017192.168.142.48:27018192.168.142.48:27019") {"shardAdded": "rs_one", "ok": 1, "$clusterTime": {"clusterTime": Timestamp (1528284663, 7) "signature": {"hash": BinData (0, "qLejzYtJDR1Bpt84+Hapdi1w1/I="), "keyId": NumberLong ("6563903792973086740")}}, "operationTime": Timestamp (1528284663, 7)}
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.