Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install the php extension of MongoDB 3.2.4 and mongoDB under RHEL6.7

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

General binary package under RHEL6.7 how to install MongoDB 3.2.4 and mongoDB php extension, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

I. introduction of the software

MongoDB is a product between relational database and non-relational database, which is the most functional and most like relational database in non-relational database. The data structure he supports is very loose, which is similar to json's bjson format, so it can store more complex data types. The most important feature of Mongo is that the query language it supports is very powerful, and its syntax is somewhat similar to the object-oriented query language. It can almost achieve most of the functions similar to the single table query of relational database, and also supports the establishment of data indexing.

It is characterized by high performance, easy to deploy, easy to use, and it is very convenient to store data. The main functional features are:

For collection storage, it is easy to store data of object type.

Mode freedom.

Dynamic query is supported.

Full indexing is supported, including internal objects.

Query is supported.

Replication and failure recovery are supported.

Use efficient binary data storage, including large objects such as video, etc.

Automatically handle fragments to support scalability at the cloud computing level

Support for RUBY,PYTHON,JAVA,C++,PHP and other languages.

The file is stored in BSON (an extension of JSON)

Accessible through the network

MongoDB is an open source documentation database that provides common performance, high availability, automatic extension, etc. A record in MongoDB is a document, which is a pair structure of fields and values. MongoDB documents are similar to JSON objects, and the values of fields can contain other documents, arrays, and arrays of documents. Records are organized into collection, which is equivalent to tables. Refer to the following figure:

The advantages of using documents are:

Documents correspond to endogenous data objects of many programming languages

Embedded documents and arrays reduce the overhead of join

Dynamic schema supports smooth polymorphism

Key features:

High performance:

Mongodb provides high-performance data persistence. In particular:

Support for the embedded data model reduces the Icano of the database system.

Indexes support quick queries and embedded documents and arrays can contain keys

High availability:

What mongodb provides with high availability is replica sets

Automatic failed switching

Data redundancy

Replica set is a set of mongodb servers that maintain the same dataset, provide redundancy, and increase data availability.

Automatically scale horizontally:

Horizontal scaling is the kernel function of mongodb.

Automatically share distributed data on a cluster

Replica sets can provide ultimate consistent read for low-latency, high-throughput applications.

2. Installation environment:

[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 GNU/Linux

[root@xuegod63 ~] # cat / etc/issue

Red Hat Enterprise Linux Server release 6.7 (Santiago)

Kernel\ r on an\ m

Software: mongodb-linux-x86_64-rhel62-3.2.4.tgz

Download and install

[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 # download

[root@xuegod63] # tar-zxvf mongodb-linux-x86_64-rhel62-3.2.4.tgz # decompress

[root@xuegod63 ~] # mv mongodb-linux-x86_64-rhel62-3.2.4 / usr/local/mongodb # copy the unzipped package to the specified directory

IV. Configuration of environmental variables

The executable file for MongoDB is located in the bin directory, so you can add it to the PATH path:

[root@xuegod63 ~] # vim .bash _ profile

PATH=$PATH:/usr/local/mongodb/bin

[root@xuegod63 ~] # source .bash _ profile

Create a database storage directory

MongoDB's data is stored in the db directory of the data directory, but this directory is not created automatically during installation, so you need to manually create the data directory and create the db directory in the data directory. In the following example, we create the data directory under the root directory (/).

Note: / data/db is the default MongoDB startup database path (--dbpath).

[root@xuegod63 ~] # mkdir-p / usr/local/mongondb/ {data,logs}

Set the values of ulimit-n and ulimit-u to be greater than 20000. If the value of ulimit is set too low, an error will occur when the MongoDB is accessed frequently, resulting in the inability to connect to the MongoDB instance.

[root@xuegod63] # ulimit-n 25000

[root@xuegod63] # ulimit-u 25000

6. Create a user mongo

[root@xuegod63] # useradd-r mongo

[root@xuegod63] # chown-R mongo:mongo / usr/local/mongondb/data/

Add a configuration file and start it

① can use the command in the / usr/local/mongodb/bin/ directory:

[root@xuegod63 ~] # mongod

② creates a conf directory to add configuration files under / usr/local/mongodb/

[root@xuegod63] # mkdir-p / usr/local/mongodb/conf

[root@xuegod63 ~] # vim / usr/local/mongodb/conf/mongodb.conf

Dbpath=/usr/local/mongodb/data / / data file storage directory

Logpath=/usr/local/mongodb/logs/mongodb.log / / log file storage directory

Bind_ip=127.0.0.1192.168.1.63 / / can only be accessed through local area network IP:192.168.1.63 and local computer.

Port=27017 / / Port

Fork=true / / is enabled as a daemon, that is, running in the background

Master=true

Verbose = true

Vvvv = true

MaxConns = 5000 / / the maximum simultaneous connections defaults to 2000

Objcheck = true

Logappend=true / / write the log by appending

Shardsvr=true

Directoryperdb=true / / use one directory per database

Nohttpinterface=true

Noauth=true / / does not enable authentication

Rest=false

③ manually starts the service

[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 800-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

8. Set up boot boot

Method 1. Add a boot script

① adds the mongod script in the / etc/init.d/ directory as follows:

#! / 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

② add script execution permissions

[root@xuegod63 ~] # chmod + x / etc/init.d/mongod

③ setting boot up

[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 800-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

Method 2. Add the startup process to / 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

/ / Login method that does not require a password

[root@xuegod63] # / usr/local/mongodb/bin/mongod-dbpath / usr/local/mongodb/data-logpath=/usr/local/mongodb/logs/mongodb.log-logappend-port=27017-fork-auth

/ / Login method that requires permission. User name and password are required to connect.

[root@xuegod63 ~] # ps-efl | grep mongod | grep-v grep

S root 16897 12 800-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 15 * LISTEN 16897/mongod

Setting up a firewall to facilitate the access of other servers in the local area network

[root@xuegod63] # iptables-An 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

10. Connection testing

[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]

>

# View the current database

> db

Test

# cut to database mydb

> use mydb

Switched to db mydb

> db

Mydb

# create two documents with javascript

> j = {name: "mongo"}

{"name": "mongo"}

> k = {x: 3}

{"x": 3}

# create mydb database and testdata 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 db

Switched to db db

> 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 ({XRV 3})

{"_ id": ObjectId ("54ddd728d692cfe0bd20d984"), "x": 3}

{"_ id": ObjectId ("54ddda7dd692cfe0bd20d987"), "x": 3}

> exit

[root@xuegod63 ~] #

Reference:

Docs.mongodb.org/manual/tutorial/install-mongodb-on-linux/

Graphical management (similar to phpmyadmin)

Http://code.google.com/p/rock-php/wiki/rock_mongo_zh

Download, decompress and modify config.php to the corresponding address and port, and access it using admin:admin.

Backup and restore the existing database (database name blog is backed up to the / backup directory)

[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

13. Installation of php mongo extension:

Php version 5.2.17 compilation installation, installation path / usr/local/php

Download the mongodb extension source code

The source code is downloaded from http://pecl.php.net/package/mongo to

[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.2. Execute phpize to prepare the environment for compiling extensions

[root@xuegod63 ~] # / usr/local/php/bin/phpize

The execution result after running is as follows:

Configuring for:

PHP Api Version: 20041225

Zend Module Api No: 20060613

Zend Extension Api No: 220060519

13.3. Configure php mongo extension

[root@xuegod63] #. / configure-- with-php-config=/usr/local/php/bin/php-config

The parameter with-php-config tells the configuration script php-config the path to this program. The introduction of php-config is here.

The above command runs in a correctly configured environment with the following results:

Creating libtool

Appending configuration tag "CXX" to libtool

Configure: creating. / config.status

Config.status: creating config.h

13.4. Compile and install extensions

[root@xuegod63] # make & & make install

The result of correct compilation and execution is as follows:

Build complete.

Don't forget to run 'make test'.

Installing shared extensions: / usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/

13.5. Edit php.ini file

[root@xuegod63 ~] # vim / usr/local/php/etc/php.ini

Extension=mongo.so

Generally, the default ini file for compiling php is / usr/local/php/etc/php.ini.

13.6. Restart the service to verify the installation results

Test:

[root@xuegod63 ~] # cd / var/www/html

[root@xuegod63 ~] # vim index.php # Edit and enter the following

: wq! # Save exit

Restart the service:

[root@xuegod63 ~] # service httpd restart

Or

[root@xuegod63 ~] # service php-fpm restart

Enter the server IP address in the client browser, if you can see the configuration information related to mongo! Then the extension to mongodb is installed successfully.

Http://localhost/index.php

After reading the above, have you mastered how to install MongoDB 3.2.4 and mongoDB's php extension to the general binary package under RHEL6.7? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report