Linux:MongoDB_2.6.12版本的安装及配置

场景:公司老项目服务器迁移,因为老项目安装的版本非常老,所以记录下老版本的安装过程。

操作系统:CentOS Linux release 7.2.1511

目标安装版本:MongoDB_2.6.12

下载地址:https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.12.tgz

一、下载解压

[root@Arvin627 ~]# cd /data/
[root@Arvin627 data]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.12.tgz
[root@Arvin627 data]# tar zxvf mongodb-linux-x86_64-2.6.12.tgz
[root@Arvin627 data]# mv mongodb-linux-x86_64-2.6.12 /usr/local/mongodb-2.6.12
[root@Arvin627 data]# mkdir -p /data/mongodb/mongodb_data/
[root@Arvin627 data]# mkdir -p /data/mongodb/mongodb_log/

二、启动MongoDB

## 启动MongoDB
[root@Arvin627 ~]# /usr/local/mongodb-2.6.12/bin/mongod --port 27017 --fork --dbpath=/data/mongodb/mongodb_data/ --logpath=/data/mongodb/mongodb_log/mongodb.log --logappend


## 查看MongoDB是否启动
[root@Arvin627 ~]# netstat -lanp | grep "27017" 


[root@Arvin627 ~]# cd /usr/local/mongodb-2.6.12/bin/

## 进入MongoDB数据库控制台
[root@Arvin627 bin]# ./mongo
        use admin              ## 进入admin数据库
        db.shutdownServer()    ## 关闭MongoDB数据库
        exit                   ## 退出

三、设置MongoDB数据库

## 进入MongoDB安装目录
[root@Arvin627 ~]# cd /usr/local/mongodb-2.6.12/

## 编辑配置文件
[root@Arvin627 ~]# vi /usr/local/mongodb-2.6.12/mongodb.conf

## mongodb.conf内容
port=27017
dbpath=/data/mongodb/mongodb_data
logpath=/data/mongodb/mongodb_log/mongodb.log
pidfilepath=/usr/local/mongodb-2.6.12/mongo.pid
fork=true
logappend=true
shardsvr=true
directoryperdb=true

四、设置开机启动MongoDB

[root@Arvin627 ~]# vi /etc/init.d/mongod

## mongod内容
#!/bin/sh
# chkconfig: - 64 36
# description:mongod

case $1 in

start)
/usr/local/mongodb-2.6.12/bin/mongod  --maxConns 20000  --config /usr/local/mongodb-2.6.12/mongodb.conf
;;

stop)
/usr/local/mongodb-2.6.12/bin/mongo 127.0.0.1:27017/admin --eval "db.shutdownServer()"
;;

status)
/usr/local/mongodb-2.6.12/bin/mongo 127.0.0.1:27017/admin --eval "db.stats()"
;;
esac


## 添加脚本执行权限
[root@Arvin627 init.d]# chmod +x /etc/init.d/mongod
## 设置开机启动
[root@Arvin627 init.d]# chkconfig mongod on
## 启动MongoDB
[root@Arvin627 init.d]# service mongod start

五、添加环境变量

[root@Arvin627 /]# vi /etc/profile

## 在最后一行添加下面的代码
export PATH=$PATH:/usr/local/mongodb-2.6.12/bin



## 使配置立即生效
[root@Arvin627 /]# source /etc/profile

## 进入MongoDB控制台
[root@Arvin627 /]# mongo  

六、数据库导入导出

## 导出
[root@oldServer data]# mongodump --host 127.0.0.1:27017 -d local -o /data

## 导入
[root@oldServer bin]# ./mongorestore --port 27017 --authenticationDatabase admin -d local --drop /data/local

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
为什么会这样[user_mongo@nosql01 replicaset]$ cd /opt [user_mongo@nosql01 opt]$ ll total 0 drwxr-xr-x. 3 root root 25 Mar 16 17:08 servers drwxr-xr-x. 2 root root 51 Mar 16 17:10 software [user_mongo@nosql01 opt]$ tar -zxvf /opt/software/mongodb-linux-x86_64-rhel70-4.4.12.tgz -C /opt/servers/mongodb_demo/replicaset/ mongodb-linux-x86_64-rhel70-4.4.12/LICENSE-Community.txt tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/LICENSE-Community.txt: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/MPL-2 tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/MPL-2: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/README tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/README: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/THIRD-PARTY-NOTICES tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/THIRD-PARTY-NOTICES: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/install_compass tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/install_compass: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongo tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongo: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongod tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongod: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongos tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongos: Cannot open: No such file or directory tar: Exiting with failure status due to previous errors [user_mongo@nosql01 opt]$ tar -zcvf /opt/software/mongodb-linux-x86_64-rhel70-4.4.12.tgz -C /opt/servers/mongodb_demo/replicaset/ tar: Cowardly refusing to create an empty archive Try `tar --help' or `tar --usage' for more information.
最新发布
06-01

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值