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

相关文章推荐

systemctl里万恶的203

如前面的两个例子,在执行systemctl时经常出现问题 例如 [root@z system]# systemctl status changeconfig.service -l changec...

Centos7 设置Mongodb开机启动-自定义服务

一.官网下载 mongodb,解压到指定目录 二 .编写配置文件,主要指定数据库文件,日志文件,以及一些启动参数. 三.编写自定义服务...
  • i_vic
  • i_vic
  • 2016年12月05日 16:08
  • 4967

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

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

使用curl命令发送http请求

Examples: curl -svo /dev/null http://test/index.html -x 127.0.0.1:9711

Keepalived之MISC_CHECK方式检测

! Configuration File for keepalived global_defs { #全局配置 notification_email { ...

centos7 配置nginx服务、设置开机自动启动

环境:VM+CentOS7+Linux+Nginx1.9.9+PHP7.1.6+Mysql5.7.17 1、新建nginx文件 vi /etc/init.d/nginx #写入以下内容 #! /b...

CentOS 7.x设置自定义开机启动,添加自定义系统服务

Centos 系统服务脚本目录: [html] view plaincopyprint?   /usr/lib/systemd/   有系统(system)...

centos7安装redis及开机自启动

centos7搭建redis及开机自启动

Centos7禁止或者允许开机启动服务

[root@bogon rsyslog.d]# systemctl is-enabled httpd disabled [root@bogon rsyslog.d]# systemctl status...

redis 开机启动。亲测可用 应用于centos 7 mini

修改redis.conf,打开后台运行选项: [html] view plaincopy # By default Redis does not run a...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:centos7开机启动mongodb shard cluster
举报原因:
原因补充:

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