CentOS 7 安装单机版MongoDB

  1. 下载

    选择适合自己系统版本的安装包,本文安装环境CentOS 7.

    MongoDB的官方网站是https://www.mongodb.com/,可以到官网上下载MongoDB的程序。之所以说是程序,是因为下载的安装包中MongoDB的相关程序已经编译好了,我使用的是mongodb-linux-x86_64-3.6.4.tgz ,可以在这个页面选择下载https://www.mongodb.com/download-center?jmp=nav#community

    [root@bigdata1 software]# cd /data/software/
    [root@bigdata1 software]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.4.tgz
  2. 安装和配置

    等待下载完成后解压,并更改文件夹名称为mongodb(可选)

    [root@bigdata1 software]# tar -zxf mongodb-linux-x86_64-3.6.4.tgz
    [root@bigdata1 software]# mv mongodb-linux-x86_64-3.6.4.tgz mongodb

    在mongodb目录下创建数据库目录db、创建日志目录logs、创建配置文件目录conf

    [root@bigdata1 software]# cd mongodb
    [root@bigdata1 mongodb]# mkdir db
    [root@bigdata1 mongodb]# mkdir logs
    [root@bigdata1 mongodb]# mkdir conf
    [root@bigdata1 mongodb]# ll
    total 120
    drwxr-xr-x. 2 root root   248 May  5 10:25 bin
    drwxr-xr-x. 2 root root    26 May  5 10:48 conf
    drwxr-xr-x. 4 root root  4096 May  5 10:55 db
    -rw-r--r--. 1 root root 34520 Apr 13 23:37 GNU-AGPL-3.0
    drwsr-xr-x. 2 root root    25 May  5 10:40 logs
    -rw-r--r--. 1 root root 16726 Apr 13 23:37 MPL-2
    -rw-r--r--. 1 root root  2195 Apr 13 23:37 README
    -rw-r--r--. 1 root root 57190 Apr 13 23:37 THIRD-PARTY-NOTICES

    在conf下新建配置文件mogodb.conf,并配置以下内容

    [root@bigdata1 mongodb]# cd conf/
    [root@bigdata1 conf]# touch mongodb.conf
    [root@bigdata1 conf]# vi mongodb.conf 

    配置内容,如果提示nohttpinterface不存在,注释了就好了

    
    #端口号,使用默认端口
    
    port = 27017
    
    #数据库目录
    
    dbpath = /data/software/mongodb/db
    
    #日志目录
    
    logpath = /data/software/mongodb/logs/mongodb.log
    logappend = true
    
    #是否以守护进程的方式运行
    
    fork = true
    
    #是否关闭http管理接口
    
    
    #nohttpinterface=true
    
  3. 启动验证

    启动

    ​ 启动mongodb需要使用bin目录下的mongod,如果通过-f 或–config= 来指定配置文件

    [root@bigdata1 conf]# cd /data/software/mongodb
    [root@bigdata1 mongodb]# ./bin/mongod -f conf/mongodb.conf 
    about to fork child process, waiting until server is ready for connections.
    forked process: 6770
    child process started successfully, parent exiting
    [root@bigdata1 mongodb]# ps -ef | grep mongodb
    root       6770      1 50 11:24 ?        00:00:51 ./bin/mongod -f conf/mongodb.conf
    root       6800   1124  3 11:26 pts/0    00:00:00 grep --color=auto mongodb

    连接

    ​ 连接mongodb需要使用bin目录下的mongo

    [root@bigdata1 mongodb]# ./bin/mongo
    MongoDB shell version v3.6.4
    connecting to: mongodb://127.0.0.1:27017
    MongoDB server version: 3.6.4
    Server has startup warnings: 
    2018-05-05T11:25:44.045+0800 I CONTROL  [initandlisten] 
    2018-05-05T11:25:44.045+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
    2018-05-05T11:25:44.045+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
    2018-05-05T11:25:44.045+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
    2018-05-05T11:25:44.045+0800 I CONTROL  [initandlisten] 
    2018-05-05T11:25:44.045+0800 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
    2018-05-05T11:25:44.045+0800 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server. 
    2018-05-05T11:25:44.045+0800 I CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP 
    2018-05-05T11:25:44.045+0800 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
    2018-05-05T11:25:44.045+0800 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
    2018-05-05T11:25:44.045+0800 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
    2018-05-05T11:25:44.045+0800 I CONTROL  [initandlisten] 
    2018-05-05T11:25:44.050+0800 I CONTROL  [initandlisten] 
    2018-05-05T11:25:44.050+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
    2018-05-05T11:25:44.050+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
    2018-05-05T11:25:44.050+0800 I CONTROL  [initandlisten] 
    2018-05-05T11:25:44.050+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
    2018-05-05T11:25:44.050+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
    2018-05-05T11:25:44.050+0800 I CONTROL  [initandlisten] 
    > show dbs
    admin   0.000GB
    config  0.000GB
    local   0.000GB
    > db.runoob.insert({"name":"菜鸟教程"})
    WriteResult({ "nInserted" : 1 })
    > show dbs
    admin   0.000GB
    config  0.000GB
    local   0.000GB
    test    0.000GB
    > db.runoob.find().pretty()
    { "_id" : ObjectId("5aed259516b74971a27b2528"), "name" : "菜鸟教程" }
    > 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值