Mongodb

0.概述

mongodb版本:4.0.2

linux版本:redhat 6.5

安装方式:二进制安装

1.关闭防火墙

/etc/init.d/iptables status
/etc/init.d/iptables stop
chkconfig --list iptables
chkconfig iptables off

vi /etc/selinux/config
-----------------------
SELINUX=disabled

2.创建用户组和目录

useradd mongodb
passwd mongodb

mkdir -p /opt/mongodb_data
mkdir -p /opt/mongodb_log
chown -R mongodb:mongodb /opt

3.操作系统参数修改

vi /etc/security/limits.conf
---------------------------------------------
mongodb soft nproc 65536
mongodb hard nproc 65536
mongodb soft nofile 65536
mongodb hard nofile 65536

4.安装mongodb

su - mongodb
tar -zxvf mongodb-linux-x86_64-rhel62-4.0.2.tgz
mv mongodb-linux-x86_64-rhel62-4.0.2 mongodb-4.0.2

5.配置参数文件

su - root
vi /etc/mongodb.conf
--------------------------------------------
port = 27001
dbpath = /opt/mongodb_data
logpath = /opt/mongodb_log/mongodb.log
logappend = true
fork = true
journal = true
bind_ip = 0.0.0.0
#auth = true

更改参数文件权限
chown mongodb:mongodb /etc/mongodb.conf

6.配置mongodb环境变量

vi .bash_profile
------------------------------
PATH=$PATH:$HOME/bin:/home/mongodb/mongodb-4.0.2/bin

source .bash_profile

7.启动mongod服务

mongod -f /etc/mongodb.conf

8.登陆mongodb,使用非验证模式登陆

mongo --port=27001

9.创建管理员角色

use admin;

db.createUser(
{
user: "root",
pwd: "abc123",
roles: [ { role: "root", db: "admin" } ]
}
)

关闭mongodb
db.shutdownServer()

10.修改配置参数,重启mongodb服务

更改 /etc/mongodb.conf
--------------------------------------------
#auth = true --> auth = true

mongod -f /etc/mongodb.conf

11.重新登陆,使用验证方式

mongo --port=27001 -u root -p abc123 --authenticationDatabase admin

原文地址:https://www.cnblogs.com/ddzj01/p/9911104.html