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--
Brief introduction of environment
192.168.1.151 FedoraServer is used as the main library of the replica set, and data is already available
192.168.1.152 FedoraServer slave library, empty instance
192.168.1.153 FedoraServer slave library, empty instance
Replica set of MongoDB and MySQL Multi-source three-instance cycle Master-Slave based on GTID
However, compared with MySQL's third-party plug-ins such as Keepalive or MHA, mongodb has its own failover and switchover functions, so this product is very advanced.
Building steps
Mongodb installation:
Percona-Server-MongoDB-34-server
2. Mongodb configuration:
The configuration of vim / etc/mongod.conf # mongod.conf, Percona Server for MongoDB # for documentation of all options, see: # # mongodb has a special feature: colon ":" followed by a space # Where and how to store data. Storage: dbPath: / data/mongo/27153/data/ # specify the mongodb file storage location journal: enabled: true # engine: mmapv1 # engine: PerconaFT # engine: rocksdb engine: wiredTiger # specify the storage engine, which is similar to Innodb and supports document locks (row locks) # Storage engine various options # mmapv1: # wiredTiger: # where to write logging data. SystemLog: quiet: true destination: file logAppend: true # logs are appended path: / data/mongo/27153/log/mongod.log # Log file location processManagement: fork: true # start thread pull up the main thread Somewhat similar to the mysqld_safe process pidFilePath: / data/mongo/27153/mongod.pid # PID file location # network interfaces net: port: 27153 # port, default 27017 bindIp: 0.0.0.0 # Open access IP range security: authorization: enabled # enable verification KeyFile: / data/mongo/mongodb.key # use key files for authentication between replica sets # operationProfiling: # replication: replication: replSetName: zrz # name of the synchronization set # sharding: # # Enterprise-Only Options: # auditLog:#snmp:
3. Build process:
1. All three turn off authentication mode
Vim / etc/mongod.conf comment out the configuration statement related to verification # security: # authorization: enabled # enable verification, # keyFile: / data/mongo/mongodb.key # use the key file for authentication between replica sets
two。 Start the service:
Mongod-f / etc/mongod.conf
3. Log in to an instance with data:
Mongo-- port 27151mongo > config= {"_ id": "zrz", "members": [{"_ id": 1Magnehost: "192.168.1.151config= 27151", priority:100}, {"_ id": 2priority host: "192.168.1.15227152", priority:0}]} / definition is configured in the variable config / / zrz is the group name, priority is the selected sovereign weight The higher the easier to become the master (non-failure case) mongo > rs.initiate (config) / / use the rs.initiate command to initialize the replica set configuration mongo > rs.status / / View the replica set configuration mongo > rs.add ({"_ id": 3dint host: "192.168.1.153mongo 27153", priority:0}) / / add the replica set in another way
4. Turn on authentication:
For security reasons, additional authentication is required for access to MongoDB:
Step 1: add the user db.createUser () to the current primary-level instance
Step 2: close the secondary-level instance mongod-- shutdown-f / etc/mongod.conf
Step 3: close the instance at the primary level
Step 4: modify the configuration file of each instance to enable verification. Configure the account or distribute the key
Step 5: first open the last closed primary instance, and then open each secondary instance
There are two ways of cross-instance authentication: account and password or using SSL key
Among them: account and password can only be used on the configuration server of mongos shard, and the instances are verified by config_server
The key file is a base64 string generated by an openssl program, and those with the same string can be synchronized
Generation method:
Openssl rand-base64 756 > / data/mongo/mongodb.key
Change the properties of the key file to prevent modification:
Chmod 400 / data/mongo/mongodb.key
Distribute it to your friends:
Scp / data/mongo/mongodb.key 192.168.1.152:/data/mongo/ scp / data/mongo/mongodb.key 192.168.1.153:/data/mongo/
Modify the configuration file to specify the key location
Vim / etc/mongod.conf security: authorization: enabled # enables verification, and keyFile: / data/mongo/mongodb.key # uses key files for authentication between replica sets
Just turn on the service in order.
Mongod-f / etc/mongo
Common errors and their solutions:
1. Build replica sets across versions (3.03.4), which is not supported by MongoDB.
two。 After the instance failed to join the replica set, some data was generated unexpectedly, which made it impossible for primary to join the replica set.
How to handle it: comment out the configuration files related to replication, restart the service, that is, enter stand-alone mode, and use db.dropDatabase ()
Delete all databases and then re-enter replica set startup mode
3. Prompt already configured, unable to initialize, use rs.reconfig (config {force:true})
4. Use rs.help () to view commands for related replica sets
Key file: https://docs.mongodb.com/manual/reference/configuration-options/#security.keyFile
Reconfigure: https://docs.mongodb.com/manual/reference/method/rs.reconfig/#rs.reconfig
Copy related commands: https://docs.mongodb.com/manual/reference/method/js-replication/
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.