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

CentOS compilation and installation of MongoDB

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

I. Environment

System CentOS6.4x64 minimized installation

IP 192.168.3.33

II. Installation

[root@mongodb-2 ~] # curl-O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.5.tgz[root@mongodb-2 ~] # tar xf mongodb-linux-x86_64-3.0.5.tgz [root@mongodb-2 ~] # ln-s / usr/local/mongodb-linux-x86_64-3.0.5 / / usr/local/mongodb

Set environment variabl

[root@mongodb-2 ~] # tail-3 / etc/profile#set for mongodbexport MONGODB_HOME=/usr/local/mongodbexport PATH=$MONGODB_HOME/bin:$PATH# reload environment variable [root@mongodb-2 ~] # source / etc/ profile [root @ mongodb-2 ~] # echo $PATH/usr/local/mongodb/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin# verification result [root @ mongodb-2 ~] # mongod-- versiondb version v3.0.5git version: 8bc4ae20708dbb493cb09338d9e7be6698e4a3a3

Create a catalog

[root@mongodb-2 ~] # mkdir-p / usr/local/mongodb/ data [root @ mongodb-2 ~] # mkdir-p / usr/local/mongodb/ log [root @ mongodb-2 ~] # mkdir-p / usr/local/mongodb/conf

Establish a configuration file

[root@mongodb-2 ~] # cat / usr/local/mongodb/conf/mongodb.conf#bind_ip=0.0.0.0port=27017dbpath=/usr/local/mongodb/datalogpath=/usr/local/mongodb/log/mongodb.logpidfilepath=/usr/local/mongodb/log/mongodb.piddirectoryperdb=truelogappend=trueoplogSize=1000fork=true#noprealloc=truemaster=true

Add mongodb users and set permissions

[root@mongodb-2 ~] # useradd mongodb- M-s / sbin/nologin [root@mongodb-2 ~] # chown-R mongodb.mongodb / usr/local/mongodb-linux-x86_64-3.0.5

Start the service

[root@mongodb-2 ~] # mongod-f / usr/local/mongodb/conf/mongodb.conf about to fork child process, waiting until server is ready for connections.forked process: 1545child process started successfully, parent exiting# Test [root@mongodb-2 ~] # mongo admin

Write server startup script

[root@mongodb-2 ~] # cat / etc/init.d/mongod #! / bin/sh## mongodb init file for starting up the MongoDB server## chkconfig:-208 description: Starts and stops the MongDB daemon that handles all\ # database requests.# Source function library.. / etc/rc.d/init.d/functionsexec= "/ usr/local/mongodb/bin/mongod" prog= "mongod" logfile= "/ usr/local/mongodb/log/mongodb.log" options= "- f / usr/local/mongodb/conf/mongodb.conf" [- e / etc/sysconfig/$prog] &. / etc/sysconfig/$proglockfile= "/ var/lock/subsys/mongod" start () {[- x $exec] | | exit 5 echo-n $"Starting $prog:" daemon-- user mongodb "$exec-- quiet $options run > > $logfile 2 > & 1 &" retval=$? Echo [$retval-eq 0] & & touch $lockfile return $retval} stop () {echo-n $"Stopping $prog:" killproc $prog retval=$? Echo [$retval-eq 0] & & rm-f $lockfile return $retval} restart () {stop start} reload () {restart} force_reload () {restart} rh_status () {# run checks to determine if the service is running or use generic status status $prog} rh_status_q () {rh_status > / dev/null 2 > & 1} case "$1" in start) if test-f / sys/kernel/mm/transparent_hugepage/defrag Then echo never > / sys/kernel/mm/transparent_hugepage/defrag fi if test-f / sys/kernel/mm/transparent_hugepage/enabled; then echo never > / sys/kernel/mm/transparent_hugepage/enabled fi rh_status_q & & exit 0 $1;; stop) rh_status_q | | exit 0 $1;; restart) $1 Reload) rh_status_q | | exit 7 $1;; force-reload) force_reload;; status) rh_status;; condrestart | try-restart) rh_status_q | | exit 0 restart *) echo $"Usage: $0 {start | stop | status | restart | condrestart | try-restart | reload | force-reload}" exit 2esacexit $? # Grant script execution permission [root@mongodb-2 ~] # chmod + x / etc/init.d/mongod# restart service [root@mongodb-2 ~] # / etc/init.d/mongod restartStopping mongod: [OK] Starting mongod: [OK] [root@mongodb-2 ~] # netstat-tunlp | grep mongtcp 00 0.0.0.0 netstat 27017 0.0.0.0 grep mongtcp * LISTEN 1759/mongod # added to boot self-boot [root@mongodb-2 ~] # chkconfig-- add Mongod [root @ mongodb-2 ~] # chkconfig mongod on

Parameter description for mongodb profile

Parameter description of mongodb:-- dbpath database path (data file)-- logpath log file path-- master specifies the master machine-- slave specifies the IP address of the master machine-- source specifies the IP address of the master machine-- pologSize specifies that the log file size does not exceed 64m. Because resync is very heavy 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). -- add at the end of the logappend log file-- port enable port number-- fork runs in the background-- only specifies which database is replicated only-- slavedelay refers to the time interval detected from replication-- whether auth requires authentication permission login (username and password)

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

Wechat

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

12
Report