十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
# update by csc 20170217
创新互联建站是一家专业提供成武企业网站建设,专注与网站设计制作、网站建设、H5技术、小程序制作等业务。10年已为成武众多企业、政府机构等服务。创新互联专业网站设计公司优惠进行中。
#opensystem centos 6.5 64 bit
tar -xvzf MongoDB-linux-x86_64-rhel62-3.4.2.gz -C /usr/local/
mv /usr/local/mongodb-linux-x86_64-rhel55-3.4.2 /usr/local/mongodb
echo 'export PATH=$PATH:/usr/local/mongodb/bin' >>/etc/profile
source /etc/profile
===============================
mkdir -p /data/mongodb/config/data
mkdir -p /data/mongodb/config/log
mkdir -p /data/mongodb/mongos/log
mkdir -p /data/mongodb/shard1/data
mkdir -p /data/mongodb/shard1/log
mkdir -p /data/mongodb/shard2/data
mkdir -p /data/mongodb/shard2/log
如果启动报警 则要配置;/
echo 0 > /proc/sys/vm/zone_reclaim_mode
echo never >/sys/kernel/mm/transparent_hugepage/enabled
echo never >/sys/kernel/mm/transparent_hugepage/defrag
cat >>/etc/rc.d/rc.local< echo 0 > /proc/sys/vm/zone_reclaim_mode echo never >/sys/kernel/mm/transparent_hugepage/enabled echo never >/sys/kernel/mm/transparent_hugepage/defrag EOF ############## 生产keyFile文件 (认证使用 --账户管理) #openssl rand -base64 753 copy 字符串到 /usr/local/mongodb/key chmod 600 /root/mobgodb/key 并把key文件复制到其他2节点的相同目录下 ################################ /usr/local/mongodb/bin/mongod --configsvr --replSet cfgReplSet --dbpath /data/mongodb/config/data --port 21000 --logpath /data/mongodb/config/log/config.log --fork --keyFile /usr/local/mongodb/key /usr/local/mongodb/bin/mongod --shardsvr --replSet shard1 --port 22001 --dbpath /data/mongodb/shard1/data --logpath /data/mongodb/shard1/log/shard1.log --fork --oplogSize 10000 --keyFile /usr/local/mongodb/key /usr/local/mongodb/bin/mongod --shardsvr --replSet shard2 --port 22002 --dbpath /data/mongodb/shard2/data --logpath /data/mongodb/shard2/log/shard2.log --fork --oplogSize 10000 --keyFile /usr/local/mongodb/key /usr/local/mongodb/bin/mongos --configdb cfgReplSet/192.168.1.15:21000,192.168.1.16:21000,192.168.1.17:21000 --port 30000 --logpath /data/mongodb/mongos/log/mongos.log --fork --keyFile /usr/local/mongodb/key ======================= mongo 192.168.1.15:21000 use admin config = { _id:"cfgReplSet", members:[ {_id:0,host:"192.168.1.15:21000"}, {_id:1,host:"192.168.1.16:21000"}, {_id:2,host:"192.168.1.17:21000"} ] } rs.initiate(config); ========================= mongo 192.168.1.15:22001 use admin config = { _id:"shard1", members:[ {_id:0,host:"192.168.1.15:22001",priority:2}, {_id:1,host:"192.168.1.16:22001",priority:1}, {_id:2,host:"192.168.1.17:22001",arbiterOnly:true} ] } rs.initiate(config); ======================== mongo 192.168.1.16:22002 use admin config = { _id:"shard2", members:[ {_id:0,host:"192.168.1.15:22002",priority:1}, {_id:1,host:"192.168.1.16:22002",priority:2}, {_id:2,host:"192.168.1.17:22002",arbiterOnly:true} ] } rs.initiate(config); ===================== mongo 192.168.1.15:30000 use admin 串联 - 增加 --路由服务器与分配副本集1 db.runCommand( { addshard : "shard1/192.168.1.15:22001,192.168.1.16:22001,192.168.1.17:22001"}); 串联 - 增加 --路由服务器与分配副本集2 db.runCommand( { addshard : "shard2/192.168.1.15:22002,192.168.1.16:22002,192.168.1.17:22002"}); ############################################# ##创建账户 mongos 192.168.1.15:30000 ##创建超级管理用户密码 root/12345 use admin db.createUser( { user: "root", pwd: "12345", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } ) ###查看 show users ########################################################## #创建 数据库的账户密码 portal/123456 数据库:WHTY_EDU_469026 use WHTY_EDU_469026 db.createUser( { user: "portal", pwd: "123456", roles: [ { role: "readWrite", db: "WHTY_EDU_469026" }, ] } ) ##### 查看 show users ############ 链接 方式1: # mongo -u portal -p 123456 127.0.0.1:30000/WHTY_EDU_469026 ########### 链接 方式2: use admin db.auth("portal","123456") #认证,返回1表示成功 #### 删除账户 用admin账户登入,然后 use 数据库 , 执行 db.dropuser("portal")
本文标题:mongodb3.4--2分片配置实验wiredTiger
链接地址:http://mswzjz.cn/article/pjcipj.html