RHEL6.7MongoDB 3.2.4mongoDBphp
MongoDBjsonbjsonMongo
RUBYPYTHONJAVAC++PHP
BSONJSON
MongoDBMongoDBMongoDBJSONcollection
join
schema
mongodb
I/O
mongodbreplica sets
replica setmongodb
mongodb
replica sets
[root@xuegod63 ~]# uname -a
Linux xuegod63.cn 2.6.32-573.el6.x86_64 #1 SMP Wed Jul 1 18:23:37 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@xuegod63 ~]# cat /etc/issue
Red Hat Enterprise Linux Server release 6.7 (Santiago)
Kernel r on an m
mongodb-linux-x86_64-rhel62-3.2.4.tgz
[root@xuegod63 ~]# curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.4.tgz
or
[root@xuegod63 ~]# wget -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.4.tgz #
[root@xuegod63 ~]# tar -zxvf mongodb-linux-x86_64-rhel62-3.2.4.tgz #
[root@xuegod63 ~]# mv mongodb-linux-x86_64-rhel62-3.2.4 /usr/local/mongodb #
MongoDBbinPATH
[root@xuegod63 ~]# vim .bash_profile
PATH=$PATH:/usr/local/mongodb/bin
[root@xuegod63 ~]# source .bash_profile
MongoDBdatadbdatadatadbdata(/)
/data/dbMongoDB(–dbpath)
[root@xuegod63 ~]# mkdir -p /usr/local/mongondb/{data,logs}
ulimit -nulimit -u20000ulimitMongoDBMongoDB
[root@xuegod63 ~]#ulimit -n 25000
[root@xuegod63 ~]#ulimit -u 25000
mongo
[root@xuegod63 ~]# useradd -r mongo
[root@xuegod63 ~]# chown -R mongo:mongo /usr/local/mongondb/data/
/usr/local/mongodb/bin/
[root@xuegod63 ~]# mongod
/usr/local/mongodb/conf
[root@xuegod63 ~]# mkdir -p /usr/local/mongodb/conf
[root@xuegod63 ~]# vim /usr/local/mongodb/conf/mongodb.conf
dbpath=/usr/local/mongodb/data //
logpath=/usr/local/mongodb/logs/mongodb.log //
bind_ip=127.0.0.1,192.168.1.63 //IP192.168.1.63
port=27017 //
fork=true //
master=true
verbose = true
vvvv = true
maxConns = 5000 // 2000
objcheck = true
logappend=true //
shardsvr=true
directoryperdb=true //
nohttpinterface=true
noauth=true //
rest=false
[root@xuegod63 ~]# mongod -f /usr/local/mongodb/conf/mongodb.conf
or
[root@xuegod63 ~]# mongod –config /usr/local/mongodb/conf/mongodb.conf
[root@xuegod63 ~]# ps -efl |grep mongod |grep -v grep
1 S root 14338 1 2 80 0 – 104363 poll_s 19:17 ? 00:00:03 mongod –config /usr/local/mongodb/conf/mongodb.conf
[root@xuegod63 ~]# netstat -tunlp |grep mongod
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 14338/mongod
/etc/init.d/mongod
#!/bin/bash
#chkconfig: 2345 80 90
#description: mongodb
start() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb.conf
}
stop() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb.conf –shutdown
}
case “$1” in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $”Usage: $0 {start|stop|restart}”
exit 1
esac
[root@xuegod63 ~]# chmod +x /etc/init.d/mongod
[root@xuegod63 ~]# chkconfig mongond –add
[root@xuegod63 ~]# chkconfig mongond on
[root@xuegod63 init.d]# service mongod restart
killing process with pid: 15302
about to fork child process, waiting until server is ready for connections.
forked process: 15430
child process started successfully, parent exiting
[root@xuegod63 init.d]# ps -efl |grep mongod |grep -v grep
1 S root 15525 1 2 80 0 – 80141 poll_s 19:47 ? 00:00:01 /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb.conf
[root@xuegod63 init.d]# netstat -tunlp |grep mongod
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 15724/mongod
/etc/rc.local
[root@xuegod63 ~]# echo “/usr/local/mongodb/bin/mongod –dbpath /usr/local/mongodb/data –logpath=/usr/local/mongodb/logs/mongodb.log–logappend–port 27017–fork” >> /etc/rc.local
[root@xuegod63 ~]# service mongod stop
killing process with pid: 16781
[root@xuegod63 ~]# ps -efl |grep mongod |grep -v grep
[root@xuegod63 ~]# /usr/local/mongodb/bin/mongod –dbpath /usr/local/mongodb/data –logpath=/usr/local/mongodb/logs/mongodb.log –logappend–port 27017–fork
about to fork child process, waiting until server is ready for connections.
forked process: 16897
child process started successfully, parent exiting
//
[root@xuegod63 ~]#/usr/local/mongodb/bin/mongod –dbpath /usr/local/mongodb/data –logpath=/usr/local/mongodb/logs/mongodb.log –logappend –port=27017–fork–auth
//,
[root@xuegod63 ~]# ps -efl |grep mongod |grep -v grep
1 S root 16897 1 2 80 0 – 98274 poll_s 20:26 ? 00:00:00 /usr/local/mongodb/bin/mongod –dbpath /usr/local/mongodb/data–logpath=/usr/local/mongodb/logs/mongodb.log –logappend–port 27017–fork
[root@xuegod63 ~]# netstat -tunlp |grep mongod
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 16897/mongod
[root@xuegod63 ~]#iptables-A INPUT -m state –state NEW -m tcp -p tcp –dport 27017 -j ACCEPT
[root@xuegod63 ~]#/etc/init.d/iptables save
[root@xuegod63 ~]#/etc/init.d/iptables restart
[root@xuegod63 ~]# mongo
MongoDB shell version: 3.2.4
connecting to: test
Server has startup warnings:
2016-03-30T05:09:28.032+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2016-03-30T05:09:28.032+0800 I CONTROL [initandlisten]
2016-03-30T05:09:28.032+0800 I CONTROL [initandlisten]
2016-03-30T05:09:28.032+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘always’.
2016-03-30T05:09:28.032+0800 I CONTROL [initandlisten] ** We suggest setting it to ‘never’
2016-03-30T05:09:28.032+0800 I CONTROL [initandlisten]
2016-03-30T05:09:28.032+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is ‘always’.
2016-03-30T05:09:28.032+0800 I CONTROL [initandlisten] ** We suggest setting it to ‘never’
2016-03-30T05:09:28.032+0800 I CONTROL [initandlisten]
>
#
> db
test
# mydb
> use mydb
switched to db mydb
> db
mydb
#javascript
> j = { name : “mongo” }
{ “name” : “mongo” }
> k = { x : 3 }
{ “x” : 3 }
#mydbtestdata collection
> db.testdata.insert(j)
WriteResult({ “nInserted” : 1 })
> db.testdata.insert(k);
WriteResult({ “nInserted” : 1 })
> show collections
system.indexes
testdata
> db.testdata.find()
{ “_id” : ObjectId(“54ddd717d692cfe0bd20d983”), “name” : “mongo” }
{ “_id” : ObjectId(“54ddd728d692cfe0bd20d984”), “x” : 3 }
> show dbs
admin (empty)
local 0.078GB
mydb 0.078GB
> use hahadb
switched to db hahadb
> show dbs
admin (empty)
local 0.078GB
mydb 0.078GB
> db
hahadb
> j = { name : “mongo” }
{ “name” : “mongo” }
> show dbs
admin (empty)
local 0.078GB
mydb 0.078GB
> db.testdata.insert(j)
WriteResult({ “nInserted” : 1 })
> show dbs
admin (empty)
hahadb 0.078GB
local 0.078GB
mydb 0.078GB
> use mydb
switched to db mydb
> show collections
system.indexes
testdata
> db.testdata.insert(j)
WriteResult({ “nInserted” : 1 })
> db.testdata.find()
{ “_id” : ObjectId(“54ddd717d692cfe0bd20d983”), “name” : “mongo” }
{ “_id” : ObjectId(“54ddd728d692cfe0bd20d984”), “x” : 3 }
{ “_id” : ObjectId(“54ddda64d692cfe0bd20d986”), “name” : “mongo” }
> db.testdata.insert(k)
WriteResult({ “nInserted” : 1 })
> db.testdata.find()
{ “_id” : ObjectId(“54ddd717d692cfe0bd20d983”), “name” : “mongo” }
{ “_id” : ObjectId(“54ddd728d692cfe0bd20d984”), “x” : 3 }
{ “_id” : ObjectId(“54ddda64d692cfe0bd20d986”), “name” : “mongo” }
{ “_id” : ObjectId(“54ddda7dd692cfe0bd20d987”), “x” : 3 }
> db.testdata.find({x:3})
{ “_id” : ObjectId(“54ddd728d692cfe0bd20d984”), “x” : 3 }
{ “_id” : ObjectId(“54ddda7dd692cfe0bd20d987”), “x” : 3 }
> exit;
[root@xuegod63 ~]#
docs.mongodb.org/manual/tutorial/install-mongodb-on-linux/
phpmyadmin
http://code.google.com/p/rock-php/wiki/rock_mongo_zh
config.phpadmin:admin
blog/backup
[root@xuegod63 ~]# /usr/local/mongodb/bin/mongodump -h 127.0.0.1 -d blog -o /backup/blog.dmp
[root@xuegod63 ~]#/usr/local/mongodb/bin/mongorestore -h 127.0.0.1 -d blog /backup/ddc.dmp
php mongo
php5.2.17/usr/local/php
13.1mongodb
http://pecl.php.net/package/mongo
[root@xuegod63 ~]#wget http://pecl.php.net/get/mongo-1.2.2.tgz
[root@xuegod63 ~]#tar -zxvf mongo-1.2.2.tgz
[root@xuegod63 ~]#cd mongo-1.2.2
13.2phpize
[root@xuegod63 ~]#/usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
13.3php mongo
[root@xuegod63 ~]#./configure –with-php-config=/usr/local/php/bin/php-config
–with-php-configphp-config,php-config
creating libtool
appending configuration tag “CXX” to libtool
configure: creating ./config.status
config.status: creating config.h
13.4
[root@xuegod63 ~]#make && make install
:
Build complete.
Don’t forget to run ‘make test’.
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
13.5php.ini
[root@免费云主机域名xuegod63 ~]# vim/usr/local/php/etc/php.ini
extension=mongo.so
phpini/usr/local/php/etc/php.ini
13.6
[root@xuegod63 ~]#cd /var/www/html
[root@xuegod63 ~]#vim index.php #
phpinfo();
?>
:wq! #
[root@xuegod63 ~]# service httpd restart
or
[root@xuegod63 ~]# service php-fpm restart
IPmongomongodb
http://localhost/index.php
RHEL6.7MongoDB 3.2.4mongoDBphp
实验环境介绍 源库:1 1.2.0.1 rac库 2个节点 目标库:11.2.0. 1 RHEL6.5 本文也可以理解成rac 环境下的如何数据库迁移到单实例的数据库环境下,默认目标库已经安装好了同源库一样的数据库版本。 另外注意,BLOG 中代码部分需要特别…
免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。