MongoDB authentication downgrade

Background: As the business feedback MongoDB PHP client migration lead to abnormal connections DB, the investigation found MongoDB3.0 version of authentication and authorization mechanism is SCRAM-SHA-1, the program drives the abnormal, need to be downgraded to an authentication and authorization mechanisms: MONGODB-CR
 
Downgrade following authentication (login authentication to the situation in the absence of):
1, the configuration file comments authentication
security:
   keyFile: /data1/ceshi27020_mongo/etc/keyfile
   authorization: enabled
2, restart mongo
3, run the following command on the master:
db.system.users.find();
db.system.version.findOne();
var schema = db.system.version.findOne({"_id" : "authSchema"}) 
schema.currentVersion = 3 
db.system.version.save(schema) 
Rebuild User:
db.dropUser('test_rw');
db.createUser( { "user" : "test_rw",
"pwd": "iwoCsl173",
"roles" : [{ role: "readWrite", db: "lsession" }] });
4, open authentication, restart MongoDB
 
Version 3.0 authentication and authorization mechanisms: SCRAM-SHA-1
After the authentication and authorization mechanisms degradation: MONGODB-CR
 
PHP is connected MongoDB Code Example:
root@xxx-xxxx:/# cat mongo.php 
<?php
$server = 'mongodb://10.x.x.x:27030';
$options = array(
                'db'=>'admin',//',
                'username' => 'dba',//',
                'password' => 'xxxxxxxx',
                'replicaSet' => 'test3',
                'readPreference' => MongoClient::RP_SECONDARY_PREFERRED,
                // 'readPreference' => MongoClient::RP_PRIMARY,
                'connectTimeoutMS'=>5000,
                );
$mongo = new MongoClient($server, $options);
$db = $mongo->selectDB('zyq');
$coll = $db->selectCollection('test10');
$result = $coll->find(array("userid"=>30748));
while($doc = $result->getNext()){
        var_dump($doc);
}
Execution OK!

Guess you like

Origin www.cnblogs.com/DBA-3306/p/11097245.html