centos7开机启动mongodb shard cluster

原创 2015年06月26日 10:10:53

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 
    
版权声明:本文为博主原创文章,未经博主允许不得转载。博主地址 http://blog.csdn.net/secretx https://blog.csdn.net/secretx/article/details/46646607

systemctl里万恶的203

如前面的两个例子,在执行systemctl时经常出现问题 例如 [root@z system]# systemctl status changeconfig.service -l changec...
  • anzhuangguai
  • anzhuangguai
  • 2016-10-10 18:01:42
  • 1823

解决apache启动失败:Job for httpd.service failed.

最近用centos7搭建lamp的时候,安装完之后apache还能正常启动,但是重启之后就启动不了,总是提示:Job for httpd.service failed.。 经大神调试之后果然成功了,...
  • chaojidora
  • chaojidora
  • 2015-04-23 22:23:28
  • 73249

RHEL7/CentOS7 Network Service开机无法启动的解决方法

RHEL7/CentOS7安装完成并配置好所有网络相关配置后重启机器,使用systemctl --failed检查是否有失败的服务,发现在network服务启动失败,使用systemctl statu...
  • bluishglc
  • bluishglc
  • 2014-11-25 08:50:40
  • 110426

Linux -- Mongodb

[root@Arch ~]# systemctl -l status mongodb.service ● mongodb.service - High-performance, schema-fre...
  • u011130746
  • u011130746
  • 2014-11-26 18:51:25
  • 2857

MongoDB重装后无法启动的一个可能原因

mongo启动失败,service mongodb status查看状态如下 ● mongodb.service - An object/document-oriented database ...
  • somehow1002
  • somehow1002
  • 2018-03-21 12:36:58
  • 22

mongodb 在centos7里用systemctl起不来

两个问题造成 1、/var/run/mongodb/mongod.pid 文件已存在 2、logpath和dbpath下的文件的权限问题:都得用 sudo chown mongod:mongod...
  • zhao4471437
  • zhao4471437
  • 2016-11-14 17:58:17
  • 2367

Centos7安装mongodb出现的问题:服务无法启动

问题描述:Centos7安装mongodb刚开始安装成功时执行sudo service mongod start 能启动,执行sudo service mongod status显示Active: a...
  • bwangk
  • bwangk
  • 2016-12-18 14:19:25
  • 3339

如何解决MongoDB启动时无法连接到Upstart的错误

注意:sitewhere安装遇到此问题直接看文末即可。在Ubuntu 16.04 TLS系统上安装MongoDB,安装完成后使用service mongod start命令启动mongoDB失败,提示...
  • orchidofocean
  • orchidofocean
  • 2017-06-12 21:08:12
  • 996

Centos7下systemctl status postgresql 命令相关研究

postgres有源码安装,yum安装,或者下载包自己rpm,安装方法众多。 以前一台yum安装postgres的机器设置了  systemctl enable postgresql 这样pos...
  • yibei8811
  • yibei8811
  • 2015-06-22 14:17:44
  • 1689

mysql 启动时失败

使用 # yum install mysql-server mysql 安装成功后,启动mysql 服务,使用 # systemctl start mysqld.service  ...
  • hamztx
  • hamztx
  • 2015-03-16 23:33:39
  • 4301
收藏助手
不良信息举报
您举报文章:centos7开机启动mongodb shard cluster
举报原因:
原因补充:

(最多只允许输入30个字)