前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MongoDB 基础(3)

MongoDB 基础(3)

作者头像
franket
发布2021-10-19 19:40:47
2920
发布2021-10-19 19:40:47
举报
文章被收录于专栏:技术杂记技术杂记

连接服务

使用mongo客户端来连接服务,mongo 客户端由 mongodb-org-shell 包提供

代码语言:javascript
复制
[root@h105 ~]# rpm -ql mongodb-org-shell-3.2.6-1.el6.x86_64
/usr/bin/mongo
/usr/share/man/man1/mongo.1
[root@h105 ~]# 

拷贝一份到 bin 中

代码语言:javascript
复制
[root@h105 mongo]# which mongo
/usr/bin/mongo
[root@h105 mongo]# cp /usr/bin/mongo bin/
[root@h105 mongo]# ll bin/
total 60696
-rwxr-xr-x 1 root root 22561172 May 18 16:54 mongo
-rwxr-xr-x 1 root root 39583898 May 18 15:55 mongod
[root@h105 mongo]# ./bin/mongo --help 
MongoDB shell version: 3.2.6
usage: ./bin/mongo [options] [db address] [file names (ending in .js)]
db address can be:
  foo                   foo database on local machine
  192.169.0.5/foo       foo database on 192.168.0.5 machine
  192.169.0.5:9999/foo  foo database on 192.168.0.5 machine on port 9999
Options:
  --shell                             run the shell after executing files
  --nodb                              don't connect to mongod on startup - no 
                                      'db address' arg expected
  --norc                              will not run the ".mongorc.js" file on 
                                      start up
  --quiet                             be less chatty
  --port arg                          port to connect to
  --host arg                          server to connect to
  --eval arg                          evaluate javascript
  -h [ --help ]                       show this usage information
  --version                           show version information
  --verbose                           increase verbosity
  --ipv6                              enable IPv6 support (disabled by default)
  --disableJavaScriptJIT              disable the Javascript Just In Time 
                                      compiler
  --enableJavaScriptProtection        disable automatic JavaScript function 
                                      marshalling
  --ssl                               use SSL for all connections
  --sslCAFile arg                     Certificate Authority file for SSL
  --sslPEMKeyFile arg                 PEM certificate/key file for SSL
  --sslPEMKeyPassword arg             password for key in PEM file for SSL
  --sslCRLFile arg                    Certificate Revocation List file for SSL
  --sslAllowInvalidHostnames          allow connections to servers with 
                                      non-matching hostnames
  --sslAllowInvalidCertificates       allow connections to servers with invalid
                                      certificates
  --sslFIPSMode                       activate FIPS 140-2 mode at startup

Authentication Options:
  -u [ --username ] arg               username for authentication
  -p [ --password ] arg               password for authentication
  --authenticationDatabase arg        user source (defaults to dbname)
  --authenticationMechanism arg       authentication mechanism
  --gssapiServiceName arg (=mongodb)  Service name to use when authenticating 
                                      using GSSAPI/Kerberos
  --gssapiHostName arg                Remote host name to use for purpose of 
                                      GSSAPI/Kerberos authentication

file names: a list of files to run. files have to end in .js and will exit after unless --shell is specified
[root@h105 mongo]# 

进行连接

代码语言:javascript
复制
[root@h105 mongo]# ./bin/mongo 127.0.0.1:12345/test
MongoDB shell version: 3.2.6
connecting to: 127.0.0.1:12345/test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	http://docs.mongodb.org/
Questions? Try the support group
	http://groups.google.com/group/mongodb-user
Server has startup warnings: 
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] 
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] 
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] 
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] 
>

停止服务

代码语言:javascript
复制
[root@h105 mongo]# ./bin/mongo 127.0.0.1:12345/test
MongoDB shell version: 3.2.6
connecting to: 127.0.0.1:12345/test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	http://docs.mongodb.org/
Questions? Try the support group
	http://groups.google.com/group/mongodb-user
Server has startup warnings: 
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] 
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] 
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] 
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-05-18T15:57:03.510+0800 I CONTROL  [initandlisten] 
> db.shutdownServer()
shutdown command only works with the admin database; try 'use admin'
> use admin
switched to db admin
> db.shutdownServer()
server should be down...
2016-05-18T16:57:34.674+0800 I NETWORK  [thread1] trying reconnect to 127.0.0.1:12345 (127.0.0.1) failed
2016-05-18T16:57:34.682+0800 W NETWORK  [thread1] Failed to connect to 127.0.0.1:12345, reason: errno:111 Connection refused
2016-05-18T16:57:34.682+0800 I NETWORK  [thread1] reconnect 127.0.0.1:12345 (127.0.0.1) failed failed 
> ^C
bye
[root@h105 mongo]# 

查看日志

代码语言:javascript
复制
[root@h105 mongo]# tail -f log/mongod.log 
2016-05-18T16:57:34.670+0800 I CONTROL  [conn1] now exiting
2016-05-18T16:57:34.670+0800 I NETWORK  [conn1] shutdown: going to close listening sockets...
2016-05-18T16:57:34.670+0800 I NETWORK  [conn1] closing listening socket: 6
2016-05-18T16:57:34.670+0800 I NETWORK  [conn1] closing listening socket: 7
2016-05-18T16:57:34.670+0800 I NETWORK  [conn1] removing socket file: /tmp/mongodb-12345.sock
2016-05-18T16:57:34.670+0800 I NETWORK  [conn1] shutdown: going to flush diaglog...
2016-05-18T16:57:34.670+0800 I NETWORK  [conn1] shutdown: going to close sockets...
2016-05-18T16:57:34.670+0800 I STORAGE  [conn1] WiredTigerKVEngine shutting down
2016-05-18T16:57:34.823+0800 I STORAGE  [conn1] shutdown: removing fs lock...
2016-05-18T16:57:34.823+0800 I CONTROL  [conn1] dbexit:  rc: 0
^C
[root@h105 mongo]#

命令汇总

  • vim /etc/yum.repos.d/mongodb-org-3.2.repo
  • yum clean all
  • yum install -y mongodb-org
  • mongo --version
  • getenforce
  • grep -i '^SELINUX' /etc/sysconfig/selinux
  • rpm -ql mongodb-org-server
  • /etc/init.d/mongod start
  • mkdir mongo
  • cd mongo/
  • mkdir data
  • mkdir log
  • mkdir conf
  • mkdir bin
  • cp /usr/bin/mongod bin
  • cd conf
  • vim mongod.conf
  • ./bin/mongod -f conf/mongod.conf
  • netstat -ant | grep 1234
  • tail log/mongod.log
  • rpm -ql mongodb-org-shell-3.2.6-1.el6.x86_64
  • cp /usr/bin/mongo bin/
  • ./bin/mongo --help
  • ./bin/mongo 127.0.0.1:12345/test
  • tail -f log/mongod.log

原文地址

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 连接服务
  • 停止服务
  • 命令汇总
相关产品与服务
云数据库 MongoDB
腾讯云数据库 MongoDB(TencentDB for MongoDB)是腾讯云基于全球广受欢迎的 MongoDB 打造的高性能 NoSQL 数据库,100%完全兼容 MongoDB 协议,支持跨文档事务,提供稳定丰富的监控管理,弹性可扩展、自动容灾,适用于文档型数据库场景,您无需自建灾备体系及控制管理系统。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档