How to Create Master & Slave Setup on Mongodb by Two Different Servers?

Hi Team,

We have set up two Rocky LinuxServers for Our Application through MongoDB

By the Way of Master & Slave Setup

I Need the Process for Sync the DB Files between two Servers
Then I Need a Primary & Secondary Process too.

Please Support & Answer as Soon as Possible

The terms master and slave are not appropriate anymore.

You need to setup a replica set with 3 servers. Look at the following for well written information

1 Like

After the Replication Setup, I have Facing a DB Destroy Issue
Please Check the Screenshot and Support Immediately

image

It is a bit frustrating that you wait for 2 months before any follow up on a reply to your OP to ask for

It looks you have been hacked by lack of security on your installation. You will probably get more help by reading READ__ME_TO_RECOVER_YOUR_DATA.

If you had important data and no recent backup, no one knows except the creator of the READ__ME_TO_RECOVER_YOUR_DATA. This is irresponsible to have important data and no recent backup. The solution is to secure your installation and define a backup strategy.

If you had important data and a recent backup, the obvious solution is to secure your installation and restore from your backup.

If you did not have important data, no harm has been done. But secure your installation and define a backup strategy.

The important things to remember are:

1- secure your installation
2- define a backup strategy

Hi Steeve
While Secure My Installation I am Using Security as a Key File Authentication Process
While Setup I am Facing Some Error Below I Will Include the Error Log for Your Reference

{“t”:{“$date”:“2024-05-20T22:14:49.812-05:00”},“s”:“I”, “c”:“NETWORK”, “id”:4915701, “ctx”:“main”,“msg”:“Initialized wire specification”,“attr”:{“spec”:{“incomingExternalClient”:{“minWireVersion”:0,“maxWireVersion”:21},“incomingInternalClient”:{“minWireVersion”:0,“maxWireVersion”:21},“outgoing”:{“minWireVersion”:6,“maxWireVersion”:21},“isInternalClient”:true}}}
{“t”:{“$date”:“2024-05-20T22:14:49.816-05:00”},“s”:“I”, “c”:“CONTROL”, “id”:23285, “ctx”:“main”,“msg”:“Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols ‘none’”}
{“t”:{“$date”:“2024-05-20T22:14:49.817-05:00”},“s”:“I”, “c”:“NETWORK”, “id”:4648601, “ctx”:“main”,“msg”:“Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize.”}
{“t”:{“$date”:“2024-05-20T22:14:49.837-05:00”},“s”:“I”, “c”:“ACCESS”, “id”:20254, “ctx”:“main”,“msg”:“Read security file failed”,“attr”:{“error”:{“code”:30,“codeName”:“InvalidPath”,“errmsg”:“Error reading file /home/saravanan/mongo-security/keyfile.txt: Permission denied”}}}
{“t”:{“$date”:“2024-05-20T22:14:49.838-05:00”},“s”:“I”, “c”:“ASIO”, “id”:6529201, “ctx”:“main”,“msg”:“Network interface redundant shutdown”,“attr”:{“state”:“Stopped”}}
{“t”:{“$date”:“2024-05-20T22:14:49.838-05:00”},“s”:“I”, “c”:“ASIO”, “id”:22582, “ctx”:“main”,“msg”:“Killing all outstanding egress activity.”}
{“t”:{“$date”:“2024-05-20T22:14:49.838-05:00”},“s”:“I”, “c”:“SHARDING”, “id”:5847201, “ctx”:“main”,“msg”:“Balancer command scheduler stop requested”}
{“t”:{“$date”:“2024-05-20T22:14:49.838-05:00”},“s”:“I”, “c”:“ASIO”, “id”:6529201, “ctx”:“main”,“msg”:“Network interface redundant shutdown”,“attr”:{“state”:“Stopped”}}
{“t”:{“$date”:“2024-05-20T22:14:49.838-05:00”},“s”:“I”, “c”:“ASIO”, “id”:22582, “ctx”:“main”,“msg”:“Killing all outstanding egress activity.”}
{“t”:{“$date”:“2024-05-20T22:14:49.838-05:00”},“s”:“F”, “c”:“CONTROL”, “id”:20575, “ctx”:“main”,“msg”:“Error creating service context”,“attr”:{“error”:“Location5579201: Unable to acquire security key[s]”}}

But I have Given Folder Permission and File Permission too

The error message

does not lie and what ever you did when your did

is not appropriate. More details about the ownership and permissions you gave to the file are needed. The command you use to start mongodb is also important to share.

@Saravanaprasad_k, after

and then you leave the last reply without followup for a week. Do not wonder why if you feel ghosted next time.

I am working with the security key authentication installation method, but I am still facing the same error

Please read what we write. Because we wrote, a week ago,

And you have not supplied any other information.

Hi Steeve
I Locked Under Another Work Please Wait
Once I Started My Progress on this Work I Will get back to You

Hi Steeve

I am Still Facing the Same Error I Removed and installed Multiple times With Reference to Multiple Websites and YouTube videos

Error:
tail -f /var/log/mongodb/mongod.log
{“t”:{“$date”:“2024-06-02T10:25:36.380-05:00”},“s”:“I”, “c”:“CONTROL”, “id”:23285, “ctx”:“main”,“msg”:“Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols ‘none’”}
{“t”:{“$date”:“2024-06-02T10:25:36.380-05:00”},“s”:“I”, “c”:“NETWORK”, “id”:4915701, “ctx”:“main”,“msg”:“Initialized wire specification”,“attr”:{“spec”:{“incomingExternalClient”:{“minWireVersion”:0,“maxWireVersion”:21},“incomingInternalClient”:{“minWireVersion”:0,“maxWireVersion”:21},“outgoing”:{“minWireVersion”:6,“maxWireVersion”:21},“isInternalClient”:true}}}
{“t”:{“$date”:“2024-06-02T10:25:36.381-05:00”},“s”:“I”, “c”:“NETWORK”, “id”:4648601, “ctx”:“main”,“msg”:“Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize.”}
{“t”:{“$date”:“2024-06-02T10:25:36.403-05:00”},“s”:“I”, “c”:“ACCESS”, “id”:20254, “ctx”:“main”,“msg”:“Read security file failed”,“attr”:{“error”:{“code”:30,“codeName”:“InvalidPath”,“errmsg”:“error opening file: /var/lib/mongo/mongodb_keyfile: bad file”}}}
{“t”:{“$date”:“2024-06-02T10:25:36.404-05:00”},“s”:“I”, “c”:“ASIO”, “id”:6529201, “ctx”:“main”,“msg”:“Network interface redundant shutdown”,“attr”:{“state”:“Stopped”}}
{“t”:{“$date”:“2024-06-02T10:25:36.404-05:00”},“s”:“I”, “c”:“ASIO”, “id”:22582, “ctx”:“main”,“msg”:“Killing all outstanding egress activity.”}
{“t”:{“$date”:“2024-06-02T10:25:36.404-05:00”},“s”:“I”, “c”:“SHARDING”, “id”:5847201, “ctx”:“main”,“msg”:“Balancer command scheduler stop requested”}
{“t”:{“$date”:“2024-06-02T10:25:36.404-05:00”},“s”:“I”, “c”:“ASIO”, “id”:6529201, “ctx”:“main”,“msg”:“Network interface redundant shutdown”,“attr”:{“state”:“Stopped”}}
{“t”:{“$date”:“2024-06-02T10:25:36.404-05:00”},“s”:“I”, “c”:“ASIO”, “id”:22582, “ctx”:“main”,“msg”:“Killing all outstanding egress activity.”}
{“t”:{“$date”:“2024-06-02T10:25:36.404-05:00”},“s”:“F”, “c”:“CONTROL”, “id”:20575, “ctx”:“main”,“msg”:“Error creating service context”,“attr”:{“error”:“Location5579201: Unable to acquire security key[s]”}}

Blockquote

Lastly, I followed URL: “https://www.mongodb.com/docs/manual/tutorial/deploy-replica-set-with-keyfile-access-control/

On a single Server itself, i am facing this Error

**Please Share the Proper Steps to Setup secure my installation **
I am using Rockylinux 9 server

You do because you are not sharing what we asked. We asked a few days ago the following:

We do not really want to know which guide you followed. We want to see the exact steps that you took. This is the only way we can see which steps you missed or did wrong.

Any reasons why you are not using Atlas?

Hi Saravanaprasad_k,

Could you check if a few lines above the message, you find something like “Permissions on {keyfile-path} are too open.”

If that’s the case, then you just need to set the mode:

chmod 400 {keyfile-path}

It is stated that the keyfile should not be group and world visible (hence need the 400 mode in Linux/Unix).

Let me know if this works.

1 Like

Hi @Daniel_Baktiar1

Thanks for Your Reply I have followed the below Steps Now Same Security Keyfile is Working for both Servers

Steps:

openssl rand -base64 756 > /var/lib/mongo/keyfile

chown mongod:mongod /var/lib/mongo/keyfile

chmod 400 /var/lib/mongo/keyfile

security:
authorization: enabled
keyFile: /var/lib/mongo/keyfile

systemctl restart mongod

systemctl status mongod

Status Failed Error Check Log
tail -f /var/log/mongodb/mongod.log

If Error on Socket File Remove that
rm /tmp/mongodb-27017.sock

Again Restart and Check Status its Work Status Shown as success

cd /var/lib/mongo/

Copy the Keyfile to Another Replication Server
scp keyfile root@hostname:/var/lib/mongo/

Check File Permission

ls -l /var/lib/mongo/keyfile

Check File Ownership

stat /var/lib/mongo/keyfile

The error is

but you mentioned

So it looks like one of the mongod configuration file specifies the wrong key file name.

Hi Steeve
This is Re-installed Configuration
On that time of Error I Removed Completely
After Fresh Installation its Works Properly

1 Like