Get the App
SLTechnology News&Howtos  ›  Database  › 

Mongodb is the master and slave of auth.

Shulou Source: shulou.com Published: 2022-06-01 04:11:03 11月19日 Update

Foreword:

My version is 2.6.9. I have the master and follower of auth. I haven't found it for a long time on the Internet. Finally, I found a way to be the master and follower on the official website. It's actually very simple.

If you are a master and slave with verification, then you need to use keyFile verification, according to the official.

When running with authorization enabled, in master-slave deployments configure a keyFile so that slave mongod instances can authenticate and communicate with the master mongod instance.

To enable authentication and configure the keyFile add the following option to your configuration file:

KeyFile=/srv/mongodb/keyfile

So we need to configure keyFile, which is very simple (but it hurts if we don't know)

1. You can use openssl to generate a random key

Openssl rand-base64 741 > > key1

[root@localhost data2] # openssl rand-base64 741

MkME0hJ8TiIKy9+Dm/jkgYEzbC4ZdrGYVFkFQc48pkxiVW+3icmeVPWhbdjv9xR/

RzTkpwYf8idP9qmpujTOHl2hSDAh72r+5DK7Ap0LzYmIEU1ySIQAv1g6VPbfIiwF

XFwZwklp6Fss6YWBoyHOs4YaQWycr20O6mRwUtWC3YmuiIY5UU9go+8xWS+UUBBP

IyM8ZAAWub7USE51nKipi+W+zH2LVMf3NKHjpxuJLsS4iuVJJbA4UbriiE+lQTYR

71xQpZ5hCQw2pywwZsDmQV69FukaLGUcePodGuy8dT8vey9oD/SG0+LolrZTqSv2

IWbP2TYuqVsTQ80stLQAO5LofgC4NZ3mTGn5IVfNVcVuXhu4y0YBE246RdPp83ia

5XbZMDDavuoOoKft87G7mq169GsVJ/4KS0NErfrwPWkGLaCBfkrD2H8/YSs3PnTH

XzXs9xSuhxnGalR7a2S0Gho+NieO4/MIMfiflYuiCxH4SpoHtC+enyNaAEukKKRv

WUvI9+OCBDiB1JHDwK/Lq4edAbb1CLeAsLyLWhRnxWJz+3y+NfixWyrlOB1VAe3s

Jqd15d59t3x82h7tilUmVDqTHL4DipuVsztLHvSjUUlyPGISPwmxYzuItGbuDqVP

4dS/grvJR3Eb94623rFxiZX98U3p6SaPQIyFiOu7RUhHtNzjiMm5FOhu1Hjl42yR

FGGwJG9yZKenEoQOscPgBRENkv08nxiScyFr2tw6YkRdYRxcZWLNcCO36eKlvZRk

49SgUUz8KVxB7kxakztth/dkzAMbqraWoaUzjvj5h565Wdln9cnixxznk85SXLPV

BJuN9KI5ShFRXF1FtDuVmiD2Ibudr6pb08xEtHQYYHHLcmRZmSdYyOUjd9wHBbX5

O3VAs83rsdAhQkwLKgXDYERcveRjRGgu681Ksj5Rc0VZthhpkrhZN4w+tTddm2LR

Y6xaKo22SoW4B/SS67C63hwM1GQh

2. Place key in the mongodb directory and set 0600 permissions

[root@localhost mongodb] # ll

Total 76

Drwxr-xr-x. 2 root root 4096 May 5 01:20 bin

-rw-r--r--. 1 1046 1046 34520 Mar 23 07:49 GNU-AGPL-3.0

-rw-. 1 root root 1004 May 6 04:43 key1

-rw-r--r--. 1 root root 1620 May 6 04:55 mongodb.conf

-rw-r--r--. 1 1046 1046 1359 Mar 23 07:49 README

-rw-r--r--. 1 1046 1046 17793 Mar 23 07:49 THIRD-PARTY-NOTICES

3. Modify the configuration file of mongodb.conf, remove the comments on keyFile options, and fill in the current key1 path.

KeyFile=/usr/local/services/mongodb/key1

4. You can start to be the master and follower now.

1) modify the slave mongodb.conf configuration file

Master=false

Slave=true

Source= main library IP

Slavedelay=60

Autoresync=true

2) start the slave library

Tags: Master-slave configuration verification file preface official method permission comment version directory path generation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Apple NVidia vpn macOS