[url]
http://blog.sina.com.cn/s/blog_48f9c0840100mmt1.html
[/url]
[root@jieshiyeskey ~]# lsb_release -a LSB Version: :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch Distributor ID: CentOS Description: CentOS release 5.5 (Final) Release: 5.5 Codename: Final [root@jieshiyeskey ~]# uname -m x86_64 [root@jieshi /var/db/mongodb]# uname -a FreeBSD jieshi.hapame.com.cn 8.1-RELEASE FreeBSD 8.1-RELEASE #0: Mon Jul 19 02:36:49 UTC 2010 [email protected]:/usr/obj/usr/src/sys/GENERIC amd64 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ [root@jieshi ~]# cd /usr/ports/databases/mongodb/ [root@jieshi /usr/ports/databases/mongodb]# make install clean [root@jieshi ~]/usr/local/etc/rc.d/mongod onestart #首次启动 [root@jieshi ~]# cat /etc/rc.conf mongod_enable="YES" #加入参数后,重启就可以用Usage: /usr/local/etc/rc.d/mongod [fast|force|one](start|stop|restart|rcvar|status|poll) [root@jieshiyeskey ~]# cat /etc/yum.repos.d/markgeng.repo [10gen] name=10gen Repository baseurl=http://downloads.mongodb.org/distros/centos/5.4/os/x86_64/ gpgcheck=0 [root@jieshiyeskey ~]# yum -y install mongo-stable* [root@jieshiyeskey ~]# /etc/init.d/mongod start Starting mongod: all output going to: /var/log/mongo/mongod.log forked process: 5028 [ OK ] [root@jieshiyeskey ~]# netstat -an |grep 27017 tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN unix 2 [ ACC ] STREAM LISTENING 13236 /tmp/mongodb-27017.sock [root@jieshiyeskey ~]# ps -ef|grep mongod mongod 5028 1 0 14:23 ? 00:00:00 /usr/bin/mongod -f /etc/mongod.conf root 5091 4836 0 14:25 pts/0 00:00:00 grep mongod 在mongoDB 主服务器(linux)的配置如下: [root@markgneg ~]# vim /etc/mongod.conf master = true source = 192.168.16.103,192.168.16.216 (从服务器上的IP) oplogSize = 64 [root@markgneg ~]# /etc/init.d/mongod restart Stopping mongod: [ OK ] Starting mongod: all output going to: /var/log/mongo/mongod.log forked process: 6601 [ OK ] 在mongoDB 从服务1(linux)上配置如下: [root@jieshiyeskey ~]# vim /etc/mongod.conf slave = true source = 192.168.16.205 #主服务器的IP地址 only = test #指仅仅复制此数据库 在mongoDB 从服务2(freebsd)上配置如下: [root@jieshi ~]# cat /usr/local/etc/mongodb.conf slave=true source=192.168.16.205 #主服务器的IP地址 only=test #指仅仅复制此数据库 [root@jieshiyeskey ~]# /etc/init.d/mongod restart Stopping mongod: [ OK ] Starting mongod: all output going to: /var/log/mongo/mongod.log forked process: 5461 测试: 在主服务器上: [root@markgneg ~]# mongo MongoDB shell version: 1.6.4 connecting to: test > db.foo.save({"id":110,"name":'jieshichina'}) > db.foo.find({"id":110}) { "_id" : ObjectId("4cda3f97eec444f3184d8e09"), "id" : 110, "name" : "jieshichina" } 在从服务器上1(linux): [root@jieshiyeskey ~]# mongo MongoDB shell version: 1.6.4 connecting to: test > db.foo.find({"id":110}) { "_id" : ObjectId("4cda3f97eec444f3184d8e09"), "id" : 110, "name" : "jieshichina" } 在从服务器2上(freebsd) [root@jieshi ~]# mongo MongoDB shell version: 1.6.3 connecting to: test > db.foo.find({"id":110}) { "_id" : ObjectId("4cda3f97eec444f3184d8e09"), "id" : 110, "name" : "jieshichina" } > exit
参考:
https://github.com/erh/mongo-jdbc http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart http://code.google.com/p/morphia/wiki/Datastore