Project objectives: automatic failover and automatic repair of member nodes, the data between each database is exactly the same.
Item Description: The replica set does not have a fixed master node and is a master node that is elected by the entire cluster and changes other nodes when it does not work. The smallest replica set should also have a primary node and two secondary nodes. A replica set of two nodes does not have a true failover capability. All secondary are down, or only one node in the replica set, then the node can only be secondary node, it means that the entire cluster intelligent read operation and cannot write operation, when the other recovery, the previous primary node is still primary node
Project Environment: Three server RHEL6.5
Keepalived-1.2.7.tar.gz
Mongodb-linux-x86_64-2.4.9.tgz
Note: replica sets differ greatly from master to slave, but the installation process is the same.
First, download keepalived and MongoDB source package
http://yunpan.cn/cLnMGSt7v2X4s Access Password 956a
Second, installation keepalived
[Email protected] ~]yum-y install gccopenssl-devel popt popt-devel LIBNL libnl-devel Kernel-dev El #所需依赖包
[Email protected]~]# tar-zxvf keepalived-1.2.7.tar.gz
[[Email protected]~]# CD keepalived-1.2.7.tar.gz
[Email protected]]#./configure #安装三部曲
[[Email protected]]# make
[[Email protected]]# make install
Iii. Copy configuration files and startup scripts
[[Email protected]~]# cp/usr/local/etc/rc.d/init.d/keepalived/etc/rc.d/init.d/
[[Email protected]~]# cp/usr/local/etc/sysconfig/keepalived/etc/sysconfig
[[Email protected]~]# mkdir/etc/keepalived
[[Email protected]~]# cp/usr/local/etc/keepalived/keepalived.conf/etc/keepalived/
[[Email protected]~]# cp/usr/local/sbin/keepalived/usr/sbin/
Iv. Adding boot-up
[Email protected]~] #chkconfig--add keepalived #添加服务
[Email protected]~] #chkconfig keepalived on #开机启动
V. Configuration files
[Email protected]~] #cat/etc/keepalived/keepalived.conf
! Configuration File for Keepalived
vrrp_instancemg_1 {
State BACKUP #三台全为BACKUP
Interfaceeth 0
VIRTUAL_ROUTER_ID 55
Priority #其中两台优先级为100, the last one is 90
Advert_int 1
#nopreempt #不抢占资源
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
192.168.0.10 #虚拟IP
}
}
vi. [[Email protected] ~]# service keepalived start
Starting keepalived: [OK]
Seven or more configurations, of which two are identical, the last priority set to 90, and set to not preempt resources.
Eight, the command IP A can view the virtual IP, successful display virtual IP.
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/76/52/wKiom1ZO8xTDFHGXAAB2ZwU816M294.png "title=" QQ picture 20151120181630.png "alt=" Wkiom1zo8xtdfhgxaab2zwu816m294.png "/>
Ix. installation of MongoDB
[Email protected] ~]# tar-zxvfmongodb-linux-x86_64-2.4.9.tgz-c/usr/local/
[Email protected] local]# MV Mongodb-linux-x86_64-2.4.9/mongodb
[Email protected] local]# CD mongodb/
[[email protected] mongodb]# mkdir DB
[Email protected] mongodb]# mkdir logs
[[Email protected] mongodb]# CD bin
[email protected] bin]# cat mongodb.conf
dbpath=/usr/local/mongodb/db #数据存放路径
Logpath=/usr/local/mongodb/logs/mongodb.log
port=27017
Fork=true #以守护进程的方式运行MongoDB
Nohttpinterface=true #禁止HTTP状态接口默认情况下Mongodb Running the HTTP interface on port 28017
maxconns=5000 #最大同时连接数
Replset=mongodb #同一副本集, must
#shardsvr =true #启动分片
X. Start MongoDB
[Email protected]]# numactl--interleave=all/usr/local/mongodb/bin/mongod--config/us R/local/mongodb/bin/mongodb.conf
xi. [[email protected] bin]# VIM/ETC/BASHRC
Path=/usr/local/mongodb/bin: $PATH # add command path
[Email protected] bin]# SOURCE/ETC/BASHRC
[Email protected] ~]# vim/etc/rc.local
Numactl--interleave=all/usr/local/mongodb/bin/mongod--config/usr/local/mongodb/bin/mongodb.conf # append command, boot start
12. Enter the database and configure the replica set server
[[Email protected] ~] #mongo #进入mongodb
MongoDB Shell version:2.4.9
Connecting To:test
> config = {_id: "MongoDB", members:[
... {_id:0,host: "192.168.0.100:27017", priority:10},
... {_id:1,host: "192.168.0.200:27017", priority:10},
... {_id:2,host: "192.168.0.5:27017", Priority:5}]
...}
>rs.initiate (config); #初始化副本集配置
>rs.reconfig (CFG); #重新加载配置文件
13. If you want to increase the server executable command
>rs.add ({"_id": 3, "host": "192.168.0.300:27017"})
14, have virtual IP, executable command
[[Email protected] ~] #mongo 192.168.0.10 #进入数据库, IP is virtual
XV, the above configuration if executed, there is an error message, please own Baidu. I have successfully configured it.
This article from the "System operation and maintenance of the road" blog, declined reprint!
MongoDB Replica Set