千家信息网

mongodb2.6安装

发表于:2025-11-10 作者:千家信息网编辑
千家信息网最后更新 2025年11月10日,操作系统环境如下:[root@zxl-nginx ~]# cat /etc/issueCentOS release 6.4 (Final)Kernel \r on an \m[root@zxl-ngi
千家信息网最后更新 2025年11月10日mongodb2.6安装

操作系统环境如下:

[root@zxl-nginx ~]# cat /etc/issueCentOS release 6.4 (Final)Kernel \r on an \m[root@zxl-nginx ~]# uname -r2.6.32-358.el6.x86_64

mongodb2.6下载地址

# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.11.tgz

安装mongodb2.6

[root@zxl-nginx src]# ll mongodb-linux-x86_64-2.6.11.gz -rw-r--r-- 1 root root 116659120 Dec 13 09:32 mongodb-linux-x86_64-2.6.11.gz[root@zxl-nginx src]# tar fxz mongodb-linux-x86_64-2.6.11.gz[root@zxl-nginx src]# mv mongodb-linux-x86_64-2.6.11 /usr/local/[root@zxl-nginx src]# ln -s  /usr/local/mongodb-linux-x86_64-2.6.11 /usr/local/mongodb

创建mongodb用户

[root@zxl-nginx src]#groupadd -r mongodb[root@zxl-nginx src]#useradd -r -g mongodb mongodb

创建mongodb数据库和logs目录

[root@zxl-nginx src]#mkdir /data/[root@zxl-nginx src]#mkdir /data/logs /data/m20000[root@zxl-nginx src]#chown mongodb.mongodb /data -R

mongo环境变量配置

vim /etc/profileexport PATH=$PATH:/usr/local/mongodb/bin

加载环境配置文件

source /ect/profile

启动mongodb

mongod --dbpath=/data/m20000/ --logpath=/data/logs/m20000.log  --logappend -fork --port 20000

登陆mongodb

[root@zxl-nginx ~]# mongo --port 20000MongoDB shell version: 2.6.11connecting to: 127.0.0.1:20000/test> dbtest


创建数据以及查看

> use zxlswitched to db zxl> db.ha.insert({name:"abc",age:21})WriteResult({ "nInserted" : 1 })> db.ha.find(){ "_id" : ObjectId("56739b27154b52481c1c5749"), "name" : "abc", "age" : 21 }


0