Mongodb 在CentOS6.2上的安装
来源:互联网 发布:网络自制剧最新排行榜 编辑:程序博客网 时间:2024/05/21 23:52
mongodb-linux-x86_64-2.2.1.tgz
[root@lfy mongodb]# wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.2.1.tgz
[root@lfy mongodb]# tar zxvf mongodb-linux-x86_64-2.2.1.tgz
[root@lfy mongodb]# mv mongodb-linux-x86_64-2.2.1 /opt/mongodb
#创建mongodb的数据目录和log目录
[root@lfy mongodb]# mkdir /opt/mongodb/data
[root@lfy mongodb]# mkdir /opt/mongodb/log
#创建mongodb的log文件
[root@lfy mongodb]# touch /opt/mongodb/log/mongodb.log
#创建mongodb的配置目录
[root@lfy mongodb]# mkdir /opt/mongodb/config
#创建mongodb服务停止文件
[root@lfy mongodb]# vi
--输入下面内容
#!/bin/bash
--写入到mongodb-stop文件
:w /opt/mongodb/mongodb-stop
注意:其中192.168.10.21是安装mongodb的服务器IP地址,即CentOS6.2使用的IP。
#增加mongodb-start和mongodb-stop的执行权限
[root@lfy mongodb]# chmod +x /opt/mongodb/mongodb-start
[root@lfy mongodb]# chmod +x /opt/mongodb/mongodb-stop
[root@lfy mongodb]# chmod +x /etc/rc.d/init.d/mongodb /etc/init.d/mongodb
[root@lfy mongodb]# grep mongodb /etc/passwd
mongodb:x:498:502::/opt/mongodb:/bin/bash
#给mongodb:mongodb增加执行权限
[root@lfy mongodb]# chown mongodb:mongodb -R /opt/mongodb/
3.启动mongodb
[root@lfy mongodb]# service mongodb start
Starting MongoDB... all output going to: /opt/mongodb/log/mongodb.log
forked process: 32190
child process started successfully, parent exiting
[root@lfy mongodb]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT
[root@lfy mongodb]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 28017 -j ACCEPT
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
# 查看规则是否生效
[root@lfy mongodb]# service iptables status
或者:
[root@lfy mongodb]# iptables -L -n
MongoDB shell version: 2.2.1
connecting to: test
Tue Nov 27 19:03:22 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed
MongoDB shell version: 2.2.1
connecting to: 192.168.10.21:27017/test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
> db
test
MongoDB shell version: 2.2.1
connecting to: 192.168.10.21:27017/test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
> db
test
> show collections;
Tue Nov 27 19:06:53 uncaught exception: error: {
"$err" : "unauthorized db:test ns:test.system.namespaces lock type:1 client:192.168.10.21",
"code" : 10057
}
>
Stopping MongoDB
[root@lfy mongodb]# vi /opt/mongodb/config/mongodb.cnf
设置auth = false
[root@lfy mongodb]# service mongodb start
3.添加超级管理员
MongoDB shell version: 2.2.1
connecting to: 192.168.10.21:27017/test
> show dbs
local (empty)
> use admin
switched to db admin
> show collections
> db
admin
> db.addUser("root", "admin");
{
"user" : "root",
"readOnly" : false,
"pwd" : "bb961f1e866e2d4a2b85c2675b6a3c3b",
"_id" : ObjectId("50b4e79eaeb4e7fe8996721c")
}
> show collections;
system.indexes
system.users
> db.system.users.find();
{ "_id" : ObjectId("50b4e79eaeb4e7fe8996721c"), "user" : "root", "readOnly" : false, "pwd" : "bb961f1e866e2d4a2b85c2675b6a3c3b" }
> exit
bye
[lify@lfy ~]$
Stopping MongoDB
[root@lfy ~]# vi /opt/mongodb/config/mongodb.cnf
设置auth = true
[root@lfy ~]# service mongodb start
Starting MongoDB... all output going to: /opt/mongodb/log/mongodb.log
forked process: 32393
child process started successfully, parent exiting
MongoDB shell version: 2.2.1
connecting to: 192.168.10.21/test
> db
test
> use store
switched to db store
> db
store
> db.customers.insert({key:1,name:"yang"});
Tue Nov 27 19:33:08 uncaught exception: getlasterror failed: { "errmsg" : "need to login", "ok" : 0 }
/*插入数据不成功,用管理员登录,并建立新账户*/
> use adminswitched to db admin
> db.auth('root','admin');
1
> show dbs;
admin 0.203125GB
local (empty)
store (empty)
> use store
switched to db store
> db
store
> db.addUser('yang','yang');
{
"user" : "yang",
"readOnly" : false,
"pwd" : "faa29b3be8dab9ff195ab49c56bd133c",
"_id" : ObjectId("50b4ebc2363cd6ea440763de")
}
> db
store
/*重新登录*/
> db.auth('yang','yang');1
> show collections;
system.indexes
system.users
> db.customers.insert({key:1,name:"yang"});
> show collections;
customers
system.indexes
system.users
> db.customers.find();
{ "_id" : ObjectId("50b4ebec363cd6ea440763df"), "key" : 1, "name" : "yang" }
>
mongodb的安装介绍完毕。
- Mongodb 在CentOS6.2上的安装
- MongoDB 3.0的在CentOS6.5/linux上的安装(何志雄)
- MongoDB在ubuntu上的安装-2
- yael在CentOS6.5上的安装
- Docker在CentOS6.5上的安装
- centos6.5 86_64上安装mongodb
- Mongodb在Windows上的安装
- Mongodb在Windows上的安装
- MongoDB在ubuntu上的安装
- mongoDB在centos7上的安装
- mongodb在ubutun上的安装
- 在CentOS6上安装 maven
- MongoDB的使用(1):在Centos7上安装MongoDB
- 在CentOS6.4上安装oracle10g需要的补丁
- pyenv在CentOS6.6上的安装和使用
- redis2.6.4 在centos6.4上的安装
- redis2.6.4 在centos6.4上的安装
- redis2.6.4 在centos6.4上的安装
- JavaScript权威指南 第一部分 读书笔记
- HDCP的key交互
- mysql相似于oracle的to_char() to_date()方法
- IOS7新特性之Xcode
- 喝牛奶最好一口一口慢慢喝
- Mongodb 在CentOS6.2上的安装
- 《高效学习OpenGL》 之 反馈 glFeedbackBuffer(), glPassThrough()
- rabbitmq安装使用 ,java环境
- php各种插件安装,持续更新
- u盘坏了如何恢复数据
- Linux中的常用命令
- c++ algorithm 的用法
- ACMer 进来看看吧
- 第二周习题(二)