美文网首页mongodb
【mongoDB】install_mongoReplicaSet

【mongoDB】install_mongoReplicaSet

作者: Bogon | 来源:发表于2022-09-06 00:11 被阅读0次

    $ cat install_mongoReplicaSet.sh

    #!/bin/bash
    IP='192.168.1.202'
    NA='rsb'
    
    if [ "$1" = "reset" ]
    then
            pkill -9 mongo
            rm -rf /home/m*
            exit
    fi
    
    
    if [ "$1" = "install" ]
    then
    
        mkdir -p /home/m0 /home/m1 /home/m2 /home/mlog
    
        /usr/local/mongodb/bin/mongod --dbpath /home/m0 --logpath /home/mlog/m17.log --logappend --port 27017 --fork  --replSet ${NA}
        /usr/local/mongodb/bin/mongod --dbpath /home/m1 --logpath /home/mlog/m18.log --logappend --port 27018 --fork  --replSet ${NA}
        /usr/local/mongodb/bin/mongod --dbpath /home/m2 --logpath /home/mlog/m19.log --logappend --port 27019 --fork  --replSet ${NA}
       
        exit
    fi
    
    
    if [ "$1" = "repl" ]
    then
    /usr/local/mongodb/bin/mongo <<EOF
    
    use admin
    rsconf = {
    _id:'${NA}',
    members:[
    {_id:0,host:'${IP}:27017'},
    {_id:1,host:'${IP}:27018'},
    {_id:2,host:'${IP}:27019'},
    ]
    }
    rs.initiate(rsconf)
    EOF
    fi
    

    相关文章

      网友评论

        本文标题:【mongoDB】install_mongoReplicaSet

        本文链接:https://www.haomeiwen.com/subject/wnfyyrtx.html