测试架构:
测试目的:
测试一个config server 服务器挂机后,集群是否能读写数据。
测试原因:
上周因为内存吃紧,准备添加内存。在查看服务器时,把一台服务器关机检查。
关机后,web 端应用出错,用户无法登录,所有都出错。
但在我理解,因为config是3台冗余的,一台关机,应该不会产生影响才对,或者说不会影响到无法
登录,应用不能正常运行。只是会有数据不均衡啊。
但我使用mongochef 登录,确实登录数据库不成功。
测试结果:
经下面的测试,印证了我的理解,一台config 宕机,只是会提示连接config 出错,
但能登录数据库,插入数据的代码(mongo -port 28000 登录后运行的js 代码),还能正常运行下去。
但为什么当时web 端会出错,我看到他们php 配置文件中如下:
$connect = new mongoclient("mongodb://192.168.2.188:28000,192.168.2.132:28000", array("replicaset" => "myreplset"));
却没加mongoconnectionexception。 容错出错没有的话,当正在操作时,一个collection打开出错,不会再重新连接数据库,
就报错了。如果这时能重新连接数据库,应该能再找到另外正常的节点连接的。
测试环境为: mongodb3.0.3
2个shard,3个配置config,3个mongos
set host:port statestr
————————————————————
shard1 192.168.2.188:28011 primary
shard1 192.168.2.132:28011 secondary
shard1 192.168.2.134:28011 secondary
shard2 192.168.2.188:28012 secondary
shard2 192.168.2.132:28012 secondary
shard2 192.168.2.134:28012 primary
——————————————————————–
192.168.2.188:28010 config
192.168.2.188:28000 mongos
192.168.2.132:28010 config
192.168.2.132:28000 mongos
192.168.2.134:28010 config
192.168.2.134:28000 mongos
#备用服务器,当134挂机后,把134 对应的t3 服务器名称修改为 135
192.168.2.135:28010 config
各服务器的hosts 文件:
[root@localhost bin]# cat /etc/hosts
192.168.2.188 t1
192.168.2.132 t2
192.168.2.134 t3
192.168.2.135 t4
一、配置集群:
初始化replica set shard1
用mongo 连接其中一个节点: 比如:shard11 执行以下:
> config = {_id: \\\’shard1\\\’, members: [
{_id: 0, host:\\\’t1:28011\\\’}]
}
> rs.initiate(config);
rs.add({_id: 1, host:\\\’t2:28011\\\’})
rs.add({_id: 2, host:\\\’t3:28011\\\’})
初始化replica set shard2
用mongo 连接其中一个节点: 比如:shard11 执行以下:
> config = {_id: \\\’shard2\\\’, members: [
{_id: 0, host:\\\’t1:28012\\\’}]
}
> rs.initiate(config);
rs.add({_id: 1, host:\\\’t2:28012\\\’})
rs.add({_id: 2, host:\\\’t3:28012\\\’})
#遇到如下错误
shard2:primary> rs.add({_id: 1, host:\\\’t2:28012\\\’})
{
"ok" : 0,
"errmsg" : "quorum check failed because not enough voting nodes responded; required 2 but only the following 1 voting nodes responded: t1:28012; the following nodes did not respond affirmatively: t2:28012 failed with failed attempt to connect to t2:28012; couldn\\\’t connect to server t2:28012 (192.168.2.132), connection attempt failed",
"code" : 74
}
#原因:有防火墙
#关闭防火墙
[root@t2 ~]# chkconfig iptables off
[root@t2 ~]# service iptables stop
iptables:清除防火墙规则: [确定]
iptables:将链设置为政策 accept:nat mangle filter [确定]
iptables:正在卸载模块: [确定]
[root@t2 ~]#
二、配置分片
1:配置一下时间一致,不然无法建立分片集群:
*/5 * * * * /usr/sbin/ntpdate -u ntp.sjtu.edu.cn
2.mongos 运行时的参数如下:
/opt/mongodb3.0.3/bin/mongos –configdb t1:28010,t2:28010,t3:28010 –port 28000 –logpath /opt/mongodb3.0.3/logs/mongos.log –logappend –fork
3.连接到其中一个mongos进程,并切换到admin数据库做以下配置
3.1. 连接到mongs,并切换到admin
./mongo 192.168.20.11:28000/admin
>db
admin
3.2. 加入shards
命令格式:
replicasetname/[:port] [,serverhostname2[:port],…]
执行如下:
>use admin;
>db.runcommand({addshard:"shard1/t1:28011,t2:28011,t3:28011"});
>db.runcommand({addshard:"shard2/t1:28012,t2:28012,t3:28012"});
添加分片后,把chunksize 改成 1m,以方便测试
>use config
mongos> db.shards.find()
{ "_id" : "shard1", "host" : "shard1/t1:28
7z文件用什么打开 压缩包后缀7z怎么打开云南服务器机柜报价购买域名太慢-其他问题电脑中玩足球小将:新秀崛起经常闪退怎么办 电脑中玩足球小将:新秀崛起经常闪退如何修复阿里云服务器怎么查看网页日志cn域名注意事项有哪些?SEO优化中要努力克服的一些难题黑帽SEO主要是有哪些作弊手法呢?