文档章节

MongoDB的安装

kenyon_君羊
 kenyon_君羊
发布于 2012/12/30 09:06
字数 1465
阅读 922
收藏 9
MongoDB据说是一款很棒的NOSQL产品,今天开始研究一下。

 
一、下载
通过CURL命名下到本地
[root @localhost ~]# curl http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.2.2.tgz > mongo.tgz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  73  53M  86  47.6M  0   0  132K  0    0:06:50  0:04:50 0:01:12  140k  

二、解压 
[root @localhost ~]# tar zxvf mongo.tgz 
mongodb-linux-x86_64-2.2.2/GNU-AGPL-3.0
mongodb-linux-x86_64-2.2.2/README
mongodb-linux-x86_64-2.2.2/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-2.2.2/bin/mongodump
mongodb-linux-x86_64-2.2.2/bin/mongorestore
mongodb-linux-x86_64-2.2.2/bin/mongoexport
mongodb-linux-x86_64-2.2.2/bin/mongoimport
mongodb-linux-x86_64-2.2.2/bin/mongostat
mongodb-linux-x86_64-2.2.2/bin/mongotop
mongodb-linux-x86_64-2.2.2/bin/mongooplog
mongodb-linux-x86_64-2.2.2/bin/mongofiles
mongodb-linux-x86_64-2.2.2/bin/bsondump
mongodb-linux-x86_64-2.2.2/bin/mongoperf
mongodb-linux-x86_64-2.2.2/bin/mongosniff
mongodb-linux-x86_64-2.2.2/bin/mongod
mongodb-linux-x86_64-2.2.2/bin/mongos
mongodb-linux-x86_64-2.2.2/bin/mongo

三、环境配置
1.创建用户与组
[root@localhost ~]# groupadd mongo
[root@localhost ~]# useradd mongo -g mongo

2.创建数据文件与日志文件路径,并修改权限
[root@localhost ~]# mv mongodb-linux-x86_64-2.2.2/* /home/mongo/
[root@localhost ~]# mkdir -p /database/mongo_data
[root @localhost ~]# mkdir -p /home/mongo/mongo_log
[root @localhost ~]# chown -R mongo:mongo /home/mongo/
[root @localhost ~]# chown -R mongo:mongo /database/mongo_data/

[mongo @localhost ~]$ vi .bash_profile
export MONGO_HOME=/home/mongo
export MONGO_DATA=/database/mongo_data
[mongo @localhost ~]$ source .bash_profile      --使生效


四、启动
[mongo@localhost ~]$nohup mongod --dbpath=/database/mongo_data/ --logpath=/home/mongo/mongo_log --logappend --port=27017 >/home/mongo/mongo_log/mongo.log 2>&1 &
[1] 3144
[mongo@localhost ~]$ ps -ef|grep mongo
mongo     3144     1  0 Dec28 ?        00:00:03 mongod --dbpath=/database/mongo_data/ --logpath=/home/mongo/mongo_log --logappend --port=27017
root         2560  2544  0 00:07 pts/1    00:00:00 su - mongo
mongo     2561  2560  0 00:07 pts/1    00:00:00 -bash
mongo     2580  2561  0 00:07 pts/1    00:00:00 mongo


五、连接
初次连接有Welcome信息
[mongo@localhost mongo_log]$ mongo
MongoDB shell version: 2.2.2
connecting to: 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
>

再连接就没了
[mongo@localhost mongo_log]$ mongo
MongoDB shell version: 2.2.2
connecting to: test


六、关闭
客户端关闭(ctrl+c或exit)
[mongo @localhost ~]$ mongo
MongoDB shell version: 2.2.2
connecting to: test
> show dbs;
local     (empty)
> ^C
bye
[mongo @localhost ~]$ 

服务端关闭(kill pid或者db.shutdownServer()或者mongod --shutdown)   --注意S大写

[mongo @localhost ~]$ mongo
MongoDB shell version: 2.2.2
connecting to: test
> use admin;
switched to db admin
> db.shutdownserver();
Sat Dec 29 01:54:40 TypeError: db.shutdownserver is not a function (shell):1
> db.shutdownServer();
Sat Dec 29 01:54:47 DBClientCursor::init call() failed
Sat Dec 29 01:54:47 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1:27017
server should be down...

[mongo @localhost ~]$ mongod --shutdown --dbpath=/database/mongo_data/
killing process with pid: 4097

七、帮助
bin下有很多文件,在这些文件后面带上--help可查看帮助,示例:
1.查看版本
[mongo@localhost bin]$ mongod --version
db version v2.2.2, pdfile version 4.5
Fri Dec 28 22:06:37 git version: d1b43b61a5308c4ad0679d34b262c5af9d664267

2.查看mongod帮助
[mongo@localhost bin]$ mongod --help
Allowed options:

General options:
  -h [ --help ]               show this usage information
  --version                   show version information
  -f [ --config ] arg         configuration file specifying additional options
  -v [ --verbose ]            be more verbose (include multiple times for more
                              verbosity e.g. -vvvvv)
  --quiet                     quieter output
  --port arg                  specify port number - 27017 by default
  --bind_ip arg               comma separated list of ip addresses to listen on
                              - all local ips by default
  --maxConns arg              max number of simultaneous connections - 20000 by
                              default
  --objcheck                  inspect client data for validity on receipt
  --logpath arg               log file to send write to instead of stdout - has
                              to be a file, not directory
  --logappend                 append to logpath instead of over-writing
  --pidfilepath arg           full path to pidfile (if not set, no pidfile is
                              created)
  --keyFile arg               private key for cluster authentication
  --nounixsocket              disable listening on unix sockets
  --unixSocketPrefix arg      alternative directory for UNIX domain sockets
                              (defaults to /tmp)
  --fork                      fork server process
  --syslog                    log to system's syslog facility instead of file
                              or stdout
  --auth                      run with security
  --cpu                       periodically show cpu and iowait utilization
  --dbpath arg                directory for datafiles - defaults to /data/db/
  --diaglog arg               0=off 1=W 2=R 3=both 7=W+some reads
  --directoryperdb            each database will be stored in a separate
                              directory
  --ipv6                      enable IPv6 support (disabled by default)
  --journal                   enable journaling
  --journalCommitInterval arg how often to group/batch commit (ms)
  --journalOptions arg        journal diagnostic options
  --jsonp                     allow JSONP access via http (has security
                              implications)
  --noauth                    run without security
  --nohttpinterface           disable http interface
  --nojournal                 disable journaling (journaling is on by default
                              for 64 bit)
  --noprealloc                disable data file preallocation - will often hurt
                              performance
  --noscripting               disable scripting engine
  --notablescan               do not allow table scans
  --nssize arg (=16)          .ns file size (in MB) for new databases
  --profile arg               0=off 1=slow, 2=all
  --quota                     limits each database to a certain number of files
                              (8 default)
  --quotaFiles arg            number of files allowed per db, requires --quota
  --repair                    run repair on all dbs
  --repairpath arg            root directory for repair files - defaults to
                              dbpath
  --rest                      turn on simple rest api
  --shutdown                  kill a running server (for init scripts)
  --slowms arg (=100)         value of slow for profile and console log
  --smallfiles                use a smaller default file size
  --syncdelay arg (=60)       seconds between disk syncs (0=never, but not
                              recommended)
  --sysinfo                   print some diagnostic system information
  --upgrade                   upgrade db if needed

Replication options:
  --oplogSize arg       size to use (in MB) for replication op log. default is 5% of disk space (i.e. large is good)

Master/slave options:
  --master                master mode
  --slave                   slave mode
  --source arg           when slave: specify master as <server:port>
  --only arg               when slave: specify a single database to replicate
  --slavedelay arg      specify delay (in seconds) to be used when applying master ops to slave
  --autoresync           automatically resync if slave data is stale

Replica set options:
  --replSet arg           arg is <setname>[/<optionalseedhostlist>]
  --replIndexPrefetch arg specify index prefetching behavior (if secondary) [none|_id_only|all]

Sharding options:
  --configsvr                declare this is a config db of a cluster; default port 27019; default dir /data/configdb
  --shardsvr                 declare this is a shard db of a cluster; default port 27018
  --noMoveParanoia      turn off paranoid saving of data for moveChunk.  this is on by default for now, but default will switch


[mongo@localhost bin]$ mongodump --help
Export MongoDB data to BSON files.

options:
  --help                      produce help message
  -v [ --verbose ]         be more verbose (include multiple times for more verbosity e.g. -vvvvv)
  --version                  print the program's version and exit
  -h [ --host ] arg        mongo host to connect to ( <set name>/s1,s2 for sets)
  --port arg                server port. Can also use --host hostname:port
  --ipv6                      enable IPv6 support (disabled by default)
  -u [ --username ] arg    username
  -p [ --password ] arg    password
  --dbpath arg                 directly access mongod database files in the given
                                     path, instead of connecting to a mongod  server -
                                     needs to lock the data directory, so cannot be used
                                     if a mongod is currently accessing the same path
  --directoryperdb           if dbpath specified, each db is in a separate directory
  --journal                      enable journaling
  -d [ --db ] arg              database to use
  -c [ --collection ] arg     collection to use (some commands)
  -o [ --out ] arg (=dump) output directory or "-" for stdout
  -q [ --query ] arg        json query
  --oplog                       Use oplog for point-in-time snapshotting
  --repair                      try to recover a crashed database
  --forceTableScan         force a table scan (do not use $snapshot)

八、工具连接问题
我是用的secureCRT连接的mongodb,连接进去后发现backspace和enter键有问题,每次都会显示之前输的东西,xshell则不会有这个问题

类似我按回车时:
[mongo@localhost ~]$ mongo
MongoDB shell version: 2.2.2
connecting to: test
> show dbs;show dbsshow dbshow dshow showshoshs^C
bye
[mongo@localhost ~]$ mongo

在本机上操作是没有这个问题,初步判断是工具的兼容性问题,搜索了以下解决办法,其中使用颜色方案不选择的话会显示之前设置的颜色方案,个人一直喜欢Traditional。

 

© 著作权归作者所有

共有 人打赏支持
kenyon_君羊
粉丝 500
博文 170
码字总数 121714
作品 0
杭州
其他
私信 提问
php xhprof扩展xhgui安装时提示mongodb未安装

报错信息如下: Problem 1 - Installation request for mongodb/mongodb 1.0.2 -> satisfiable by mongodb/mongodb[1.0.2]. - mongodb/mongodb 1.0.2 requires ext-mongodb ^1.1.0 -> the req......

MHZ
2017/01/05
247
0
Windowns、Ubuntu17.10 下安装 MongoDB - [图文并茂]

Windows 下安装 MongoDB MongoDB 安装包下载 点击下载 Windowns 平台: MongoDB 安装包 MongoDB 下载中心 MongoDB 安装 运行安装包,单击Next 选择安装路径 单击Next,完成安装 安装完成后,...

kangvcar
2017/11/01
0
0
CentOS-6安装使用mongodb

Centos-6.3下安装Mongodb,首先从http://www.mongodb.org/downloads下载软件压缩包mongodb-linux-x86_64-2.2.2.tgz。 安装机器:192.168.15.237 上传位置:/usr/local/ 软件安装:/usr/loca...

drewin
2013/10/21
0
0
Mac和Ubuntu18.04下MongoDB的安装

Mac安装mongodb 使用安装 从默认的配置文件启动mongodb 安装完成后,MongoDB服务启动、停止、重启命令如下: Mac下的mongodb可视化管理工具,推荐使用开源免费的, 下载地址:https://robomon...

翌日千里
2018/05/26
0
0
CentOS6.4 安装MongoDB

1、下载MongoDB(32位) wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.0.3.tgz 2、安装MongoDB(安装到/usr/local) 复制代码 tar zxvf mongodb-linux-x86_64-2.4.9.tgz mv m......

Surjur
2014/12/02
0
0

没有更多内容

加载失败,请刷新页面

加载更多

SpringBoot引入第三方jar包或本地jar包的处理方式

在开发过程中有时会用到maven仓库里没有的jar包或者本地的jar包,这时没办法通过pom直接引入,那么该怎么解决呢 一般有两种方法 - 第一种是将本地jar包安装在本地maven库 - 第二种是将本地j...

独钓渔
53分钟前
2
0
五、MyBatis缓存

一、MyBatis缓存介绍 缓存的使用可以明显的加快访问数据速度,提升程序处理性能,生活和工作中,使用缓存的地方很多。在开发过程中,从前端-->后端-->数据库等都涉及到缓存。MyBatis作为数据...

yangjianzhou
今天
2
0
最近研究如何加速UI界面开发,有点感觉了

最近在开发JFinal学院的JBolt开发平台,后端没啥说的,做各种极简使用的封装,开发者上手直接使用。 JBolt开发平台包含常用的用户、角色、权限、字典、全局配置、缓存、增删改查完整模块、电...

山东-小木
今天
3
0
《月亮与六便士》的读后感作文3000字

《月亮与六便士》的读后感作文3000字: 看完英国作家威廉.萨默塞特.毛姆所著《月亮与六便士》(李继宏译),第一疑问就是全书即没提到“月亮”,也没提到“六便士”。那这书名又与内容有什么...

原创小博客
昨天
2
0
微信网页授权获取用户信息(ThinkPHP5)+ 微信发送客服消息(一)

以thinkphp5为实例,创建控制器 class Kf extends Controller { /** * [protected description]微信公众号appid * @var [type] */ protected $appid = "xxxxxxxxxxxxxxx"; /** * [protected......

半缘修道半缘君丶
昨天
2
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部