def stop(): """Stops Mongodb""" mongo_nodes = addresses()['db_public_ip'] config_server = addresses()['man_public_ip'] execute(stop_mongod, hosts=mongo_nodes) execute(stop_mongos, hosts=mongo_nodes) execute(stop_config_server, hosts=config_server)
def start(): """Runs MongoDB""" mongo_nodes = addresses()['db_public_ip'] config_server = addresses()['man_public_ip'] print 'stopping mongo first...' stop() print 'Installing & Starting Mongod/Mongos on hosts: %s' % mongo_nodes print 'Installing & Starting Config Server on hosts: %s' % config_server print emphasis('changing configuration') execute(change_mongod_conf, hosts=mongo_nodes) print emphasis('starting config server') execute(start_mongo_config_server, hosts=config_server) print emphasis('starting mongod') execute(start_mongod, hosts=mongo_nodes) print emphasis('starting mongos') execute(start_mongos, hosts=mongo_nodes) print emphasis('configuring sharding') execute(configure_sharding, hosts=mongo_nodes[0]) print '********Mongo is running********'
def make_substitutions(base, yaml): seed = addresses()['db_private_ip'][0] index = addresses()['db_public_ip'].index(env.host_string) host_internal_ip = addresses()['db_private_ip'][index] _commit_log_dir, _data_dir = prepare_directories() with open(yaml, "wt") as fout: with open(base, "rt") as fin: for line in fin: line = line.replace('seeds: "127.0.0.1"', 'seeds: "%s"' % seed) line = line.replace('listen_address: localhost', 'listen_address: %s' % host_internal_ip) line = line.replace( '# broadcast_rpc_address: 1.2.3.4', 'broadcast_rpc_address: %s' % host_internal_ip) if use_instance_store: line = line.replace( 'commitlog_directory: /var/lib/cassandra/commitlog', 'commitlog_directory: %s' % _commit_log_dir) line = line.replace(' - /var/lib/cassandra/data', ' - /%s' % _data_dir) fout.write(line) fout.write("\nauto_bootstrap: false")
def install(): print 'Installing Cassandra on hosts: %s' % addresses()['db_public_ip'] execute( # install in parallel _install, hosts=addresses()['db_public_ip']) execute(_configure, hosts=addresses()['db_public_ip']) print '********Cassandra is installed********'
def start_mongos(): config_server = addresses()['man_public_ip'][0] sudo("killall -q mongos", warn_only=True) sudo( 'echo "mongos --configdb %s:27027 --port 27028 >/var/log/mongodb/mongos.log 2>/var/log/mongodb/mongos-err.log" | at now' % config_server) wait_for_connection('localhost:27028') print 'succeeded in connecting to mongos'
def configure_sharding(): mongods = addresses()['db_private_ip'] url = 'localhost:27028/ycsb' for mongod in mongods: run_mongo_shell(url, 'sh.addShard(\'%s:27017\')' % mongod, acceptable_error='host already used') run_mongo_shell(url, 'sh.enableSharding(\'ycsb\')', acceptable_error='already enabled') run_mongo_shell( url, 'sh.shardCollection(\'ycsb.usertable\', { \'_id\': \'hashed\' })', acceptable_error='already sharded') run_mongo_shell(url, 'db.usertable.remove({})', check_return_code=False)
def install(): execute(install_mongodb, hosts=addresses()['db_public_ip'] + addresses()['man_public_ip'])