Skip to content

Instantly share code, notes, and snippets.

@lxj5891
Last active August 29, 2015 14:04
Show Gist options
  • Save lxj5891/0828208aecc6eef7d8e6 to your computer and use it in GitHub Desktop.
Save lxj5891/0828208aecc6eef7d8e6 to your computer and use it in GitHub Desktop.

Mongo触发器

=========================

环境搭建

  • db:10.2.9.104    root/ssmartdb
  • db:10.2.9.105    root/ssmartdb
  • db:10.2.9.106    root/ssmartdb
  • db:10.2.9.107    root/ssmartdb

epel源

wget http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm

Install

  • Create a /etc/yum.repos.d/mongodb.repo file to hold the following configuration information for the MongoDB repository:
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
yum install mongodb-org

mkdir -p /data/db
rm -rf /data/db
mongod --dbpath /data/db --logpath=/tmp/mongdb.log --replSet repset --smallfiles


mongod --dbpath /data/db --replSet repset --smallfiles
git clone https://github.com/exabugs/MongoTrigger.git
  • 配置mongo
mkdir -p /data/test/config/db/
mkdir -p /data/test/config/log/
mkdir -p /data/test/mongos/log/
mkdir -p /data/test/shard1/db/
mkdir -p /data/test/shard1/log/
mkdir -p /data/test/shard2/db/
mkdir -p /data/test/shard2/log/

mongod --configsvr --dbpath /data/test/config/db --port 21000 --logpath /data/test/config/log/config.log --fork

mongos --configdb 10.2.9.104:21000,10.2.9.105:21000,10.2.9.106:21000 --port 20000 --logpath /data/test/mongos/log/mongos.log --fork

mongod --shardsvr --replSet repset1 --port 22001 --dbpath /data/test/shard1/db --logpath /data/test/shard1/log/shard1.log --fork

mongod --shardsvr --replSet repset2 --port 22002 --dbpath /data/test/shard2/db --logpath /data/test/shard2/log/shard2.log --fork

use admin
var config = { _id : "repset1" , members : [
{_id : 0 , host :"10.2.9.104:22001" , priority : 100}, 
{_id :1  , host :"10.2.9.105:22001" , priority : 90},
{_id :2  , host :"10.2.9.106:22001" , arbiterOnly: true},
{_id :3  , host :"10.2.9.107:22001" , priority:0, buildIndexes: false}
]};
rs.initiate(config);

use admin
var config = { _id : "repset2" , members : [
{_id : 0 , host : "10.2.9.104:22002" , priority : 100}, 
{_id :1 , host :"10.2.9.105:22002" , priority : 90},
{_id :2 , host :"10.2.9.106:22002" , arbiterOnly: true},
{_id :3 , host :"10.2.9.107:22002" , priority:0, buildIndexes: false}
]};
rs.initiate(config);



mongo 127.0.0.1:20000

use admin;

db.runCommand({addshard : "repset1/10.2.9.104:22001,10.2.9.105:22001,10.2.9.106:22001,10.2.9.107:22001"});

db.runCommand({addshard : "repset2/10.2.9.104:22002,10.2.9.105:22002,10.2.9.106:22002,10.2.9.107:22002"});

db.runCommand( { listshards : 1 } );

db.runCommand({enableSharding:"test"});

//查看分片状态
db.getSiblingDB("config").shards.find()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment