mongoDB安装
# 以Linux为例安装
- yum源
创建文件/etc/yum.repos.d/mongodb-org-3.6.repo
, 加yum源:
[mongodb-org-3.6]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc
1
2
3
4
5
6
2
3
4
5
6
- 安装
sudo yum install -y mongodb-org
1
- 运行
[root@pdai yum.repos.d]# systemctl start mongod
[root@pdai yum.repos.d]# sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2020-07-28 09:59:55 CST; 26s ago
Docs: https://docs.mongodb.org/manual
Process: 8868 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
Process: 8865 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 8863 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 8862 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
Main PID: 8872 (mongod)
CGroup: /system.slice/mongod.service
└─8872 /usr/bin/mongod -f /etc/mongod.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# 连接和建库
- 连接
[root@pdai yum.repos.d]# mongo --host 127.0.0.1:27017
MongoDB shell version v3.6.19
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("cb27e5a9-600f-4f57-9096-c7348a9ae5f9") }
MongoDB server version: 3.6.19
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
2020-07-28T09:59:54.521+0800 I STORAGE [initandlisten]
2020-07-28T09:59:54.521+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2020-07-28T09:59:54.521+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2020-07-28T09:59:55.705+0800 I CONTROL [initandlisten]
2020-07-28T09:59:55.705+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-07-28T09:59:55.705+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-07-28T09:59:55.705+0800 I CONTROL [initandlisten]
2020-07-28T09:59:55.705+0800 I CONTROL [initandlisten]
2020-07-28T09:59:55.705+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2020-07-28T09:59:55.705+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2020-07-28T09:59:55.705+0800 I CONTROL [initandlisten]
2020-07-28T09:59:55.705+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2020-07-28T09:59:55.705+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2020-07-28T09:59:55.705+0800 I CONTROL [initandlisten]
> show dbs;
admin 0.000GB
config 0.000GB
local 0.000GB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
- 建库
> use testdb;
switched to db testdb
1
2
2
编辑 (opens new window)
上次更新: 2024/02/22, 14:03:19