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 description
1. The cluster architecture of our prod environment MongoDB is the deployment of sharding clusters, but at present we do not have sharding, that is, all the data are on one shard. If the quantity is large and needs to be allocated in the later stage, the cluster can be sharded at any time and transparent to the business side.
2. Deployment of each role
Role IP Port replication set name mongos172.21.244.101172.21.244.102172.21.244.9427000 No config server172.21.244.101172.21.244.102172.21.244.9427100repl_configsvr Storage Node (shard) 172.21.244.101172.21.244.102172.21.244.9427101shard1
3. MongoDB version
Mongos > db.version () 4.0.4-62-g7e345a7
II. Preparation of basic information
0. System optimization
Echo "never" > / sys/kernel/mm/transparent_hugepage/enabledecho "never" > / sys/kernel/mm/transparent_hugepage/defrag
1. Download the MongoDB binary file
Cd / chj/appwget ops.chehejia.com:9090/pkg/chj_mongodb_4.0.4.tar.gztar-zxvf chj_mongodb_4.0.4.tar.gz
2. Establishment of relevant catalogs
# establish base directory mkdir / chj/data/mongodb/chj_db# move MongoDB binaries to bin folder under base directory mv chj_mongodb_4.0.4/bin / chj/data/mongodb/chj_db/bin# establish authentication file directory mkdir / chj/data/mongodb/chj_db/auth# establish configuration file directory mkdir / chj/data/mongodb/chj_db/conf# establish config server data and log directory mkdir / chj / data/mongodb/chj_db/config/data-pmkdir / chj/data/mongodb/chj_db/config/log# establish mongos log directory mkdir / chj/data/mongodb/chj_db/mongos/log-p # establish data node data and log directory mkdir / chj/data/mongodb/chj_db/shard1/data-pmkdir / chj/data/mongodb/chj_db/shard1/log
3. Compilation of related configuration files
A, mongos configuration file compilation
Vim / chj/data/mongodb/chj_db/conf/mongos.confsystemLog: destination: file logAppend: true path: / chj/data/mongodb/chj_db/mongos/log/mongos.logprocessManagement: fork: true # fork and run in background pidFilePath: / chj/data/mongodb/chj_db/mongos/log/mongos.pid # location of pidfile timeZoneInfo: / usr/share/zoneinfonet: port: 27000 bindIpAll: true maxIncomingConnections: 1000 unixDomainSocket: enabled: true pathPrefix: / chj/data/mongodb/chj_db/mongos / log filePermissions: 0700security: keyFile: / chj/data/mongodb/chj_db/auth/keyfile.key# authorization: enabled#replication:sharding: configDB: repl_configsvr/172.21.244.101:27100172.21.244.102:27100172.21.244.94:27100
B, config server configuration file compilation
Vim / chj/data/mongodb/chj_db/conf/config.confsystemLog: destination: file logAppend: true path: / chj/data/mongodb/chj_db/config/log/congigsrv.logstorage: dbPath: / chj/data/mongodb/chj_db/config/data journal: enabled: true wiredTiger: engineConfig: directoryForIndexes: trueprocessManagement: fork: true # fork and run in background pidFilePath: / chj/data/mongodb/chj_db/config/log/configsrv.pid # location of pidfile timeZoneInfo: / usr/share / zoneinfonet: port: 27100 bindIp: 0.0.0.0 # Enter 0.0.0.0 :: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting. # bindIpAll: true maxIncomingConnections: 1000 unixDomainSocket: enabled: true pathPrefix: / chj/data/mongodb/chj_db/config/data filePermissions: 0700security: keyFile: / chj/data/mongodb/chj_db/auth/keyfile.key authorization: enabledreplication: replSetName: repl_configsvrsharding: clusterRole: configsvr
C, the configuration file of storage node is written.
Vim / chj/data/mongodb/chj_db/conf/shard1.confsystemLog: destination: file logAppend: true path: / chj/data/mongodb/chj_db/shard1/log/shard1.logstorage: dbPath: / chj/data/mongodb/chj_db/shard1/data journal: enabled: true wiredTiger: engineConfig: directoryForIndexes: trueprocessManagement: fork: true # fork and run in background pidFilePath: / chj/data/mongodb/chj_db/shard1/log/shard1.pid # location of pidfile timeZoneInfo: / usr/share / zoneinfonet: port: 27101 bindIp: 0.0.0.0 # Enter 0.0.0.0 :: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting. # bindIpAll: true maxIncomingConnections: 1000 unixDomainSocket: enabled: true pathPrefix: / chj/data/mongodb/chj_db/shard1/data filePermissions: 0700security: keyFile: / chj/data/mongodb/chj_db/auth/keyfile.key authorization: enabledreplication: replSetName: shard1sharding: clusterRole: shardsvr
4. Production key certification documents
Echo "chj123456" > / chj/data/mongodb/chj_db/auth/keyfile.key# sets the permissions of the file to 400, otherwise the service cannot start chmod 400 / chj/data/mongodb/chj_db/auth/keyfile.key
III. Cluster initialization
1. Start the config server service
/ chj/data/mongodb/chj_db/bin/mongod-f / chj/data/mongodb/chj_db/conf/config.conf
2. Initialize the config server cluster
# Log in to one of the config server nodes / chj/data/mongodb/chj_db/bin/mongo-- port 2710 configure cluster config = {_ id: "repl_configsvr", members: [{_ id:0,host: "172.21.244.101purge 27100"}, {_ id:1,host: "172.21.244.102purge 27100"}, {_ id:2 Host: "172.21.244.94 config 27100"}]} # initialize the cluster rs.initiate (config) PS: the output is as follows Indicates that the cluster is initialized successfully. You can check the cluster status {"ok": 1, "$gleStats": {"lastOpTime": Timestamp (1557538260, 1), "electionId": ObjectId ("00000000000000000000000000000"), "lastCommittedOpTime": Timestamp (0,0)} via the rs.status () command.
3. Start the storage node service
/ chj/data/mongodb/chj_db/bin/mongod-f / chj/data/mongodb/chj_db/conf/shard1.conf
4. Initialize the storage cluster
# Log in to the server / chj/data/mongodb/chj_db/bin/mongo that you want to be the primary node-- port 2710 configuration cluster config = {_ id: "shard1", members: [{_ id:0,host: "172.21.244.101config 27101"}, {_ id:1,host: "172.21.244.102config 27101"}, {_ id:2,host: "172.21.244.94config 27101" ArbiterOnly:true}]} # initialize the cluster rs.initiate (config) PS: the output is as follows Indicates that the cluster is initialized successfully. You can check the cluster status {"ok": 1} by using the rs.status () command.
5. Add the management account of the storage cluster
Log in to the primary node
/ chj/data/mongodb/chj_db/bin/mongo-- port 27101use admindb.createUser ({user: "root", pwd: "123456", roles: [{role: "root", db: "admin"}]})
6. Start the mongos service
/ chj/data/mongodb/chj_db/bin/mongos-f / chj/data/mongodb/chj_db/conf/mongos.conf
7. Add the management account of config server
Log in to any mongos node
/ chj/data/mongodb/chj_db/bin/mongo-- port 27000use admindb.createUser ({user: "root", pwd: "123456", roles: [{role: "root", db: "admin"}]})
8. Add storage nodes to mongos
Log in to any mongos node (if you are in the window in the previous step, you need to log out and log in again)
/ chj/data/mongodb/chj_db/bin/mongo-- port 27000use admindb.auth ('root','123456') # add shard sh.addShard (' shard1/172.21.244.101:27101172.21.244.102:27101172.21.244.94:27101') # View shard status sh.status ()
IV. Delivery to the business side
1. Set up an application account
Log in to any mongos node / chj/data/mongodb/chj_db/bin/mongo-- port 27000use admindb.auth ('root','123456') # cut to the business database use chj_db# to set up a read / write account db.createUser ({user: "chj_db_rw", pwd: "123456", roles: [{role: "readWrite", db: "chj_db"}, {role: "dbOwner") Db: "chj_db"}]}) # establish a read-only account (confirm whether it is required according to business requirements) db.createUser ({user: "chj_db_r", pwd: "123456", roles: [{role: "read", db: "chj_db"}]})
2. Deliver developer information
Connection address: 172.21.244.101Viru 27000172.21.244.102VOU 27000172.21.244.94Rank name: chj_db account: chj_db_rw password: 123456
Fifth, the database enables sharding
If there is a large amount of business in the later stage, sharding needs to be enabled. The configuration is as follows.
# specify the database mongos > sh.enableSharding ("chj_db") {"ok": 1, "operationTime": Timestamp (1557546835, 3), "$clusterTime": {"clusterTime": Timestamp (1557546835, 3), "signature": {"hash": BinData (0, "bkrrr8Kxrr9j9udrDc/hURHld38=") "keyId": NumberLong ("6689575940508352541")}} # created the ascending chip keys mongos > sh.shardCollection ("chj_db.users", {name:1,age:1}) {"collectionsharded": "chj_db.users", "collectionUUID": UUID ("59c0b99f-efff-4132-b489-f6c7e3d98f42"), "ok": 1 in the chj_db database and the users collection "operationTime": Timestamp (1557546861, 12), "$clusterTime": {"clusterTime": Timestamp (1557546861, 12), "signature": {"hash": BinData (0, "UBB1A/YODnmXwG5eAhgNLcKVzug=") "keyId": NumberLong ("6689575940508352541")}} # View sharding mongos > sh.status ()-Sharding Status-sharding version: {"_ id": 1, "minCompatibleVersion": 5, "currentVersion": 6, "clusterId": ObjectId ("5cd625e0da695346d740f749")} shards: {"_ id": "shard1" "host": "shard1/172.21.244.101:27101172.21.244.102:27101", "state": 1} active mongoses: "4.0.4-62-g7e345a7": 3 autosplit: Currently enabled: yes balancer: Currently enabled: yes Currently running: no Failed balancer rounds in last 5 attempts: 0 Migration Results for the last 24 hours: No recent migrations databases: {"_ id": "chj_db" "primary": "shard1", "partitioned": true, "version": {"uuid": UUID ("82088bc7-7b98-4033-843d-7058d8d959f6"), "lastMod": 1} chj_db.users shard key: {"name": 1 "age": 1} unique: false balancing: true chunks: shard1 1 {"name": {"$minKey": 1}, "age": {"$minKey": 1}}-- > {"name": {"$maxKey": 1}, "age": {"$maxKey": 1} on: shard1 Timestamp (1) 0) {"_ id": "config", "primary": "config" "partitioned": true} config.system.sessions shard key: {"_ id": 1} unique: false balancing: true chunks: shard1 1 {"_ id": {"$minKey": 1}}-- > {"_ id": {"$maxKey": 1}} on: shard1 Timestamp (1,0)
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
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
Is there any Python you have the technology, I have the need to cooperate sincerely
© 2024 shulou.com SLNews company. All rights reserved.