When you run your shell script to you get any errors?
Having this in a shell script works just fine for me to init a three node replica set running locally on my Mac:
mongo --host 127.0.0.1 --port 27017 --eval 'rs.initiate({_id: "testing", members: [{_id: 0, host: "127.0.0.1:27017", priority: 2}, {_id: 1, host: "127.0.0.1:27018"}, {_id: 2, host: "127.0.0.1:27019"}]})'
Make sure to replace the host IP with your machine’s IP and testing with the actual name of your replicaSet (the same value you used on in the mongod --replSet testiing
value. Make sure that all machines have port 27017 open up to each other and to the machine running the script (if it’s not one of the machines in the replica set). This should be the case since you can do it manually inside of the mongo
shell, but something you will want to check.
You will want to check the MongoDB logs
grep mongologfile | grep REPL
Replace mongologfile
with the path and file name of your log. Any replication operations will have the term REPL in the log line. You should see a lot of these as the replica set initializes and elections are performed.
If none of that is happening, then I’m not sure what’s going on. Without having logs it’s hard to troubleshoot.