您好,登錄后才能下訂單哦!
# update by csc 20170217
#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<<EOF
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")
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。