logo头像
Snippet 博客主题

centos7下mongodb安装

1.下载mongodb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
╭─lzq@localhost.localdomain ~  
╰─➤ cd /usr/local
╭─lzq@localhost.localdomain /usr/local
╰─➤ su
密码:
╭─root@localhost.localdomain /usr/local #下载命令
╰─➤ wget -XGET https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.2.tgz
--2019-07-19 10:07:14-- https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.2.tgz
正在连接 127.0.0.1:8118... 已连接。
已发出 Proxy 请求,正在等待回应... 200 OK
长度:84586631 (81M) [application/x-gzip]
正在保存至: “mongodb-linux-x86_64-rhel70-4.0.2.tgz”

100%[======================================>] 84,586,631 5.06MB/s 用时 20s

2019-07-19 10:07:40 (4.14 MB/s) - 已保存 “mongodb-linux-x86_64-rhel70-4.0.2.tgz” [84586631/84586631])
╭─root@localhost.localdomain /usr/local #解压命令
╰─➤ tar -zxvf mongodb-linux-x86_64-rhel70-4.0.2.tgz
╭─root@localhost.localdomain /usr/local
╰─➤ mv mongodb-linux-x86_64-rhel70-4.0.2 mongodb

2.配置文件

2.1mongo配置

在/usr/local/mongodb/bin下创建一个mongodb.conf文件copy如下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 日志文件位置
logpath=/usr/local/mongodb/logs

# 数据库文件位置
dbpath=/usr/local/mongodb/data

# 以追加方式写入日志
logappend=true

# 是否以守护进程方式运行
fork = true

# 默认27017
port = 27017

#绑定ip
bind_ip=127.0.0.1
2.1.1创建日志文件和数据库文件夹
1
2
3
4
╭─root@localhost.localdomain /usr/local  
╰─➤ touch /usr/local/mongodb/logs
╭─root@localhost.localdomain /usr/local
╰─➤ mkdir /usr/local/mongodb/data

2.2配置文件详解

参考博客

3.启动

3.1启动命令

在/usr/local/mongodb/bin下执行以下命令

1
2
3
4
5
6
╭─root@localhost.localdomain /usr/local/mongodb/bin  
╰─➤ ./mongod -f mongodb.conf 1 ↵
2019-07-19T10:34:20.934+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
about to fork child process, waiting until server is ready for connections.
forked process: 23803
child process started successfully, parent exiting

看到child process started successfully, parent exiting并且没有ERROR就启动成功了

3.2遇到的错误

3.2.1 ERROR: child process failed, exited with error number 1
1
2
3
4
5
6
7
╭─root@localhost.localdomain /usr/local/mongodb/bin  
╰─➤ ./mongod -f mongodb.conf 1 ↵
2019-07-19T10:32:28.196+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
about to fork child process, waiting until server is ready for connections.
forked process: 23525
ERROR: child process failed, exited with error number 1
To see additional information in this output, start without the "--fork" option.

这是因为将日志文件创建为了日志文件夹

删除日志文件夹创建日志文件
rm -rf /usr/local/mongodb/logs
touch /usr/local/mongodb/logs

3.2.1 ERROR: child process failed, exited with error number 100
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
╭─root@localhost.localdomain /usr/local/mongodb/bin  
╰─➤ ./mongod -f mongodb.conf
2019-07-19T10:45:03.074+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
about to fork child process, waiting until server is ready for connections.
forked process: 24158
ERROR: child process failed, exited with error number 100
To see additional information in this output, start without the "--fork" option.
╭─root@localhost.localdomain /usr/local/mongodb/bin
╰─➤ lsof -i:27017 100 ↵
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mongod 23803 root 11u IPv4 132396 0t0 TCP localhost:27017 (LISTEN)
╭─root@localhost.localdomain /usr/local/mongodb/bin
╰─➤ kill -9 23803
╭─root@localhost.localdomain /usr/local/mongodb/bin
╰─➤ ./mongod -f mongodb.conf
2019-07-19T10:45:43.419+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
about to fork child process, waiting until server is ready for connections.
forked process: 24192
child process started successfully, parent exiting

这是因为已经启动了mongodb在启动会报的错

解决方法:杀掉启动的mongodb进程然后启动

微信打赏