### mongodb的主从配置(不带auth认证)
创新互联建站是一家专注于成都做网站、网站制作、
成都外贸网站建设与策划设计,西充网站建设哪家好?
创新互联建站做网站,专注于网站建设10余年,网设计领域的专业建站公司;建站业务涵盖:西充等地区。西充做网站价格咨询:13518219792
### 注意事项:
- 服务器节点之前时间要同步
- 开启防火墙的一定要允许通过相关端口
- 开启selinux的也要进行设置
- 建立双击互信模式最好不过
### master配置文件
[root@blog ~]# sed -e '/^#/d;/^$/d' /etc/mongodb.conf
bind_ip = 192.168.58.10
port = 27017
fork = true
pidfilepath = /var/run/mongodb/mongodb.pid
logpath = /var/log/mongodb/mongodb.log
dbpath =/mongo/data
journal = true
master = true
nohttpinterface = true
[root@blog ~]#
### slave配置文件
- slave = true
- source = 192.168.58.10:27017
[root@redis ~]# sed -e '/^#/d;/^$/d' /etc/mongodb.conf
bind_ip = 192.168.58.30
port = 27017
fork = true
pidfilepath = /var/run/mongodb/mongodb.pid
logpath = /var/log/mongodb/mongodb.log
dbpath =/var/lib/mongodb
journal = true
nohttpinterface = true
slave = true
source = 192.168.58.10:27017
[root@redis ~]#
### 重启两节点的mongodb服务进行初始化操作并验证数据同步情况
[root@blog ~]#
[root@blog ~]# hostname
blog.unix178.com
[root@blog ~]# mongo
MongoDB shell version: 2.4.6
connecting to: test
> show dbs
admin0.203125GB
local10.0732421875GB
test0.203125GB
zhuima0.203125GB
>
[root@redis ~]# hostname
redis.unix178.com
[root@redis ~]# mongo
MongoDB shell version: 2.4.6
connecting to: test
> show dbs
admin0.203125GB
local0.078125GB
zhuima0.203125GB
>
### 查看同步情况
[root@blog ~]# mongo 192.168.58.30
MongoDB shell version: 2.4.6
connecting to: 192.168.58.30/test
> show dbs
admin0.203125GB
local0.078125GB
nick0.203125GB
test0.203125GB
zhuima0.203125GB
>
[root@redis ~]# mongo 192.168.58.10
MongoDB shell version: 2.4.6
connecting to: 192.168.58.10/test
> show dbs;
admin0.203125GB
local10.0732421875GB
nick0.203125GB
test0.203125GB
zhuima0.203125GB
>
### 添加新的数据进行验证
[root@redis ~]# mongo 192.168.58.10
MongoDB shell version: 2.4.6
connecting to: 192.168.58.10/test
> show dbs;
admin0.203125GB
local10.0732421875GB
nick0.203125GB
test0.203125GB
zhuima0.203125GB
> use nick
switched to db nick
> use newdb
switched to db newdb
> db.newdb.insert({new:"yes",info:"nothing"})
> show collections
newdb
system.indexes
> db.newdb.find()
{ "_id" : ObjectId("53cbd4b35974b01658718b2d"), "new" : "yes", "info" : "nothing" }
>
[root@blog ~]# mongo 192.168.58.30
MongoDB shell version: 2.4.6
connecting to: 192.168.58.30/test
> show dbs
admin0.203125GB
local0.078125GB
nick0.203125GB
test0.203125GB
zhuima0.203125GB
> show dbs
admin0.203125GB
local0.078125GB
newdb0.203125GB
nick0.203125GB
test0.203125GB
zhuima0.203125GB
> use newdb
switched to db newdb
> show collections
newdb
system.indexes
> db.newdb.find()
{ "_id" : ObjectId("53cbd4b35974b01658718b2d"), "new" : "yes", "info" : "nothing" }
>
### 后记
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
当前文章:mongodb之master/slave模式-创新互联
路径分享:
http://cdxtjz.com/article/jgjos.html