MongoDB YUM 安装配置

来源:互联网 发布:java 中argc 编辑:程序博客网 时间:2024/05/16 06:10
MongoDB YUM 安装配置

第一部分:准备工作

1.全新centos6.3(以下简称centos)最基本的设置略过(比如用户、网络设置等等)。


2.这里可以联网了。这里用到的我写到一起了。
创建mongodb.repo文件
[root@localhost ~]# vim /etc/yum.repos.d/mongodb.repo

将如下内容粘贴到mongodb.repo文件中
[mongodb]   
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1  

第二部分:安装

1.执行安装命令
 [root@localhost ~]# yum -y install mongodb-org


2.配置防火墙

[root@localhost ~]# /etc/init.d/iptables status                ##查看防火墙状态

[root@localhost ~]# /etc/init.d/iptables stop                   ##本次关闭防火墙

[root@localhost ~]# /etc/init.d/iptables restart                ##重启防火墙

添加端口27017

[root@localhost ~]# /sbin/iptables -I INPUT -p tcp --dport 27017 -j ACCEPT

[root@localhost ~]# /etc/init.d/iptables save                  ##保存配置

[root@localhost ~]# /etc/init.d/iptables restart               ##重启防火墙 


3.启动Mongodb

[root@localhost ~]# service mongod start                       ##开启

[root@localhost ~]# service mongod stop                       ##关闭

[root@localhost ~]# service mongod restart                    ##重启


mongod --config=/etc/mongod.conf --journal


4.加入开机启动

[root@localhost ~]# chkconfig --level 35 mongod on


第三部分:配置

1.将#Auth = true前的#去掉,在bind_ip=127.0.0.1前面加个#号(若没有的话)

 [root@localhost ~]# vim /etc/mongod.conf

注意:#bind_ip=127.0.0.1 bind_ip用于限制IP,若前面没有#,则只有本机才能访问


2.添加登录验证

[root@localhost ~]# cd /usr/bin

[root@localhost ~]# ./mongo

>use admin;

>db.addUser("admin","admin");


第四部分:维护

1.删除数据库

[root@localhost ~]# cd /usr/bin/

[root@localhost ~]# ./mongo

>use admin;

>db.auth("admin","admin");

>use 139tong_v1;

>db.dropDatabase();


2.创建数据库

[root@localhost ~]# cd /usr/bin/

[root@localhost ~]# ./mongo

>use admin;

>db.auth("admin","admin");

>use 139tong_v1;

>db.addUser("admin","admin");


3.导出数据

[root@localhost ~]# cd /usr/bin/

[root@localhost ~]# ./mongo

>use admin;

>db.auth("admin","admin");

>quit();

[root@localhost ~]# ./mongodump -h 127.0.0.1:27017 -u admin -p admin -d 88mai_v2 -o /data/bak/88mai_mongo/2014-11-04/88mai_mongo/


4.导入数据

[root@localhost ~]# cd /usr/bin/

[root@localhost ~]# ./mongo

>use admin;

>db.auth("admin","admin");

>quit();

[root@localhost ~]# ./mongorestore -h 127.0.0.1 -u admin -p admin -d 139tong_v1 --drop /data/bak/139tong_mongo/2014-09-23/139tong_v1/

0 0
原创粉丝点击