最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】确认服务器是否已经正在运行MongoDB的服务mongod

MongoDB crifan 3225浏览 0评论

折腾:

【已解决】阿里云ECS服务器中已有的MongoDB的用户名密码和端口

期间,需要去搞清楚,是否服务器中是否已经正在,正常的,运行了mongod的MongoDB的服务了。

去服务器中运行mongod之后:

<code>[root@naturling-general-01 ~]# mongod
2018-04-02T09:05:35.585+0800 I CONTROL  [initandlisten] MongoDB starting : pid=7330 port=27017 dbpath=/data/db 64-bit host=naturling-general-01
2018-04-02T09:05:35.585+0800 I CONTROL  [initandlisten] db version v3.2.19
2018-04-02T09:05:35.585+0800 I CONTROL  [initandlisten] git version: a9f574de6a566a58b24d126b44a56718d181e989
2018-04-02T09:05:35.585+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2018-04-02T09:05:35.585+0800 I CONTROL  [initandlisten] allocator: tcmalloc
2018-04-02T09:05:35.585+0800 I CONTROL  [initandlisten] modules: none
2018-04-02T09:05:35.585+0800 I CONTROL  [initandlisten] build environment:
2018-04-02T09:05:35.585+0800 I CONTROL  [initandlisten]     distmod: rhel70
2018-04-02T09:05:35.585+0800 I CONTROL  [initandlisten]     distarch: x86_64
2018-04-02T09:05:35.585+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2018-04-02T09:05:35.585+0800 I CONTROL  [initandlisten] options: {}
2018-04-02T09:05:35.606+0800 E NETWORK  [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2018-04-02T09:05:35.606+0800 E NETWORK  [initandlisten]   addr already in use
2018-04-02T09:05:35.606+0800 E STORAGE  [initandlisten] Failed to set up sockets during startup.
2018-04-02T09:05:35.606+0800 I CONTROL  [initandlisten] dbexit:  rc: 48
[root@naturling-general-01 ~]# 
</code>

需要查看和确认,是否的确已经运行了:

查看mongodb 是否已经运行

通过查看端口状态查看mongodb是否已经启动 – CSDN博客

然后最后找到了验证方式:

<code>[root@naturling-general-01 ~]# netstat -lanp | grep 27017
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      14512/mongod        
unix  2      [ ACC ]     STREAM     LISTENING     1436989  14512/mongod         /tmp/mongodb-27017.sock

[root@naturling-general-01 ~]# ps -ef | grep mongo
root      7336  7288  0 09:08 pts/0    00:00:00 grep --color=auto mongo
mongod   14512     1  0 Mar20 ?        00:49:28 /usr/bin/mongod -f /etc/mongod.conf

[root@naturling-general-01 ~]# /etc/init.d/mongod status
[0m mongod.service - SYSV: Mongo is a scalable, document-oriented database.
   Loaded: loaded (/etc/rc.d/init.d/mongod; bad; vendor preset: disabled)
   Active: active (running) since Tue 2018-03-20 22:05:01 CST; 1 weeks 5 days ago
     Docs: man:systemd-sysv-generator(8)
   CGroup: /system.slice/mongod.service
           14512 /usr/bin/mongod -f /etc/mongod.conf

Mar 20 22:05:01 naturling-general-01 systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database....
Mar 20 22:05:01 naturling-general-01 runuser[14508]: pam_unix(runuser:session): session opened for user mongod by (uid=0)
Mar 20 22:05:01 naturling-general-01 runuser[14508]: pam_unix(runuser:session): session closed for user mongod
Mar 20 22:05:01 naturling-general-01 mongod[14497]: Starting mongod: [  OK  ]
Mar 20 22:05:01 naturling-general-01 systemd[1]: Started SYSV: Mongo is a scalable, document-oriented database..
[root@naturling-general-01 ~]# systemctl status mongod
[0m mongod.service - SYSV: Mongo is a scalable, document-oriented database.
   Loaded: loaded (/etc/rc.d/init.d/mongod; bad; vendor preset: disabled)
   Active: active (running) since Tue 2018-03-20 22:05:01 CST; 1 weeks 5 days ago
     Docs: man:systemd-sysv-generator(8)
   CGroup: /system.slice/mongod.service
           14512 /usr/bin/mongod -f /etc/mongod.conf

Mar 20 22:05:01 naturling-general-01 systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database....
Mar 20 22:05:01 naturling-general-01 runuser[14508]: pam_unix(runuser:session): session opened for user mongod by (uid=0)
Mar 20 22:05:01 naturling-general-01 runuser[14508]: pam_unix(runuser:session): session closed for user mongod
Mar 20 22:05:01 naturling-general-01 mongod[14497]: Starting mongod: [  OK  ]
Mar 20 22:05:01 naturling-general-01 systemd[1]: Started SYSV: Mongo is a scalable, document-oriented database..
</code>

果然已经在运行了mongod了。

【总结】

方式1:

<code>netstat -lanp | grep 27017
</code>

方法2:

<code>ps -ef | grep mongo
</code>

方法3:

<code>systemctl status mongod
</code>

等价于:

<code>/etc/init.d/mongod status
</code>

转载请注明:在路上 » 【已解决】确认服务器是否已经正在运行MongoDB的服务mongod

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
89 queries in 0.175 seconds, using 22.18MB memory