Linux (Centos7) yum install MongDB

1. Installation steps

1. Use wget to download the MongDB installation package

#没有wget的需先下载:  yum install -y wget
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-5.0.4.tgz

insert image description here
2. Unzip to/usr/local

tar -zxvf mongodb-linux-x86_64-rhel70-5.0.4.tgz -C /usr/local

insert image description here
3. Configure the database file storage directory and log files

mkdir -p /data/MyData
mkdir -p /data/logs && touch /data/logs/mongodb.log

insert image description here
4. Add configuration filesmongodb.conf

#在mongodb/bin目录添加mongodb.conf,添加以下内容
cd /usr/local/mongodb-linux-x86_64-rhel70-5.0.4/bin
vim mongodb.conf
#数据库路径-第三步自己创建的
dbpath=/data/MyData
#日志输出文件路径-第三步自己创建的
logpath=/data/logs/mongodb.log
#错误日志采用追加模式
logappend=true
#启用日志文件,默认启用
journal=true
#这个选项可以过滤掉一些无用的日志信息,若需要调试使用请设置为false
quiet=true
#端口号 默认为27017
port=27017
#允许远程访问
bind_ip=0.0.0.0
#开启子进程
fork=true
#取消账号密码,直接登录
#auth=true

insert image description here

5. Add the mongoDB service to the environment variable and refresh the configuration file

vim /etc/profile

export PATH=$PATH:/usr/local/mongodb-linux-x86_64-rhel70-5.0.4/bin

source /etc/profile

insert image description here

5. Start and check whether the startup is successful

./mongod --config mongodb.conf  #启动服务
netstat -lanp | grep "27017"    #查看通信端口

insert image description here
6. Database operation - enable user login - need to enter account password to log in

6.1-Login: Arbitrary directory inputmongo

insert image description here
6.2-Add user password

#用户都储存在admin数据库
use admin
#添加一个用户
db.createUser({
    
    user:"root",pwd:"123456",roles:[{
    
    role:"root",db:"admin"}]})
#添加后退出数据库:
exit

insert image description here
6.3-Configuration file to enable user login

#mongodb/bin目录下修改配置文件mongodb.conf,取消注释 auth=true
cd /usr/local/mongodb-linux-x86_64-rhel70-5.0.4/bin/
vim mongodb.conf

insert image description here
6.4 - Restart

#mongodb/bin目录下执行
cd /usr/local/mongodb-linux-x86_64-rhel70-5.0.4/bin/
./mongod --config mongodb.conf

2. Use GUI tools to connect remotely

Remote tool download address: https://nosqlbooster.com/downloads

Note: Before testing the connection, you need to close the firewalls of both parties, or open the port of mongodb.

#方法一:关闭防火墙
systemctl stopfirewalld  #重启防火墙服务
#方法二:开放mongdb端口,重启防火墙
firewall-cmd --zone=public --add-port=27017/tcp --permanent #开放端口
systemctl restart firewalld  #重启防火墙服务

1. Open after installation, create a new connection, modify it to your own mongo ip, clickTest Connection

insert image description here
2. After the test connection is successful, close it and click OK

insert image description here
3. Enter the ip of your own mongo

insert image description here
4. Enter the account password you added before, and click Save & Connect Connect

insert image description here
5. The connection is successful

insert image description here

Guess you like

Origin blog.csdn.net/dontYouWorry/article/details/129246500