Heat up your hands for the next job.
Read a book before, understand, but it seems that three or four years, and forget. :(
Reference URL:
Http://www.centoscn.com/image-text/install/2014/1124/4171.html
Environment:
System hardware: VMware vsphere (cpu:2*4 core, memory 2G)
System version: centos-6.5-x86_64
CentOS Compilation installs MongoDB 2.6 system preferably 64-bit, in order to better play MongoDB performance
Installation steps:
0. System Environment
[Email protected] ~]# cat/etc/redhat-release
CentOS Release 6.5 (Final)
[Email protected] ~]# uname-a
Linux CentOS 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 03:15:09 UTC x86_64 x86_64 x86_64 gnu/linux
[email protected] ~]# Yum install vim wget-y
1. Download the source file (binary compiled version)
[Email protected] ~]# mkdir-p/DATA/SRC
[Email protected] ~]# CD/DATA/SRC
[Email protected] ~]# wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.1.tgz
[Email protected] ~]# TAR-ZVXF mongodb-linux-x86_64-2.6.1.tgz
[Email protected] ~]# MV mongodb-linux-x86_64-2.6.1/opt/mongodb/
2. Configure the PATH environment variable to ensure that the MongoDB Bin directory is contained in the PATH environment variable.
2.1 Configuring Path
[Email protected] ~]# Vim/etc/profile
Add the following content:
#set for MongoDB
Export Mongodb_home=/opt/mongodb
Export path= $MONGODB _home/bin: $PATH
Save exit
2.1 View Current Path
[Email protected] ~]# echo $PATH
2.2 Let the environment variable take effect:
[Email protected] ~]# Source/etc/profile
[Email protected] ~]# echo $PATH
3. Verify that the environment variable is in effect
[Email protected] ~]# mongod-version
4. Create a directory for storing data and logs:
4.1 Creating a Directory
[Email protected] ~]# mkdir-p/data/mongodb/journal
[Email protected] ~]# mkdir-p/data/mongodb/log
4.2 Creating a log file
[Email protected] ~]# Touch/data/mongodb/log/mongodb.log
4.3 Setting up the configuration file
[Email protected] ~]# vim/etc/mongodb.conf
Enter the following to save and rewind
Dbpath=/data/mongodb
Logpath=/data/mongodb/log/mongodb.log
Logappend=true
port=27017
Fork=true
Noauth=true
Nojournal = True
Smallfiles = True
Noprealloc = True
5. Add MongoDB users and set permissions
5.1 Adding users
[Email protected] ~]# useradd mongodb-m-s/sbin/nologin
5.2 Setting Directory Permissions
[[Email protected] ~] #chown-R Mongodb.mongodb/data/mongodb
6. Restart, start the service
6.1 Restart
[Email protected] ~]# Shutdown-r now
6.2 After restarting, run the Mongod service
[Email protected] ~]# mongod-f/etc/mongodb.conf
7. Test whether the service is normal
7.1 Open another terminal and enter the admin background as an administrator
[[Email protected] ~] #mongo Admin
>show DBS;
>db.test.find ();
>exit
8. Add the Mongod service to the boot start service
8.1 Writing Service files
[Email protected] ~]# Vim/etc/init.d/mongod
Enter the following and save the exit (see code later)
8.2 Set to start the service
[Email protected] ~]# chkconfig--add Mongod
[Email protected] ~]# chkconfig--level 345 mongod on
[Email protected] ~]# chmod +x/etc/init.d/mongod
8.3 Testing
[[Email protected] ~] #service mongod Start
[[Email protected] ~] #service mongod Status
9. Reboot, and test
[[Email protected] ~] #shutdown-R now
[[Email protected] ~] #service mongod Status
[[Email protected] ~] #mongo Admin
>show DBS;
>db.test.find ();
>exit
**********************************************
MongoDB's parameter description:
--dbpath database path (data file)
--logpath log file path
--master designated as the main machine
--slave specified as Slave machine
--source Specify the IP address of the host machine
--POLOGSIZE specifies that the log file size does not exceed 64M. Because Resync is very large and time-consuming,
It is best to avoid resync by setting a large enough oplogsize (the default oplog size is 5% of the free disk size).
--logappend log file End add
--port Enable port numbers
--fork running in the background
--ONLY specifies which database to replicate only
--slavedelay refers to the time interval from which replication is detected
--auth If you need to verify permissions login (username and password)
#!/bin/SH# # MongoDB Initfile forstarting up the MongoDB server## chkconfig:- - the# Description:starts and stops the Mongdb daemon that handles all # database requests.# SourcefunctionLibrary:/etc/rc.d/init.d/functionsexec="/opt/mongodb/bin/mongod"Prog="Mongod"logfile="/data/mongodb/log/mongodb.log"Options="-f/etc/mongodb.conf"[ -e/etc/sysconfig/$prog] &&. /etc/sysconfig/$progLockfile="/var/lock/subsys/mongod"start () {[-X $exec] | | Exit5 Echo-N $"starting $prog:"Daemon--user MongoDB"$exec--quiet $options run >> $logfile 2>&1 &"retval=$?Echo[$retval-eq0] &&Touch$Lockfilereturn $retval}stop () {Echo-N $"stopping $prog:"Killproc $prog retval=$?Echo[$retval-eq0] &&RM-F $Lockfilereturn $retval}restart () {Stop start}reload () {restart}force_reload () {restart}rh_status () {# R UN checks to determineifThe service is running or use generic status status $prog}rh_status_q () {rh_status>/dev/NULL 2>&1} Case " $" inchstart) Rh_status_q&& exit0 $1 ;; Stop) Rh_status_q|| Exit0 $1 ;; Restart) $1 ;; Reload) Rh_status_q|| Exit7 $1 ;; Force-reload) force_reload;; status) Rh_status;; Condrestart|try-restart) rh_status_q|| Exit0restart;; *) Echo$"Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"Exit2EsacExit $?
Installing MongoDB on the CENTOS6