MongoDB Master-Slave environment construction

Source: Internet
Author: User
Tags auth

MongoDB is a product between a relational database and a non-relational database, and is the most versatile and most like relational database in a non-relational database. The data structure he supports is very loose and is a JSON-like Bson format, so you can store more complex data types. MONGO's biggest feature is that the query language he supports is very powerful, and its syntax is a bit like an object-oriented query language that almost implements most of the functionality of a relational database single-table query, and also supports indexing of data.

It is characterized by high performance, easy to deploy, easy to use, and easy to store data. The main features are:

* For collection storage, easy to store object type data.

* Free mode.

* Support Dynamic Query.

* Full index support, including internal objects.

* Support Query.

* Supports replication and recovery.

* Use efficient binary data storage, including large objects (such as video, etc.).

* Automatically handles fragmentation to support scalability at the cloud level.

* Support multiple languages such as ruby,python,java,c++,php,c#.

* File storage format is Bson (an extension of JSON).

* Can be accessed via the Internet. ----------------the above content from the good search encyclopedia

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 # Add service

[[email protected]~] #chkconfig keepalived on # boot up

v. configuration files

[Email protected]~] #cat/etc/keepalived/keepalived.conf

! Configuration File for Keepalived

vrrp_instancemg_1 {

State MASTER #mongodb2为BACKUP

Interfaceeth 0

VIRTUAL_ROUTER_ID 55

Priority #优先级, Backup 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, above configuration, in addition to the configuration file from the server in the small difference, the other content is exactly the same!

Eight, the command IP A can view the virtual IP, successful display virtual IP.

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

Nohttpinterface=true

Master=true #主服务器

Auth=true #开启用户验证

X. From the server configuration file

[email protected] bin]# cat mongodb.conf

dbpath=/usr/local/mongodb/db

Logpath=/usr/local/mongodb/logs/mongodb.log

port=27017

Fork=true

Nohttpinterface=true

Slave=true #从服务器

source=192.168.0.100:27017 #从主服务器复制

Autoresync=true #自动同步

Auth=true

Xi. Start MongoDB (two sets are started)---command path can be added in BASHRC, if not, please Baidu, Baidu, please find your boss.

[Email protected] bin]/usr/local/mongodb/bin/mongod-f/usr/local/mongodb/bin/mongodb.conf

12, error message: When viewing from the server MongoDB log display the following information, if you are in the configuration process without authentication users, master-Slave construction success, please ignore the error, if it is other error, please Baidu.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/76/50/wKiom1ZO3pex_LgIAAB80hnPgco952.png "title=" QQ picture 20151120164901.png "alt=" Wkiom1zo3pex_lgiaab80hnpgco952.png "/>

13, after several twists and turns, to find the reasons for the two user authentication.

[Email protected] Bin]/usr/local/mongodb/bin/mongo #进入数据库

>use Local

>db.adduser (' reql ', ' reql ')

After the user authentication, from the server connected to the primary server, display OK, but after OK display errmsg:unauthorized, this is not authorized

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/76/4F/wKioL1ZO4SzwK7goAABGU1pJbzQ174.png "title=" QQ picture 20151120165647.png "alt=" Wkiol1zo4szwk7goaabgu1pjbzq174.png "/>

14, after analysis, the general user authentication permission is small, so then the Administrator account authentication. (authentication only on the primary server) Note: Auth=true in the configuration file, please comment out and restart MongoDB

[Email protected] Bin]/usr/local/mongodb/bin/mongo #进入数据库

>use Admin

>db.adduser (' Tank ', ' test ')

>db.auth (' Tank ', ' test ') #数据库认证, must do




This article from the "System operation and maintenance of the road" blog, declined reprint!

MongoDB Master-Slave environment construction

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.