CentOS6.8 installation mongodb3.0 and backup script
I. system environment
CentOS 6.8_x64
Official reference document https://docs.mongodb.org/manual/reference/glossary/#term-init-script
2. Add the official yum library
# cd / etc/yum.repo.d/
# vim mongodb.repo
[mongodb-org-3.0] name=MongoDB Repositorybaseurl= https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/gpgcheck=0enabled=1
III. Installation and configuration
1. Install and create a data directory
# yum install-y mongodb-org#mkdir-p / Data/mongodb # chown mongod.mongod / Data/mongodb-R
2. Configure mongod.conf
# vim / etc/mongod.conf
# mongod.conf# for documentation of all options See:# http://docs.mongodb.org/manual/reference/configuration-options/# where to write logging data.systemLog: destination: file logAppend: true path: / Data/mongodb/mongod.log # Custom # Where and how to store data.storage: dbPath: / Data/mongodb/db # Custom journal: enabled: true# engine:# mmapv1:# wiredTiger:# how the process runsprocessManagement: fork: true# Fork and run in background pidFilePath: / var/run/mongodb/mongod.pid # location of pidfile# network interfacesnet: port: 27017 bindIp: 10.1.0.7 # Listen to local interface only Comment to listen on all interfaces. Need to customize # security:#operationProfiling:#replication:#sharding:# Enterprise-Only Options#auditLog:
Start mongod
# service mongod start
IV. Testing
Log in to mongodb
# mongo-- host 10.1.0.7
> db.version ()
3.0.7
> show dbs
Com_ylt_plat_passport 0.078GB
Local 0.078GB
Chown mongod.mongod / Data/mongodb-R
Service mongod start
Fifth, troubleshooting
Fault description:
When service mongod stop, it is found that the mongod service process has not been closed.
Through troubleshooting, it is found that the problem lies in line 24 of / etc/mongod.conf.
PidFilePath: / var/run/mongodb/mongod.pid # location of pidfile
Just delete the following # location of pidfile. This is a small bug.
VI. Mogond backup and restore script
# cat mongodb_bak.sh
#! / bin/shDUMP=/usr/bin/mongodumpOUT_DIR=/data1/backup/mongodb/mongod_bak_nowBAK_DIR=/data1/backup/mongodb/mongod_bak_listDATE= `date +% cd% H% M% d` # DB_USER=username#DB_PASS=DAYS=7TAR_BAK= "mongodb_bak_$DATE.tar.gz" [- d $OUT_DIR] | | mkdir-v $OUT_DIR [- d $BAK_DIR] | | mkdir-v $BAK_DIRBAK_DB () {cd $date-rf $OUT_DIR/*mkdir-p $DATE#$DUMP-u $DB_USER-p $DB_PASS-o $OUT_DIR/$DATE$DUMP-o $OUT_DIR/$DATEtar czvf $BAK_DIR/$TAR_BAK $OUT_DIR/$DATEfind $BAK_DIR/-mtime + $DAYS-delete} RESTORE_ALL () {cd $OUT_DIRfor d in `ls` Doecho $OUT_DIR/$d/usr/bin/mongorestore-d $OUT_DIR/$ddone} RESTORE_Choose () {while truedo echo "when you choose 'quit | exit' exit to restore!" Read-p "What's your choose? (Enter continue!)" Choose if [[$choose = = 'quit' | | $choose = =' exit']] then echo "You choose exit!" & & exit 2 fi cd $OUT_DIR d = `ls`cd $OUT_DIR/$d ls read-p "What's db your choose?" Whatdb if ["$whatdb"! =']; then / usr/bin/mongorestore-d $whatdb else echo "choose is empty,exit~" & & exit 0 fidone} case $1 in back) BAK_DB;; resall) RESTORE_ALL;; resone) RESTORE_Choose;; *) echo "USGE:back | resall | resone";; esac
Instructions for use:
Back backs up all mongod databases
Resall restores all databases
Resone can specify a database to be restored
7. Resolve warning tips
1. Problem description
Solve the problem of logging in mongo-- host 10.1.0.7-- port 27017 is similar to the following prompt
* * WARNING: / sys/kernel/mm/transparent_hugepage/enabled is' always'. And * * WARNING: / sys/kernel/mm/transparent_hugepage/defrag is' always'.
MongoDB shell version: 3.0.7
Connecting to: 10.1.0.7:27017/test
Server has startup warnings:
2016-12-08T16:10:15.638+0800 I CONTROL [initandlisten]
2016-12-08T16:10:15.638+0800 I CONTROL [initandlisten] * * WARNING: / sys/kernel/mm/transparent_hugepage/enabled is' always'.
2016-12-08T16:10:15.638+0800 I CONTROL [initandlisten] * * We suggest setting it to 'never'
2016-12-08T16:10:15.638+0800 I CONTROL [initandlisten]
2016-12-08T16:10:15.638+0800 I CONTROL [initandlisten] * * WARNING: / sys/kernel/mm/transparent_hugepage/defrag is' always'.
2016-12-08T16:10:15.638+0800 I CONTROL [initandlisten] * * We suggest setting it to 'never'
2016-12-08T16:10:15.638+0800 I CONTROL [initandlisten]
Since the environment is CentOS6.8, the solution is as follows. For other platforms and versions, please refer to the official document: https://docs.mongodb.org/manual/tutorial/transparent-huge-pages/
2. Solution:
Add the following script
# vim / etc/init.d/disable-transparent-hugepages
#! / bin/sh### BEGIN INIT INFO# Provides: disable-transparent-hugepages# Required-Start: $local_fs# Required-Stop:# X-Start-Before: mongod mongodb-mms-automation-agent# Default-Start: 2 3 4 "Default-Stop: 0 1" Short-Description: Disable Linux transparent hugepages# Description: Disable Linux transparent hugepages To improve# database performance.### END INIT INFOcase $1 in start) if [- d / sys/kernel/mm/transparent_hugepage] Then thp_path=/sys/kernel/mm/transparent_hugepage elif [- d / sys/kernel/mm/redhat_transparent_hugepage]; then thp_path=/sys/kernel/mm/redhat_transparent_hugepage else return 0 fi echo 'never' > ${thp_path} / enabled echo' never' > ${thp_path} / defrag unset thp_path;; esac
Add to Boot Service
# chmod + x / etc/init.d/disable-transparent-hugepages#chkconfig-- add disable-transparent-hugepages
3. Modify system parameters
# mkdir-p / etc/tune-profiles/no-thp#cd / etc/tune-profiles/no-thp#echo "set_transparent_hugepages never" > ktune.sh#chmod + x ktune.sh#tuned-adm profile no-thp execute yum install tuned- y if prompted that the command cannot be found
Reboot system
4. Verify:
$mongo-host 10.1.0.7-port 27017
MongoDB shell version: 3.0.7
Connecting to: 10.1.0.7:27017/test
>
5. The following error occurred:
* * WARNING: soft rlimits too low. Rlimits set to 1024 processes, 64000 files. Number of processes should be at least 32000: 0.5 times number of files.
# vim / etc/security/limits.conf
Add:
Mongod soft nofile 64000
Mongod hard nofile 64000
Mongod soft nproc 32000
Mongod hard nproc 32000
Restart mongod
To this mongod installation completed ~ if there is anything wrong, welcome to correct!