设为首页 收藏本站
查看: 731|回复: 0

[经验分享] MongoDB-linux-2.4.10-X86_64(centos/linux下安装,启动服务脚本)

[复制链接]

尚未签到

发表于 2018-10-27 08:24:37 | 显示全部楼层 |阅读模式
  1,下载
  从http://www.mongodb.org/downloads获取下载版本mongodb-linux-x86_64-2.4.10.tgz
  2,添加用户
  groupadd mongod
  useradd -s /sbin/nologin -M -g mongod mongod
  3,解压并移动到相应位置
  [root@localhost ~]# tar -zxvf mongodb-linux-x86_64-2.4.10.tgz
  [root@localhost ~]# cd mongodb-linux-x86_64-2.4.10
  [root@localhost mongodb-linux-x86_64-2.4.10]# ls
  bin  GNU-AGPL-3.0  README  THIRD-PARTY-NOTICES
  [root@localhost mongodb-linux-x86_64-2.4.10]# cd bin/
  [root@localhost bin]# ls
  bsondump  mongo  mongod  mongodump  mongoexport  mongofiles  mongoimport  mongooplog  mongoperf  mongorestore  mongos  mongosniff  mongostat  mongotop
  [root@localhost ~]# mv mongodb-linux-x86_64-2.4.10 /mongodb
  如有必要可设置其目录权限
  chmod 755 /mongodb-linux-x86_64-2.4.10/ -R
  如有必要可建立系统目录命令软链接
  ln -s /mongodb/bin/mongo /usr/bin/mongo
  ln -s /mongodb/bin/mongod /usr/bin/mongod
  3,手工建立运行目录并授权
  mkdir -p date
  mkdir -p logs
  mkdir -p conf
  mkdir -p run
  chmod u+w data -R
  chmod u+w logs -R
  chmod u+w run -R
  chown -R mongod:mongod date logs run
  4,建立配置文件
  vim etc/mongod.conf
  [root@localhost conf]# cat mongod.conf
  # Start MongoDB as a daemon on port 8908
  port = 8908
  fork = true # daemonize it !
  journal = true #
  rest = true
  logappend = true
  auth = true
  dbpath = /mongodb/data/
  logpath = /mongodb/logs/mongod.log
  pidfilepath = /mongodb/run/mongod.pid
  =======================================
  注:如果更多的启动参数,请在你的mongodb主目录bin目录下使用如下命令查看启动参数:
  [root@localhost bin]# pwd
  /mongodb/bin
  [root@localhost bin]# ./mongod --help
  Allowed options:
  General options:
  -h [ --help ]               show this usage information
  --version                   show version information
  -f [ --config ] arg         configuration file specifying additional options
  -v [ --verbose ]            be more verbose (include multiple times for more
  verbosity e.g. -vvvvv)
  --quiet                     quieter output
  --port arg                  specify port number - 27017 by default
  --bind_ip arg               comma separated list of ip addresses to listen on
  - all local ips by default
  --maxConns arg              max number of simultaneous connections - 20000 by
  default
  --logpath arg               log file to send write to instead of stdout - has
  to be a file, not directory
  --logappend                 append to logpath instead of over-writing
  --pidfilepath arg           full path to pidfile (if not set, no pidfile is
  created)
  --keyFile arg               private key for cluster authentication
  --setParameter arg          Set a configurable parameter
  --nounixsocket              disable listening on unix sockets
  --unixSocketPrefix arg      alternative directory for UNIX domain sockets
  (defaults to /tmp)
  --fork                      fork server process
  --syslog                    log to system's syslog facility instead of file
  or stdout
  --auth                      run with security
  --cpu                       periodically show cpu and iowait utilization
  --dbpath arg                directory for datafiles - defaults to /data/db/
  --diaglog arg               0=off 1=W 2=R 3=both 7=W+some reads
  --directoryperdb            each database will be stored in a separate
  directory
  --ipv6                      enable IPv6 support (disabled by default)
  --journal                   enable journaling
  --journalCommitInterval arg how often to group/batch commit (ms)
  --journalOptions arg        journal diagnostic options
  --jsonp                     allow JSONP access via http (has security
  implications)
  --noauth                    run without security
  --nohttpinterface           disable http interface
  --nojournal                 disable journaling (journaling is on by default
  for 64 bit)
  --noprealloc                disable data file preallocation - will often hurt
  performance
  --noscripting               disable scripting engine
  --notablescan               do not allow table scans

  --nssize arg (=16)          .ns file>  --profile arg               0=off 1=slow, 2=all
  --quota                     limits each database to a certain number of files
  (8 default)
  --quotaFiles arg            number of files allowed per db, requires --quota
  --repair                    run repair on all dbs
  --repairpath arg            root directory for repair files - defaults to
  dbpath
  --rest                      turn on simple rest api
  --shutdown                  kill a running server (for init scripts)
  --slowms arg (=100)         value of slow for profile and console log

  --smallfiles                use a smaller default file>  --syncdelay arg (=60)       seconds between disk syncs (0=never, but not
  recommended)
  --sysinfo                   print some diagnostic system information
  --upgrade                   upgrade db if needed
  Replication options:

  --oplogSize arg      >  5% of disk space (i.e. large is good)
  Master/slave options (old; use replica sets instead):
  --master              master mode
  --slave               slave mode
  --source arg          when slave: specify master as
  --only arg            when slave: specify a single database to replicate
  --slavedelay arg      specify delay (in seconds) to be used when applying
  master ops to slave
  --autoresync          automatically resync if slave data is stale
  Replica set options:
  --replSet arg           arg is [/]
  --replIndexPrefetch arg specify index prefetching behavior (if secondary)
  [none|_id_only|all]
  Sharding options:
  --configsvr           declare this is a config db of a cluster; default port
  27019; default dir /data/configdb
  --shardsvr            declare this is a shard db of a cluster; default port
  27018
  5,建立启动服务文件
  [root@localhost conf]# cat /etc/init.d/mongod
  #!/bin/bash
  # mongod - Startup script for mongod
  # chkconfig: 35 85 15
  # description: Mongo is a scalable, document-oriented database.
  # processname: mongod
  # config: /etc/mongod.conf
  # pidfile: /var/run/mongo/mongod.pid
  . /etc/rc.d/init.d/functions
  # things from mongod.conf get there by mongod reading it
  # NOTE: if you change any OPTIONS here, you get what you pay for:
  # this script assumes all options are in the config file.
  BASEDIR="/mongodb"
  CONFIGFILE="$BASEDIR/conf/mongod.conf"
  OPTIONS=" -f $CONFIGFILE"
  SYSCONFIG="/etc/sysconfig/mongod"
  # FIXME: 1.9.x has a --shutdown flag that parses the config file and
  # shuts down the correct running pid, but that's unavailable in 1.8
  # for now.  This can go away when this script stops supporting 1.8.
  DBPATH=`awk -F= '/^dbpath=/{print $2}' "$CONFIGFILE"`
  PIDFILE=`awk -F= '/^dbpath\s=\s/{print $2}' "$CONFIGFILE"`
  mongod=${MONGOD-$BASEDIR/bin/mongod}
  MONGO_USER=mongod
  MONGO_GROUP=mongod
  if [ -f "$SYSCONFIG" ]; then
  . "$SYSCONFIG"
  fi
  # Handle NUMA access to CPUs (SERVER-3574)
  # This verifies the existence of numactl as well as testing that the command works
  NUMACTL_ARGS="--interleave=all"
  if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null
  then
  NUMACTL="numactl $NUMACTL_ARGS"
  else
  NUMACTL=""
  fi
  start()
  {
  echo -n $"Starting mongod: "
  daemon --user "$MONGO_USER" $NUMACTL $mongod $OPTIONS
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod
  }
  stop()
  {
  echo -n $"Stopping mongod: "
  killproc -p "$PIDFILE" -d 300 /usr/bin/mongod
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod
  }
  restart () {
  stop
  start
  }
  ulimit -n 12000
  RETVAL=0
  case "$1" in
  start)
  start
  ;;
  stop)
  stop
  ;;
  restart|reload|force-reload)
  restart
  ;;
  condrestart)
  [ -f /var/lock/subsys/mongod ] && restart || :
  ;;
  status)
  status $mongod
  RETVAL=$?
  ;;
  *)
  echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
  RETVAL=1
  esac
  exit $RETVAL
  6,启动服务
  [root@localhost logs]# service mongod restart
  Stopping mongod:                                           [失败]
  Starting mongod: about to fork child process, waiting until server is ready for connections.
  forked process: 1605
  all output going to: /mongodb/logs/mongod.log
  child process started successfully, parent exiting
  [确定]
  [root@localhost logs]# ps -ef | grep mongod
  root      1407  1346  0 17:08 pts/1    00:00:00 vim /etc/init.d/mongod
  mongod    1564     1  1 17:13 ?        00:00:00 /mongodb/bin/mongod -f /mongodb/conf/mongod.conf
  root      1577  1410  0 17:14 pts/2    00:00:00 grep mongod
  [root@localhost logs]# lsof -i:8908
  -bash: lsof: command not found
  [root@localhost logs]# netstat -anpt
  Active Internet connections (servers and established)
  Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
  tcp        0      0 0.0.0.0:8908                0.0.0.0:*                   LISTEN      1564/mongod
  tcp        0      0 0.0.0.0:9908                0.0.0.0:*                   LISTEN      1564/mongod
  7,shell进入服务命令行查看
  系统默认使用270117端口号,故登录不成功
  [root@localhost bin]# ./mongo 
  MongoDB shell version: 2.4.10
  connecting to: test
  Wed May 21 17:28:09.809 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
  exception: connect failed
  由于改变了端口号,故使用时需要指定端口号
  [root@localhost bin]# ./mongo -port 8908  
  MongoDB shell version: 2.4.10
  connecting to: 127.0.0.1:8908/test
  Welcome to the MongoDB shell.
  For interactive help, type "help".
  For more comprehensive documentation, see
  http://docs.mongodb.org/
  Questions? Try the support group
  http://groups.google.com/group/mongodb-user
  >
  查看data目录,自动生成如下文件
  [root@localhost mongodb]# cd data/
  [root@localhost data]# ll
  总用量 507936
  -rw------- 1 mongod mongod  67108864 5月  21 17:37 admin.0
  -rw------- 1 mongod mongod 134217728 5月  21 17:37 admin.1
  -rw------- 1 mongod mongod  16777216 5月  21 17:37 admin.ns
  drwxr-xr-x 2 mongod mongod      4096 5月  21 18:01 journal
  -rw------- 1 mongod mongod  67108864 5月  21 18:01 local.0
  -rw------- 1 mongod mongod  16777216 5月  21 18:01 local.ns
  -rwxr-xr-x 1 mongod mongod         5 5月  21 18:01 mongod.lock
  -rw------- 1 mongod mongod  67108864 5月  21 18:02 test.0
  -rw------- 1 mongod mongod 134217728 5月  21 18:00 test.1
  -rw------- 1 mongod mongod  16777216 5月  21 18:02 test.ns
  OK,以上情况视为安装成功,服务正常运行
  8,基本用户管理--命令区分大小写
  http://blog.51yip.com/nosql/1575.html 请参考该博文
  9,更多shell操作管理命令
  请查看http://quanzhong.iteye.com/blog/916237 博文


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-626961-1-1.html 上篇帖子: PHP操作MongoDB简明教程 下篇帖子: MongoDB JAVA-API执行mapreduce的几种方法
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表