After reading the mongodb authoritative guide, it is more appropriate to use the replica set for read/write splitting, and the general system is enough to use it.
It is easy to find. If you do not describe it, you can only describe the key steps.
The two servers are 201 and 202 nodes, the two are initially configured on 202, and the other is added on 201.
Deploy two nodes first
202:
./Mongod -- dbpath./db1 -- port 10002 -- replSet blort/Server202: 10001
./Mongod -- dbpath./db -- port 10001 -- replSet blort/Server202: 10002
./Mongo Server202: 10001/admin
Db. runCommand ({"replSetInitiate": {"_ id": "blort", "members": [{"_ id": 1, "host": "Server202: 10001 "},{" _ id ": 2," host ":" Server202: 10002 "}]})
Db. _ adminCommand ("replSetGetStatus ");
Add a node
201:
./Mongod -- dbpath./db -- port 10001 -- replSet blort/Server202: 10002
202:
Rs. add ("Server201: 10002 ");
By default, the slave database cannot be queried. Execute the following statement to make the current slave database available for query and share the query load of the master database.
Db. getMongo (). setSlaveOk ()
The random machine automatically starts the script at/etc/rc. local.
Rm-rf/home/aircom/mongodb-linux-i686-2.0.6/bin/db/*. lock
Rm-rf/home/aircom/mongodb-linux-i686-2.0.6/bin/db1/*. lock
/Home/aircom/mongodb-linux-i686-2.0.6/bin/mongod -- dbpath/home/aircom/mongodb-linux-i686-2.0.6/bin/db -- port 10001 -- replSet blort/Server202: 10002 -- fork -- logpath/home/aircom/mongodb-linux-i686-2.0.6/bin/log/1001.log
/Home/aircom/mongodb-linux-i686-2.0.6/bin/mongod -- dbpath/home/aircom/mongodb-linux-i686-2.0.6/bin/db1 -- port 10002 -- replSet blort/Server202: 10001 -- fork -- logpath/home/aircom/mongodb-linux-i686-2.0.6/bin/log/1002.log
Modify the configuration, such as modifying the priority. You can use the priority to control the Tianji
Conf = rs. conf ()
Conf. members [0]. priority = 3
Conf. members [1]. priority = 2
Conf. members [2]. priority = 1
Conf. members [3]. priority = 0.5
Rs. reconfig (conf)