码迷,mamicode.com
首页 > 其他好文 > 详细

单点安装mongo3.4.4

时间:2018-04-27 15:55:05      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:文件的   dwr   SM   用户   警告   守护   变量   ica   成功   

下载解压

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.4.tgz
tar zxvf mongodb-linux-x86_64-rhel62-3.4.4.tgz

目录规划

[root@qiqi3 data]# tree  mongodb/
/data/mongodb/
├── bin 解压目录里复制过来
├── data 数据目录
├── key  key目录
└── logs log目录
├── conf 存放配置文件的目录

设置环境变量

vim /etc/profile
export PATH=/data/mongodb/bin:$PATH
source /etc/profile

新建配置文件mongodb.conf

###极简配置
port = 3717          #端口  默认是27017
pidfilepath = /data/mongodb/logs/mongo3717.pid  #pid目录
dbpath = /data/mongodb/data/           #数据文件存放目录  
logpath = /data/mongodb/logs/mongodb.log      #日志文件存放目录
fork = true    #以守护程序的方式启用,即在后台运行

启动mongo

/data/mongodb/bin/mongod -f /app/mongodb/conf/mongod.conf &

关闭mongo

不要kill -9粗暴的关闭mongo 一定要按照正确的方式关闭mongo

否则容易起不来,出现不可预知的错误

两种方式
1. kill -15 pid
2. 进入mongo
   use admin
   db.shutdownServer()

无密码登录mongo

 ./mongo --port 3717 #因为修改了默认端口 所以指定端口

解决警告信息

echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
写入 /etc/rc.local
重启mongo

创建管理用户root

#要先切换数据库
>use admin;

#创建root用户 密码是 root123 角色是root
> db.createUser({user: root, pwd: root123, roles: [root]}) Successfully added user: { "user" : "root", "roles" : [ "root" ] } #验证是否创建成功 返回1是成功 > db.auth(root,root123); 1 创建完毕后记得在mongodb.conf 里加入 auth=true 然后重启mongo

指定用户名密码和库登录

/data/mongodb/bin/mongo --port 3717 -uroot -proot123 --authenticationDatabase "admin"

创建指定库指定用户

> use article #创建数据库 有则切换 无则创建
switched to db article
> db.createUser({user:zwVic,pwd:adgjmp123,roles: [{role:readWrite,db:article}]}) #创建用户
Successfully added user: {
    "user" : "zwVic",
    "roles" : [
        {
            "role" : "readWrite",
            "db" : "article"
        }
    ]
}

查看所有库

> show dbs;
# 如果库是空的 使用 show dbs; 是无法看到的

#所以上文创建的数据库,暂时无法看到,按照如下方式插入数据后重新看
> db.article.insert({"name":"不粘人的小妖精"})
WriteResult({ "nInserted" : 1 })
> show dbs
local   0.078GB
article  0.078GB
test    0.078GB

查看所有用户

> use admin;
switched to db admin
> db.system.users.find()
{ "_id" : "admin.root", "user" : "root", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "aISmEOV2yp9YKtKNvkB6tQ==", "storedKey" : "eM1nymOH5t+ju7hB2mv8puPuPPw=", "serverKey" : "Qb4ljaCDutLx1Uh6WF/cFyBM4Go=" } }, "roles" : [ { "role" : "root", "db" : "admin" } ] }
{ "_id" : "article.zwVic", "user" : "zwVic", "db" : "article", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "LZlGNBxNbj9SbDfIxt1AcA==", "storedKey" : "PVAib5n/rdxCgVF13k2Rz00OaOc=", "serverKey" : "U+XtPqx+jGp5T5yQqFUFWQo01R0=" } }, "roles" : [ { "role" : "readWrite", "db" : "article" } ] }
{ "_id" : "admin.run", "user" : "run", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "ySccw/9CHRGM/IU6HHqyQw==", "storedKey" : "Ycg66+lREVH5UQbLqbZBd6KBWuY=", "serverKey" : "IL62tLJhoBzzeHJLR1MM4jv3O2I=" } }, "roles" : [ { "role" : "readWrite", "db" : "runoob" } ] }
{ "_id" : "runoob.oob", "user" : "oob", "db" : "runoob", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "sgwrur6LgZ5Td1yuj6OJ8A==", "storedKey" : "QEFrCbcDmn+V51wZKQxYxKjeEdM=", "serverKey" : "xoHLJ7EDt/Ep9s8r9VZYk1VlVIw=" } }, "roles" : [ { "role" : "readWrite", "db" : "runoob" } ] }

查看当前数据库的一些信息

> use admin; #use 你想看的数据库名字;
> db.stats()
{
    "db" : "admin",
    "collections" : 2,
    "views" : 0,
    "objects" : 6,
    "avgObjSize" : 209.16666666666666,
    "dataSize" : 1255,
    "storageSize" : 69632,
    "numExtents" : 0,
    "indexes" : 3,
    "indexSize" : 102400,
    "ok" : 1
}

 

单点安装mongo3.4.4

标签:文件的   dwr   SM   用户   警告   守护   变量   ica   成功   

原文地址:https://www.cnblogs.com/lazyball/p/8962359.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!