mogondb安装

一.安装包准备

下载地址:
https://www.mongodb.com/try/download/community

image

二.安装

1. 解压安装
tar -zxvf mongodb-linux-x86_64-rhel70-4.4.13.tgz -C /opt/module/

cd /opt/module/

mv mongodb-linux-x86_64-rhel70-4.4.13 mongodb-4.4.13

cd mongodb-4.4.13/

mkdir data
mkdir logs

touch logs/mongodb.log

安装完配置环境变量,不做赘述.

2. 创建配置文件进行配置
[root@dbserver conf]# cat mongodb.conf 
dbpath=/opt/module/mongodb-4.4.13/data
logpath=/opt/module/mongodb-4.4.13/logs/mongodb.log
logappend=true
port=27017
bind_ip=0.0.0.0
fork=true
3. 启动服务
[root@dbserver conf]# mongod -f /opt/module/mongodb-4.4.13/conf/mongodb.conf 
about to fork child process, waiting until server is ready for connections.
forked process: 20903
child process started successfully, parent exiting
4. 创建管理员用户和密码
[root@dbserver conf]# mongo
MongoDB shell version v4.4.13
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("8bd1fadb-26d2-486d-8fdc-540e2dc8af9b") }
MongoDB server version: 4.4.13
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
	https://community.mongodb.com
---
The server generated these startup warnings when booting: 
        2022-04-20T17:47:59.264+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
        2022-04-20T17:47:59.264+08:00: You are running this process as the root user, which is not recommended
        2022-04-20T17:47:59.264+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
        2022-04-20T17:47:59.264+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
        2022-04-20T17:47:59.264+08:00: Soft rlimits too low
        2022-04-20T17:47:59.264+08:00:         currentValue: 1024
        2022-04-20T17:47:59.264+08:00:         recommendedMinimum: 64000
---
---
        Enable MongoDB's free cloud-based monitoring service, which will then receive and display
        metrics about your deployment (disk utilization, CPU, operation statistics, etc).

        The monitoring data will be available on a MongoDB website with a unique URL accessible to you
        and anyone you share the URL with. MongoDB may use this information to make product
        improvements and to suggest MongoDB products and deployment options to you.

        To enable free monitoring, run the following command: db.enableFreeMonitoring()
        To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> use admin;
switched to db admin
> db.createUser({user:'root',pwd:'root',roles:[{role:'root',db:'admin'}]});
Successfully added user: {
	"user" : "root",
	"roles" : [
		{
			"role" : "root",
			"db" : "admin"
		}
	]
}
> exit
bye

配置文件中添加验证:
auth=true

重启mongo:

[root@dbserver conf]# mongod --shutdown -f /opt/module/mongodb-4.4.13/conf/mongodb.conf 
killing process with pid: 20903
[root@dbserver conf]# mongod  -f /opt/module/mongodb-4.4.13/conf/mongodb.conf 
about to fork child process, waiting until server is ready for connections.
forked process: 21118
child process started successfully, parent exiting

4. 测试远程连接

image

posted @ 2022-04-20 18:03  乐百事  阅读(54)  评论(0编辑  收藏  举报