mongodb主從配置,mongodb主從

來源:互聯網
上載者:User

mongodb主從配置,mongodb主從

1.在主從伺服器上/etc/yum.repos.d/目錄下建立檔案mongodb.repo,它包含MongoDB倉庫的配置資訊,內容如下:

[mongodb] name=MongoDB Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/ gpgcheck=0 enabled=1  

2.在主從伺服器上執行安裝命令

yum -y install mongodb-org

3.在主從伺服器上自訂db和log存放路徑

建立存放DB目錄,修改許可權

mkdir -p /data0/mongodbchown -R  mongod:mongod /data0/mongodb

主伺服器修改/etc/mongod.conf

logpath=/data0/mongodb/mongod.log
logappend=true  #使用追加的方式寫日誌
fork=true  #以守護進程的方式運行
master=true  #主庫
dbpath=/data0/mongodb
pidfilepath=/var/run/mongodb/mongod.pid
bind_ip=172.16.225.111  #綁定服務IP,不指定預設本地所有IP
auth=true  #啟用使用者密碼驗證

從伺服器修改/etc/mongod.conf

logpath=/data0/mongodb/mongod.loglogappend=truefork=trueslave=true  #從庫source=172.16.225.111:27017  #主庫IP和連接埠dbpath=/data0/mongodbpidfilepath=/var/run/mongodb/mongod.pidbind_ip=172.16.59.190auth=true

 4.主從伺服器啟動mongodb服務

/etc/init.d/mongod start

 

聯繫我們

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