服务器运维
MongoDB
2025-04-03 14:50
阅读:112
评论:0
Linux tar.gz安装mongodb
安装环境CentOS 6,理论其他环境一样,下载对应版本即可 安装 下载wget <https://fastdl.mongodb.org/linux/mongodb-linux-x8664-rhel62-4.4.16.tgz> 解压tar -zxvf mongodb-linux-x86\64-rhe
安装环境CentOS 6,理论其他环境一样,下载对应版本即可
安装
- 下载wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-4.4.16.tgz
- 解压tar -zxvf mongodb-linux-x86_64-rhel62-4.4.16.tgz
- mv mongodb-linux-x86_64-rhel62-4.4.16 /usr/local/mongodb
- 环境配置export PATH=/usr/local/mongodb/bin:$PATH
mongo.conf配置
1
2
3
4
5
6
7
8
9
#加入以下内容dbpath=/usr/local/mongodb/data #事先创建该文件logpath=/usr/local/mongodb/logs/mongo.log #事先创建该文件logappend=truejournal=truequiet=trueport=27017fork=true #后台运行bind_ip=0.0.0.0 #允许任何IP进行连接- mongo.log必须事先创建,否则会提示如下错误
1
2
ERROR: child process failed, exited with 1 To see additional information in this output, start without the "--fork" option.- 启动mongodb命令如下
/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongo.conf
配置启动脚步
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
#!/bin/bash#chkconfig: 2345 80 90#description: mongodbstart() { /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongo.conf}stop() { /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongo.conf --shutdown}case "$1" in start) start ;; stop) stop ;; status) netstat -tulnp|grep mongod ;; restart) stop start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1esac设置启动
1
2
3
4
vi /etc/init.d/mongodbchmod +x mongodb chkconfig --add mongodbchkconfig mongodb on