MongoDB複製集之:安裝部署

來源:互聯網
上載者:User
準備工作

軟體環境

OS:Oracle Linux 6.5

MongoDB:mongodb3.2.3

 

部署架構

類比有三台伺服器

10.1.5.123:28001 主節點

10.1.5.123:28002 從節點

10.1.5.123:28003 選舉節點

 

複製集架構:一主,一從,一選舉節點

 

下載安裝

下載地址:https://www.mongodb.org/downloads

mongodb-linux-x86_64-rhel62-3.2.3.tgz

  部署步驟 1.建立目錄及使用者

[root@devtest mongodb]# mkdir conf data log

[root@devtest data]# mkdir 28001 28002 28003

--建立mongo使用者

[root@devtest conf]# groupadd mongod

[root@devtest conf]# useradd -g mongod mongod

  2.建立設定檔

--配置三個執行個體的設定檔(修改相應的連接埠號碼即可)

--節點1

$ vi /home/mongod/mongodb3.2.3/conf/28001.conf

port=28001

bind_ip=10.1.5.123

logpath=/home/mongod/mongodb3.2.3/log/28001.log

dbpath=/home/mongod/mongodb3.2.3/data/28001/

logappend=true

pidfilepath=/home/mongod/mongodb3.2.3/data/28001/28001.pid

fork=true

oplogSize=1024

replSet=MyMongo

 

--節點2

$ vi /home/mongod/mongodb3.2.3/conf/28002.conf

port=28002

bind_ip=10.1.5.123

logpath=/home/mongod/mongodb3.2.3/log/28002.log

dbpath=/home/mongod/mongodb3.2.3/data/28002/

logappend=true

pidfilepath=/home/mongod/mongodb3.2.3/data/28002/28002.pid

fork=true

oplogSize=1024

replSet=MyMongo

 

--節點3

$ vi /home/mongod/mongodb3.2.3/conf/28003.conf

port=28003

bind_ip=10.1.5.123

logpath=/home/mongod/mongodb3.2.3/log/28003.log

dbpath=/home/mongod/mongodb3.2.3/data/28003/

logappend=true

pidfilepath=/home/mongod/mongodb3.2.3/data/28003/28003.pid

fork=true

oplogSize=1024

replSet=MyMongo

  3.啟動mongo複製集

$ mongod -f /home/mongod/mongodb3.2.3/conf/28001.conf

$ mongod -f /home/mongod/mongodb3.2.3/conf/28002.conf

$ mongod -f /home/mongod/mongodb3.2.3/conf/28003.conf

  4.初始化複製集

[mongod@devtest ~]$ mongo 10.1.5.123:28001/admin

MongoDB shell version: 3.2.3

connecting to: 10.1.5.123:28001/admin

Welcome to the MongoDB shell.

For interactive help, type"help".

For more comprehensive documentation, see

        http://docs.mongodb.org/

Questions? Try the support group

       http://groups.google.com/group/mongodb-user

> db

admin

> config = {

... "_id":"MyMongo",

... members:[

...{"_id":0,host:"10.1.5.123:28001"},

...{"_id":1,host:"10.1.5.123:28002"},

... {"_id":2,host:"10.1.5.123:28003"}]

... }

{

       "id" : "MyMongo",

       "members" : [

                {

                        "_id" : 0,

                        "host" :"10.1.5.123:28001"

                },

                {

                        "_id" : 1,

                        "host" :"10.1.5.123:28002"

                },

                {

                        "_id" : 2,

                        "host" :"10.1.5.123:28003"

                }

       ]

}

 

--查看複製整合員

> config.members

[

       {

                "_id" : 0,

                "host" :"10.1.5.123:28001"

       },

       {

                "_id" : 1,

                "host" :"10.1.5.123:28002"

       },

       {

      &nb

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.