redhat7.0下mongodb主從搭配

來源:互聯網
上載者:User

標籤:

1,首先安裝mongodb,見之前博文

2,在主節點執行下面的命令

mongod --dbpath=/var/lib/mongo --master --oplogSize 64 --port 27017

看到下面的資訊即啟動成功

2015-05-18T09:51:12.111+0800 I STORAGE  [initandlisten] ** WARNING: Readahead for /var/lib/mongo is set to 4096KB2015-05-18T09:51:12.111+0800 I STORAGE  [initandlisten] **          We suggest setting it to 256KB (512 sectors) or less2015-05-18T09:51:12.111+0800 I STORAGE  [initandlisten] **          http://dochub.mongodb.org/core/readahead2015-05-18T09:51:12.112+0800 I JOURNAL  [initandlisten] journal dir=/var/lib/mongo/journal2015-05-18T09:51:12.112+0800 I JOURNAL  [initandlisten] recover : no journal files present, no recovery needed2015-05-18T09:51:12.162+0800 I JOURNAL  [durability] Durability thread started2015-05-18T09:51:12.162+0800 I JOURNAL  [journal writer] Journal writer thread started2015-05-18T09:51:12.162+0800 I CONTROL  [initandlisten] MongoDB starting : pid=29245 port=27017 dbpath=/var/lib/mongo master=1 64-bit host=localhost.localdomain2015-05-18T09:51:12.162+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.2015-05-18T09:51:12.162+0800 I CONTROL  [initandlisten] 2015-05-18T09:51:12.162+0800 I CONTROL  [initandlisten] 2015-05-18T09:51:12.162+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.2015-05-18T09:51:12.162+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'2015-05-18T09:51:12.162+0800 I CONTROL  [initandlisten] 2015-05-18T09:51:12.162+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.2015-05-18T09:51:12.162+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'2015-05-18T09:51:12.162+0800 I CONTROL  [initandlisten] 2015-05-18T09:51:12.162+0800 I CONTROL  [initandlisten] db version v3.0.22015-05-18T09:51:12.163+0800 I CONTROL  [initandlisten] git version: 6201872043ecbbc0a4cc169b5482dcf385fc464f2015-05-18T09:51:12.163+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 20132015-05-18T09:51:12.163+0800 I CONTROL  [initandlisten] build info: Linux ip-10-169-109-10 3.10.0-121.el7.x86_64 #1 SMP Tue Apr 8 10:48:19 EDT 2014 x86_64 BOOST_LIB_VERSION=1_492015-05-18T09:51:12.163+0800 I CONTROL  [initandlisten] allocator: tcmalloc2015-05-18T09:51:12.163+0800 I CONTROL  [initandlisten] options: { master: true, net: { port: 27017 }, replication: { oplogSizeMB: 64 }, storage: { dbPath: "/var/lib/mongo" } }

3,從節點執行下面的命令即可

mongod --dbpath=/var/lib/mongo --port=37017--slave


看到下面日誌即啟動成功

015-05-18T11:26:21.321+0800 I REPL     [replslave] repl:  end sync_pullOpLog syncedTo: May 18 11:26:16 55595bd8:12015-05-18T11:26:21.322+0800 I REPL     [replslave] repl: syncing from host:192.168.1.1:270172015-05-18T11:26:31.322+0800 I REPL     [replslave] repl:   applied 1 operations2015-05-18T11:26:31.322+0800 I REPL     [replslave] repl:  end sync_pullOpLog syncedTo: May 18 11:26:26 55595be2:12015-05-18T11:26:31.322+0800 I REPL     [replslave] repl: syncing from host:192.168.1.1:270172015-05-18T11:26:41.322+0800 I REPL     [replslave] repl:   applied 1 operations2015-05-18T11:26:41.322+0800 I REPL     [replslave] repl:  end sync_pullOpLog syncedTo: May 18 11:26:36 55595bec:12015-05-18T11:26:41.322+0800 I REPL     [replslave] repl: syncing from host:192.168.1.1:270172015-05-18T11:26:51.322+0800 I REPL     [replslave] repl:   applied 1 operations2015-05-18T11:26:51.322+0800 I REPL     [replslave] repl:  end sync_pullOpLog syncedTo: May 18 11:26:46 55595bf6:12015-05-18T11:26:51.322+0800 I REPL     [replslave] repl: syncing from host:192.168.1.1:270172015-05-18T11:27:01.323+0800 I REPL     [replslave] repl:   applied 1 operations2015-05-18T11:27:01.323+0800 I REPL     [replslave] repl:  end sync_pullOpLog syncedTo: May 18 11:26:56 55595c00:12015-05-18T11:27:01.323+0800 I REPL     [replslave] repl: syncing from host:192.168.1.1:270172015-05-18T11:27:11.323+0800 I REPL     [replslave] repl:   applied 1 operations2015-05-18T11:27:11.323+0800 I REPL     [replslave] repl:  end sync_pullOpLog syncedTo: May 18 11:27:06 55595c0a:12015-05-18T11:27:11.323+0800 I REPL     [replslave] repl: syncing from host:192.168.1.1:270172015-05-18T11:27:21.323+0800 I REPL     [replslave] repl:   applied 1 operations2015-05-18T11:27:21.323+0800 I REPL     [replslave] repl:  end sync_pullOpLog syncedTo: May 18 11:27:16 55595c14:12015-05-18T11:27:21.323+0800 I REPL     [replslave] repl: syncing from host:192.168.1.1:270172015-05-18T11:27:31.323+0800 I REPL     [replslave] repl:   applied 1 operations2015-05-18T11:27:31.323+0800 I REPL     [replslave] repl:  end sync_pullOpLog syncedTo: May 18 11:27:26 55595c1e:12015-05-18T11:27:31.323+08


4,主庫新增一條記錄

> use testswitched to db test> db.blog.save({title:"new article"}) WriteResult({ "nInserted" : 1 })

5,從庫進行查詢

>  db.blog.find(){ "_id" : ObjectId("55595022e26fd5794a58bdd3"), "title" : "new article" }


主從同時都有了這條記錄,即配置成功


注意事項:

1,報錯如下:

repl: --source 192.168.1.1:27017 != 192.168.1.1:27017 from local.sources collection
原因:第一次執行從庫命令的時候,錯誤的把source寫成從庫的ip,第二次修改正確的主庫ip。由於從庫已經在local表裡儲存了之前的source ip,以後在執行就會報錯
解決辦法:執行下面命令,刪除錯誤的資訊即可

 db.sources.remove({'host':'192.168.1.1:27017'})

2,從庫命設定同步時機

mongod --dbpath=/var/lib/mongo --port=37017--slave --source=192.168.1.1:27017 autoresync=true 



add by joeyon1985


redhat7.0下mongodb主從搭配

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.