mongodb不同版本實現主從複製

來源:互聯網
上載者:User

標籤:

    mongoDB有一個主要特性就是複製,有多種複製形式,其中,主從複製是比較常用的一種。

    主從複製的工作原理:首先要有兩個或更多的伺服器,其中一個是主節點,負責處理用戶端的請求,其他的都是從節點,負責映射主節點的資料。主節點記錄在其上執行的所有操作,從節點定期輪詢主節點獲得的這些操作,然後執行這些操作。由於從節點和主節點執行了相同的操作,從節點就能保持與主節點的資料同步。

    實戰講解一下mongodb的搭建和主從複製,因為只有一台伺服器,所以只能通過修改連接埠號碼實現mongodb的主從,而不是通過多台伺服器實現。其實原理是一樣的~,只是這樣做實際意義不大~

    之前已經裝了一個版本的mongodb(2.6.11),既然現在mongodb已經更新到了3.0.6,那麼從庫就特意使用3.0.6,反正是測試用途,就不管那麼多了~ 

安裝

    mongodb

    下載mongodb3.0.6執行檔案包,並解壓,把二進位執行檔案放在/usr/local/mongo3.0.6目錄

配置  主庫配置
# mongod.conf#where to loglogpath=/var/log/mongodb/mongod-27017.loglogappend=true# fork and run in backgroundfork=trueport=27017#dbpath=/var/lib/mongodbpath=/data/mongodb/mongo-27017# location of pidfilepidfilepath=/var/run/mongodb/mongod-27017.pidbind_ip=127.0.0.1,192.168.56.61#noauth=true# Ignore query hints#nohints=true# Disable the HTTP interface (Defaults to localhost:27017).nohttpinterface = falserest = truemaster = true
 從庫配置
# mongod.conf#where to loglogpath=/var/log/mongodb/mongod-27018.loglogappend=true# fork and run in backgroundfork=trueport=27018#dbpath=/var/lib/mongodbpath=/data/mongodb/mongo-27018# location of pidfilepidfilepath=/var/run/mongodb/mongod-27018.pid# Listen to local interface only. Comment out to listen on all interfaces. bind_ip=127.0.0.1,192.168.56.61#noauth=true# Ignore query hints#nohints=true# Disable the HTTP interface (Defaults to localhost:27018).nohttpinterface = falserest = trueslave = truesource = 127.0.0.1:27017
啟動
# 主庫啟動/usr/local/mongo2.6.11/mongod -f /etc/mongod/mongod-27017.conf# 從庫啟動/usr/local/mongo3.0.6/mongod -f /etc/mongod/mongod-27018.conf
認證

   不同版本的mongodb開始auth模式可以通過下面的方法來實現

   1. 先把所有主從mongodb設為unauth模式

   2. 在master添加一個帳號,這樣slave也就自動同步了該帳號

   3. 把所有主從mongodb開啟auth模式

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.