You use the hostname linux command to determine the hostname.
Example: hostname = test.hostname.com
mkdir /tmp/mongo1
mkdir /tmp/mongo2
mkdir /tmp/mongo3
mongod –port 27021 –dbpath /tmp/mongo1 –fork –logpath /tmp/mongod1.log –replSet rs0
mongod –port 27022 –dbpath /tmp/mongo2 –fork –logpath /tmp/mongod2.log –replSet rs0
mongod –port 27023 –dbpath /tmp/mongo3 –fork –logpath /tmp/mongod3.log –replSet rs0
rsconf = {
_id: “rs0”,
members: [
{
_id: 0,
host: “test.hostname.com:27021”
}
]
}
rs.initiate( rsconf );
rs.conf();
rs.add(“test.hostname.com:27022”);
rs.add(“test.hostname.com:27023”);
rs.status();
Other mongo commands:
db.printSlaveReplicationInfo()
In order to read from the secondaries, you need to run slaveOk. Otherwise:
Thu Feb 26 16:05:19 uncaught exception: count failed: { “errmsg” : “not master”, “ok” : 0 }
SECONDARY> rs.slaveOk()