keepalive+mongodb副本集集群搭建

[root@node2 local]# tar -zxvf keepalived-1.2.19.tar.gz
[root@node2 local]# cd keepalived-1.2.19
[root@node2 keepalived-1.2.19]# ./configure
root@node2 keepalived-1.2.19]# make
[root@node2 keepalived-1.2.19]# make install
[root@node2 ~]# cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
[root@node2 ~]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig
[root@node2 ~]# mkdir /etc/keepalived
[root@node2 ~]# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
[root@node2 ~]# cp /usr/local/sbin/keepalived /usr/sbin/
[root@node2 ~]# vi /etc/rc.local


#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.


touch /var/lock/subsys/local
/etc/init.d/keepalived start
[root@node2 ~]# vi /etc/keepalived/keepalived.conf 
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 55
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.200.16
        192.168.200.17
        192.168.200.18
        172.17.5.223
    }

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 55
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.200.16
        192.168.200.17
        192.168.200.18
        172.17.5.223

[root@node2 ~]# service keepalived start
[root@node2 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether b2:df:90:dc:bf:12 brd ff:ff:ff:ff:ff:ff
    inet 172.17.5.46/16 brd 172.17.255.255 scope global eth0
    inet 192.168.200.16/32 scope global eth0
    inet 192.168.200.17/32 scope global eth0
    inet 192.168.200.18/32 scope global eth0
    inet 172.17.5.223/32 scope global eth0
    inet6 fe80::b0df:90ff:fedc:bf12/64 scope link 
       valid_lft forever preferred_lft forever
  
taill -f /var/log/messages
  
  
  
  




config = { _id:"shared", members:[
... {_id:0,host:"172.17.1.46:27017"},
... {_id:1,host:"172.17.1.47:27017"},
... {_id:2,host:"172.17.1.48:27017"}]
... }














config = { _id:"shared1".members:[
... {_id:0,host:"172.17.5.46:27017"},
... {_id:1,host:"172.17.5.47:27017"},
... {_id:2,host:"172.17.5.48:27017"}]}
015-08-21T05:10:39.408-0400 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2015-08-21T05:10:39.408-0400 I CONTROL  [initandlisten] 
2015-08-21T05:10:39.409-0400 I CONTROL  [initandlisten] 
2015-08-21T05:10:39.409-0400 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2015-08-21T05:10:39.409-0400 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-08-21T05:10:39.409-0400 I CONTROL  [initandlisten] 
2015-08-21T05:10:39.409-0400 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-08-21T05:10:39.409-0400 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2015-08-21T05:10:39.409-0400 I CONTROL  [initandlisten] 
 禁用disable Transparent Huge Pages(THP) 三种配置方式
mongodb官网:THP在数据库工作负载下表现不佳,往往会有稀疏而不连续的内存访问模式。必须禁用THP对Linux机器运行使用,以确保MongoDB最佳的性能。
操作步骤:
修改/etc/grub.conf 
在kernel后增加transparent_hugepage=never
        kernel /vmlinuz-2.6.32-220.el6.x86_64 ro root=/dev/mapper/vg_odsmongodb1-lv_root rd_LVM_LV=vg_odsmongodb1/lv_swap rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD quiet SYSFONT=latarcyrheb-sun16
 rhgb crashkernel=auto rd_LVM_LV=vg_odsmongodb1/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM transparent_hugepage=neve




两台同时挂掉就不行了
[root@QA-5-44 ~]# mkdir -p /data/mongodb
[root@QA-5-44 ~]# cd /usr/local
[root@QA-5-44 local]# ls
bin  etc  games  include  lib  lib64  libexec  mongodb-linux-x86_64-rhel62-3.0.5.tgz  sbin  share  src
[root@QA-5-44 local]# tar -zxvf mongodb-linux-x86_64-rhel62-3.0.5.tgz -C /data/mongodb/
mongodb-linux-x86_64-rhel62-3.0.5/README
mongodb-linux-x86_64-rhel62-3.0.5/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-rhel62-3.0.5/GNU-AGPL-3.0
mongodb-linux-x86_64-rhel62-3.0.5/bin/mongodump
mongodb-linux-x86_64-rhel62-3.0.5/bin/mongorestore
mongodb-linux-x86_64-rhel62-3.0.5/bin/mongoexport
mongodb-linux-x86_64-rhel62-3.0.5/bin/mongoimport
mongodb-linux-x86_64-rhel62-3.0.5/bin/mongostat
mongodb-linux-x86_64-rhel62-3.0.5/bin/mongotop
mongodb-linux-x86_64-rhel62-3.0.5/bin/bsondump
mongodb-linux-x86_64-rhel62-3.0.5/bin/mongofiles
mongodb-linux-x86_64-rhel62-3.0.5/bin/mongooplog
mongodb-linux-x86_64-rhel62-3.0.5/bin/mongoperf
mongodb-linux-x86_64-rhel62-3.0.5/bin/mongod
mongodb-linux-x86_64-rhel62-3.0.5/bin/mongos
mongodb-linux-x86_64-rhel62-3.0.5/bin/mongo
[root@QA-5-44 local]# cd /data/mongodb
[root@QA-5-44 mongodb]# ls
mongodb-linux-x86_64-rhel62-3.0.5
[root@QA-5-44 mongodb]# mv mongodb-linux-x86_64-rhel62-3.0.5/ mongodb/
[root@QA-5-44 mongodb]# mkdir -p /data/mongodb/data
[root@QA-5-44 mongodb]# mkdir -p /data/mongodb/log
[root@QA-5-44 bin]# cat mongodb.conf  配置config这个文件的时候应该小心
port=27017
dbpath=/data/mongodb/data
logpath=/data/mongodb/log/mongodb.log
logappend=true
fork=true
maxConns=5000
replSet=shared1
[root@QA-5-49 bin]#  numactl --interleave=all /data/mongodb/mongodb/bin/mongod --config /data/mongodb/mongodb/bin/mongodb.conf
/data/mongodb/mongodb/bin/mongod: /usr/lib64/libssl.so.10: no version information available (required by /data/mongodb/mongodb/bin/mongod)
/data/mongodb/mongodb/bin/mongod: /usr/lib64/libcrypto.so.10: no version information available (required by /data/mongodb/mongodb/bin/mongod)
/data/mongodb/mongodb/bin/mongod: /usr/lib64/libcrypto.so.10: no version information available (required by /data/mongodb/mongodb/bin/mongod)
about to fork child process, waiting until server is ready for connections.
forked process: 1639
child process started successfully, parent exiting
[root@QA-5-44 bin]# ./mongo
MongoDB shell version: 3.0.5
connecting to: test
Server has startup warnings: 
2015-08-20T04:49:54.841-0400 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2015-08-20T04:49:54.841-0400 I CONTROL  [initandlisten] 
> config = { _id:"shared", members:[config = { _id:"shared", members:[
... ... {_id:0,host:"172.17.5.46:27017"},... {_id:0,host:"172.17.5.44:27017"},
... ... {_id:1,host:"172.17.5.47:27017"},... {_id:1,host:"172.17.5.45:27017"},
... ... {_id:2,host:"172.17.5.48:27017"}]... {_id:2,host:"172.17.5.59:27017"}]
... ... }... }
{
        "_id" : "shared1",
        "members" : [
                {
                        "_id" : 0,
                        "host" : "172.17.5.44:27017"
                },
                {
                        "_id" : 1,
                        "host" : "172.17.5.45:27017"
                },
                {
                        "_id" : 2,
                        "host" : "172.17.5.59:27017"
                }
        ]
}> rs.initiate(config);rs.initiate(config);  这一步应该检查各个服务器的防火墙和config的ip
{ "ok" : 1 }
shared1:OTHER> 
> shared1:PRIMARY> 
shared1:PRIMARY> 
shared1:PRIMARY> 
shared1:PRIMARY> use test;use test;
switched to db test
shared1:PRIMARY> db.test.insert({"test1":"testval1"})db.test.insert({"test1":"testval1"})
WriteResult({ "nInserted" : 1 })
shared1:PRIMARY>
 shared1:SECONDARY> use test;use test;
switched to db test
shared1:SECONDARY> show tables show tables;show tables;
2015-08-20T05:13:18.083-0400 E QUERY    Error: listCollections failed: { "note" : "from execCommand", "ok" : 0, "errmsg" : "not master" }
    at Error (<anonymous>)
    at DB._getCollectionInfosCommand (src/mongo/shell/db.js:646:15)
    at DB.getCollectionInfos (src/mongo/shell/db.js:658:20)
    at DB.getCollectionNames (src/mongo/shell/db.js:669:17)
    at shellHelper.show (src/mongo/shell/utils.js:625:12)
    at shellHelper (src/mongo/shell/utils.js:524:36)
    at (shellhelp2):1:1 at src/mongo/shell/db.js:646
shared1:SECONDARY> show tavvshow tavv
2015-08-20T05:13:31.347-0400 E QUERY    Error: don't know how to show [tavv]
    at Error (<anonymous>)
    at shellHelper.show (src/mongo/shell/utils.js:733:11)
    at shellHelper (src/mongo/shell/utils.js:524:36)
    at (shellhelp2):1:1 at src/mongo/shell/utils.js:733
shared1:SECONDARY> 
shared1:SECONDARY> show tables;show tables;
2015-08-20T05:13:36.290-0400 E QUERY    Error: listCollections failed: { "note" : "from execCommand", "ok" : 0, "errmsg" : "not master" }
    at Error (<anonymous>)
    at DB._getCollectionInfosCommand (src/mongo/shell/db.js:646:15)
    at DB.getCollectionInfos (src/mongo/shell/db.js:658:20)
    at DB.getCollectionNames (src/mongo/shell/db.js:669:17)
    at shellHelper.show (src/mongo/shell/utils.js:625:12)
    at shellHelper (src/mongo/shell/utils.js:524:36)
    at (shellhelp2):1:1 at src/mongo/shell/db.js:646
shared1:SECONDARY> db.getMongo().setSlaveOk();db.getMongo().setSlaveOk();
shared1:SECONDARY> db.testdb.find();db.testdb.find();
shared1:SECONDARY> db.testdb.find();db.testdb.find();
shared1:SECONDARY> show tables;show tables;
system.indexes
test
shared1:SECONDARY> user testuser test
2015-08-20T05:15:10.872-0400 E QUERY    SyntaxError: Unexpected identifier
shared1:SECONDARY> show tables;show tables;
system.indexes
test
shared1:SECONDARY> 


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29898569/viewspace-1778880/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29898569/viewspace-1778880/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值