MongoDB configuration under Windows and Linux __linux

Source: Internet
Author: User
Tags auth create mongodb mkdir mongodb latest version mongodb version phpinfo syslog phpmyadmin


One, Windows environment



1, download Mogodb






MongoDB's official website is: http://www.mongodb.org/



MongoDB Latest version Download in the official website of the download menu: http://www.mongodb.org/downloads
The official website sometimes does not open, downloads after decompression puts the bin in the D:\APMServ5.2.6\Mongo directory



2. Create a folder



Create the Data folder in D:\APMServ5.2.6\Mongo, create the Conf folder, and then create the DB folder and log folder in the Data folder



Create mongodb.conf in conf, code as follows





# Start MongoDB as a daemon on port 8908

port = 27017
Journal = True
rest = True
auth = False
Logappen D = true
DBPath = d:/apmserv5.2.6/mongo/data/db
logpath =  D:/apmserv5.2.6/mongo/data/log/mongod.log

The database is placed in the Data/da directory and the log is placed in the Data/log directory





3, execute the command, install the MONGODB database



Go to the command line and enter the CD D:\APMServ5.2.6\Mongo\bin (D: In the Windows environment, of course)



Mongod-dbpath "d:/apmserv5.2.6/mongo/data/db"



Execute this command the MongoDB database file is created to the d:/apmserv5.2.6/mongo/data/db directory, and you will not be surprised to see a successful prompt for the last line of command sucess



At this point the database has been started, the interface for the MONGO startup program, after the shutdown can be directly double-click bin Mongod.exe (Note is D, this is the start of the program)



After the startup program is turned on, run the Mongo.exe program (note that there is no d)



4. Install the MOGODB into service



Command Line Input



D:\APMServ5.2.6\Mongo\bin\mongod--config d:/apmserv5.2.6/mongo/conf/mongodb.conf--servicename MongoDB--install



Successful words can be in the Computer Management, service inside see MongoDB Service, then you can net start MongoDB to open the service.



In addition, you can enter the registry regedit search MongoDB to see the system boot service, can also http://localhost:28017 to see MongoDB status, with http://localhost:27017 will prompt failure, Because there is validation



In fact, I suggest that the configuration file Auth=false first



When installed, the command line enters the bin directory, and then



Show DBS



Use admin



Db.adduser (' admin ', ' 123456 ');



This time you Db.auth (' admin ', ' 123456 ') before the show DBS is not successful.
5, so that PHP can access MongoDB






Https://github.com/mongodb/mongo-php-driver/downloads



Select the appropriate DLL version at the address above



Copy the above file to the D:\APMServ5.2.6\PHP\ext directory, to see the PHP version to choose, do not 5.2 into 5.3, PHP version can be seen in the phpinfo inside



Modify PHP.ini, add Extension=php_mongo-1.3.1-5.2-vc9.dll



Why choose the 1.3 version, you will find that if the 1.2.10 version thinkphp will be the error, 1.3 The following version is not mongoclient this class



if (!class_exists (' mongoclient ')) {



Hrow_exception (L (' _not_suppert_ '). ': Mongoclient ');



}






Here's what you can phpinfo to test.






6, Simple Moogodb operation



Use admin
Db.adduser (' admin ', ' 123456 ')
Show users is equivalent to Db.system.users.find ()
MONGO test//Set up a test table
Db.adduser (' Test ', ' 123456 ')
Db.removeuser ("Test")
Db.createcollection ("Collname", {size:20, Capped:5, max:100});



For MongoDB, the system has a user table, each database has a user table, but seemingly alone in the user table set up users can not directly access MongoDB, must go to the admin library inside Auth can



Second, Linux installation configuration



The MOGODB is installed in the/usr/local/src/mongodb/directory, the database is in/data/mongodb/db, and the log file is inside/data/mongodb/logs



cd/usr/local/src/
wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.8.tgz
Tar zxvf mongodb-linux-x86_64-2.4.8.tgz
Ln-s mongodb-linux-x86_64-2.4.8 MongoDB
Mkdir-p/data/mongodb/db
Mkdir-p/data/mongodb/logs
Cd/usr/local/src/mongodb/bin
./mongod--dbpath=/data/mongodb/db--logpath=/data/mongodb/logs/mongodb.log--logappend



Note that this time will prompt all output going to Mongodb.log, this time do not control+c terminated, reopen a command line



cd/usr/local/src/mongodb/



./mongo



Use admin



Db.adduser ("admin", "123456")



So you can quit.






Other online is let this operation actually I was not tested successfully
echo "/home/mongodb/bin/mongod--dbpath=/mongodb_data/db--port=27017--logpath=/mongodb_data/logs/mongodb.log-- Logappend--auth ">>/etc/rc.local



Above is to set the boot up step, I did not test successfully, I was using the following code to test successfully, MongoDB did not start the script, need to write their own



The startup script for the MongoDB configuration file is as follows:





#!/bin/sh
#
# mongod	This shell script takes care of starting and stopping
#	 the MySQL subsystem (mongod).
#
# chkconfig: - 64 36
# description:	MySQL database server.
# processname: mongod
# config: /etc/mongodb.conf
# pidfile: /var/mongodb/logs/mongod.pid
### BEGIN INIT INFO
# Provides: mongod
# Required-Start: $local_fs $remote_fs $network $named $syslog $time
# Required-Stop: $local_fs $remote_fs $network $named $syslog $time
# Short-Description: start and stop MySQL server
# Description: MySQL database server
### END INIT INFO

exec="/usr/local/src/mongodb/bin/mongod"
prog="mongod"

mongodpidfile="/data/mongodb/mongod.pid"

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/$prog


start(){
    [ -x $exec ] || exit 5
    $exec --config /usr/local/mongodb/bin/mongodb.conf
return 1;
}

stop(){
    kill $(ps -ef | grep -v "grep" | grep "$prog" | awk '{print $2}') 
    return 1;
}
 
restart(){
    stop
    start
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart}"
    exit 2
esac

exit $?
This file is saved as a Mogo





Then Cp/home/mogo/etc/init.d/mongod



chmod +x/etc/init.d/mongod






Chkconfig--add Mongod



Chkconfig Mongod on



Service Mongod Start



Pay attention to mongodb.conf.





# mongo.conf
# Where to log
dbpath=/data/mongodb/db
logpath=/data/mongodb/logs/mongodb.log
Logappend=true
# Fork and run in background
fork = true
port = 27017
Auth = True
Use this on the line, save in





"PS" Download time to pay attention to MongoDB version of the problem, do not download 32-bit system to 64-bit, otherwise it can not be implemented




sh/home/yanyun/meizitu/deploy/deploy_restart.sh




Additional: Windows Server Backup to Linux server
Back up the database (here is backup from windows)
CD F:\mongodb-win32-x86_64-2008plus-2.4.1\bin
Mongodump-h localhost-d meizitu-u admin-p xiaobaobei-o d:\meiziback

Restore the database (Restore to Linux, compress files in advance and download to Linux and unzip to the Meizitu directory)
Mongorestore-d Meizitu--drop/mongodb_data/db/meizitu

Add Access User (default MongoDB is no username password is accessible directly)
Cd/home/mongodb/bin
./mongo
Show DBS
Use admin
Show collections
Db.adduser (' root ', ' pwd ')
#show Collections (Error, prompt not authorized for query on admin)
#然后输入
Db.auth (' root ', ' pwd ')
Show collections









As follows I have not yet detected:


MongoDB PHP driver installation, use Phpize compiler mongodb Drive extension will MongoDB drive decompression, use unzip command
Unzip mongodb-mongo-php-driver-(xxx:version). zip [root@localhost ~]# unzip Mongodb-mongo-php-driver-1.3.0beta2-134-g606c757.zip [root@localhost ~]# CD mongodb-mongo-php-driver-606c757 [ Root@localhost ~]#/usr/local/php/bin/phpize [root@localhost ~]#./configure--with-php-config=/usr/local/php/bin/ Php-config--enable-mongo
[Root@localhost ~]# made && make install [root@localhost ~]# mkdir/usr/local/php/ext//php under the new ext directory to store PHP extensions [Root@localhost ~]# cp/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/mongo.so/usr/local/php/ext/
Modify PHP.ini, open mongo.so, and add a line to php.ini [root@localhost ~]# Vim/usr/local/apache/conf/php.ini
extension=/usr/local/php/ext/mongo.so [root@localhost ~]# service httpd restart

The Rockmongo configuration (similar to the phpMyAdmin MongoDB management tool) will rockmongo uncompressed and move to/usr/local/apache/htdocs/to modify the database connection configuration, which is very similar to phpMyAdmin [Root@localhost ~]# vim/usr/local/apache/htdocs/rockmongo/config.php       $MONGO [" Servers "[$i] [" mongo_name "] =" Localhost ";                  //server name, can customize     $MONGO ["Servers"][$ i]["mongo_host"] = "127.0.0.1";                  /server IP address     $MONGO ["Servers"] [$i] [" Mongo_port "] =" 27017 ";                          //MONGODB Port     $ mongo["Servers" [$i] ["mongo_auth"] = false;                              //MONGODB required username secret Code verification      $MONGO ["Servers"] [$i] ["mongo_user"] = "mongo_username";    //MONGODB database username      $MONGO ["Servers"] [$i["mongo_pass"] = "Mongo_password";    //MONGODB Database password      $MONGO ["Servers"] [$i] ["control_auth"] = true;                                //Control Panel required Verify (must open true)     $MONGO ["Servers"] [$i] ["Control_users"] ["admin"] = "admin";            //Control Panel login username and password (previous username, last password)
Rockmongo login address, username and password is the user name and password of the console http://192.168.0.21/rockmongo/




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.