centos7开机启动mongodb shard cluster

centos7开机启动mongodb shard cluster


分享光荣,盗链可耻。转载务必注明出处,鄙视盗链鼠辈。

shard配置

  • shard node1配置

    shardsvr=true#注意此项
    port=27018
    rest=true
    httpinterface=true
    fork=true
    dbpath=/mongo_data/shard/node1
    logpath=/var/log/mongo/shard/node1.log
    pidfilepath=/tmp/mongo_shard_node1.pid
  • shard node2配置

    shardsvr=true#注意此项
    port=27081
    rest=true
    httpinterface=true
    fork=true
    dbpath=/mongo_data/shard/node2
    logpath=/var/log/mongo/shard/node2.log
    pidfilepath=/tmp/mongo_shard_node2.pid
  • config server配置

    configsvr = true#注意此项
    port = 27019
    rest=true
    httpinterface=true
    fork=true
    dbpath=/mongo_data/shard/config
    logpath=/var/log/mongo/shard/config.log
    pidfilepath=/tmp/mongo_shard_config.pid
  • mongos配置

    configdb = 127.0.0.1:27019#注意与configsvr一致
    chunkSize = 64
    httpinterface=true
    fork=true
    logpath=/var/log/mongo/shard/mongos.log
    pidfilepath=/tmp/mongos.pid

shard启动脚本

启动,停止顺序自行思考,很好想

  • start_mongo_shard.sh(先起shard node,再config server,再mongos)

    #!/bin/sh
    /usr/local/mongodb3.0/bin/mongod --config=/usr/local/mongodb3.0/shard_node1_server
    /usr/local/mongodb3.0/bin/mongod --config=/usr/local/mongodb3.0/shard_node2_server
    /usr/local/mongodb3.0/bin/mongod --config=/usr/local/mongodb3.0/shard_config_server
    /usr/local/mongodb3.0/bin/mongos --config=/usr/local/mongodb3.0/shard_mongos_server
  • stop_mongo_shard.sh(先停mongos,再config server,再shard node)

    #!/bin/sh
    kill `cat /tmp/mongos.pid`
    kill `cat /tmp/mongo_shard_config.pid`
    kill `cat /tmp/mongo_shard_node1.pid`
    kill `cat /tmp/mongo_shard_node2.pid`
  • 注意:启停脚本第一行#!/bin/sh非常重要,如果不写这行,命令行下脚本正常运行,但是在systemctl start xxxx启动mongodb服务时报错。详见后文。

shard开机自动启动

  • vim /usr/lib/systemd/system/mongodb.service

    [unit]
    Description=mongodb
    After=network.target
    
    [Service]  
    Type=forking  
    ExecStart=/usr/local/mongodb3.0/start_mongo_shard.sh
    ExecStop=/usr/local/mongodb3.0/stop_mongo_shard.sh
    PrivateTmp=true  
    
    [Install]
    WantedBy=multi-user.target
    
  • systemctl enable mongodb开机自动启动

  • 启停:systemctl start mongodb // systemctl stop mongodb

错误备录

  • 如果启停脚本不写第一行#!/bin/sh,命令行直接执行start_mongo_shard.sh没问题,但是systemctl start mongodb会报错,如下

    [xxx@xxx-centos7 system]$ sudo systemctl status mongodb
    mongodb.service
    Loaded: loaded (/usr/lib/systemd/system/mongodb.service; enabled)
    Active: failed (Result: exit-code) since 四 2015-06-25 15:03:58 CST; 9s ago
    Process: 25509 ExecStart=/usr/local/mongodb3.0/start_mongo_shard.sh (code=exited, status=203/EXEC)
    Main PID: 25426 (code=exited, status=203/EXEC)
    
    6月 25 15:03:58 xxx-centos7 systemd[25509]: Failed at step EXEC spawning /usr/local/mongodb3.0/start_mongo_...rror
    6月 25 15:03:58 xxx-centos7 systemd[1]: mongodb.service: control process exited, code=exited status=203
    6月 25 15:03:58 xxx-centos7 systemd[1]: Failed to start mongodb.service.
    6月 25 15:03:58 xxx-centos7 systemd[1]: Unit mongodb.service entered failed state.
    Hint: Some lines were ellipsized, use -l to show in full.
  • 加上#!/bin/sh后信息如下

    [xxx@xxx-centos7 system]$ sudo systemctl status mongodb
    mongodb.service
    Loaded: loaded (/usr/lib/systemd/system/mongodb.service; enabled)
    Active: active (running) since 四 2015-06-25 15:08:47 CST; 3s ago
    Process: 25656 ExecStart=/usr/local/mongodb3.0/start_mongo_shard.sh (code=exited, status=0/SUCCESS)
    Main PID: 25426 (code=exited, status=203/EXEC)
    CGroup: /system.slice/mongodb.service
           ├─25659 /usr/local/mongodb3.0/bin/mongod --config=/usr/local/mongodb3.0/shard_node1_server
           ├─25674 /usr/local/mongodb3.0/bin/mongod --config=/usr/local/mongodb3.0/shard_node2_server
           ├─25689 /usr/local/mongodb3.0/bin/mongod --config=/usr/local/mongodb3.0/shard_config_server
           └─25705 /usr/local/mongodb3.0/bin/mongos --config=/usr/local/mongodb3.0/shard_mongos_server 
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值