Centos7 虚拟机MongoDB单机安装Replica Set

1. 下载MongoDB。下载地址:https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.4.7.tgz

2. 解压,tar zxvf mongodb-linux-x86_64-rhel70-3.4.7.tgz

3. 新建Mongo文件夹,mkdir Mongodb

4. 将mongo复制到文件夹中, mv mongodb-linux-x86_64-rhel70-3.4.7/ ../Mongodb/mongo

5. 新建数据、日志、配置文件夹,mkdir conf data log

6. 进入data目录, cd data/

7. 新建节点的文件夹,mkdir 27017 27018 27019

8. 进入配置文件夹, cd conf/

9. 新建PRIMARY配置27017, vi 27017.conf

    port=27017

    bind_ip=10.11.17.171

    logpath=/home/jiangyi/Mongodb/log/27017.log

    dbpath=/home/jiangyi/Mongodb/data/27017/

    logappend=true

    pidfilepath=/home/jiangyi/Mongodb/data/27017/27017.pid

    fork=true

    oplogSize=1024

    replSet=MyMongo

10. 新建SECONDARY配置27018,vi 27018.conf

    port=27018

    bind_ip=10.11.17.171

    logpath=/home/jiangyi/Mongodb/log/27018.log

    dbpath=/home/jiangyi/Mongodb/data/27018/

    logappend=true

    pidfilepath=/home/jiangyi/Mongodb/data/27018/27018.pid

    fork=true

    oplogSize=1024

    replSet=MyMongo

11. 新建ARBITOR配置27019, vi 27019.conf

    bind_ip=10.11.17.171

    logpath=/home/jiangyi/Mongodb/log/27019.log

    dbpath=/home/jiangyi/Mongodb/data/27019/

    logappend=true

    pidfilepath=/home/jiangyi/Mongodb/data/27019/27019.pid

    fork=true

    oplogSize=1024

    replSet=MyMongo

12. 启动三个节点

    cd /home/jiangyi/Mongodb/mongodb/bin

    ./mongod -f /home/jiangyi/Mongodb/conf/27017.conf

    ./mongod -f /home/jiangyi/Mongodb/conf/27018.conf

    ./mongod -f /home/jiangyi/Mongodb/conf/27019.conf

11. 登录主节点,./mongo 10.11.17.171:27017/admin,配置

    db;

    config = {

    "_id":"MyMongo",

    members:[

        {"_id":0,host:"10.11.17.171:27017"},

        {"_id":1,host:"10.11.17.171:27018"},

        {"_id":2,host:"10.11.17.171:27019"}]

    }

12. 将27019设置为仲裁节点

    config.members[2] ={"_id":2,"host":"10.11.17.171:27019",arbiterOnly:true}

13. 初始化config

    rs.initiate(config)

14. 查看状态

    rs.status()

15. 切换到root用户,设置防火墙,ip屏蔽取消

    firewall-cmd --permanent --add-port=27017/tcp

    firewall-cmd --permanent --add-port=27018/tcp

    firewall-cmd --permanent --add-port=27019/tcp

    firewall-cmd --reload

    systemctl restart firewalld.service

你可能感兴趣的:(Centos7 虚拟机MongoDB单机安装Replica Set)