#.解压重命名
[root@single03 download]# tar -zxf mongodb-linux-x86_64-rhel70-4.0.24.tgz -C /opt/software/
[root@single03 download]# cd ../software/
[root@single03 software]# mv mongodb-linux-x86_64-rhel70-4.0.24 mongodb
[root@single03 software]# cd mongodb/
# 新建数据和日志存储目录
[root@single03 mongodb]# mkdir -p data/db/
[root@single03 mongodb]# mkdir log
[root@single03 mongodb]# pwd
/opt/software/mongodb
#新建配置文件
[root@single03 mongodb]# vim mongo.conf
-----------------------------------------
systemLog:
destination: file
path: "/opt/software/mongodb/log/mongod.log"
logAppend: true
storage:
dbPath: "/opt/software/mongodb/data/db"
journal:
enabled: true
processManagement:
fork: true
net:
bindIp: localhost,192.168.xxx.xxx
port: 27017
------------------------------------------
# 添加、激活环境变量
[root@single03 ~]# vim /etc/profile.d/my.sh
--------------
# MONGODB
export MONGODB_HOME=/opt/software/mongodb
export PATH=$MONGODB_HOME/bin:$PATH
--------------
source /etc/profile
# 激活mongo.conf配置文件
[root@single03 mongodb]# mongod -config ./mongo.conf
about to fork child process, waiting until server is ready for connections.
forked process: 6521
child process started successfully, parent exiting
[root@single03 mongodb]# ps -ef | grep mongd
root 6572 1627 0 12:02 pts/0 00:00:00 grep --color=auto mongd
[root@single03 mongodb]# ps -ef | grep mongod
root 6521 1 0 12:00 ? 00:00:01 mongod -config ./mongo.conf
root 6574 1627 0 12:03 pts/0 00:00:00 grep --color=auto mongod
#启动mongodb
[root@single03 mongodb]# mongo
...
# 查看库
> show dbs
---------------
admin 0.000GB
config 0.000GB
local 0.000GB
----------------
# 查看表
> show tables
> show collections
# 向表中插入数据
> db.teststu.insert({"id":1,"name":"zs"})
WriteResult({ "nInserted" : 1 })
# 查看表数据
> db.teststu.find()
{ "_id" : ObjectId("63351feb7f08cbd01e3bb38a"), "id" : 1, "name" : "zs" }
mongodb 安装
最新推荐文章于 2024-08-24 14:54:02 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)