gentoo 安装mongodb

1,启动脚本

保存在 /etc/init.d/mongodb

  
  
  
  
  1. Helder RibeiroFreedom on all levels. 
  2. Installing MongoDB on Gentoo 
  3.  
  4. So I had some trouble running the good old “sudo emerge mongodb -va” due to some issues. After installing it by hand I found this little portage overlay that handles things better, but it has an outdated version of MongoDB, so I’ll show you how to get the latest and greatest. It’s all very basic, but since I’m no sysadmin, I still had to wrestle with things a bit to get it working, so I hope to relieve others of the same effort. 
  5.  
  6. Since the problem was with one of the dependencies (spidermonkey), you’ll need the static version, that is, the one that comes with all the dependencies compiled in. Below is the one I used, but make sure to find the latest tgz for your platform here (choose the “legacy-static”). 
  7.  
  8.  
  9. wget http://downloads.mongodb.org/linux/mongodb-linux-i686-static-1.4.2.tgz 
  10.  
  11. After that, basically all you have to do is follow the instructions on this guide. It’s in German, but you can get what you have to do from the commands it tells you to run (the automatic translation is also not so bad). 
  12.  
  13. The only thing you’re not supposed to do is copy the script in the section “Start-Stop Script”. It is meant for Debian distributions and won’t work on Gentoo because of some missing commands. So instead, copy the script below into /etc/init.d/mongodb, give it +x permission and follow the rest of the guide as usual. Let me know if you run into any troubles! 
  14.  
  15.  
  16. #! /bin/sh 
  17. # start / stop script for mongodb 
  18.  
  19. ### BEGIN INIT INFO 
  20. # Provides: mongod 
  21. # Required-Start: \$remote_fs \$syslog 
  22. # Required-Stop: \$remote_fs \$syslog 
  23. # Default-Start: 2 3 4 5 
  24. # Default-Stop: 0 1 6 
  25. # Short-Description: Start mongod at boot time 
  26. # Description: Enable service provided by mongod. 
  27. ### END INIT INFO 
  28.  
  29. # Source function library. 
  30. #. /lib/lsb/init-functions 
  31.  
  32. retval=0 
  33. pidfile=/var/run/mongodb.pid 
  34.  
  35. exec="/bin/mongod" 
  36. prog="mongod" 
  37. config="/etc/mongodb/mongodb.conf" 
  38. lockfile="/var/lock/mongod" 
  39.  
  40. [ -e $config ] && . $config 
  41.  
  42. start() { 
  43. if [ ! -x $exec ] 
  44. then 
  45. echo $exec not found 
  46. exit 5 
  47. fi 
  48.  
  49. echo "Starting mongoDB daemon" 
  50. echo $prog 
  51.  
  52. start-stop-daemon --start --pidfile $pidfile -m -c $MONGO_USER \ 
  53. --exec $exec -- $MONGO_OPTS run > /dev/null 2>&1 & 
  54. retval=$? 
  55.  
  56. if [ $retval -eq 0 ] 
  57. then 
  58. echo 0 
  59. else 
  60. echo 1 
  61. fi 
  62. return $retval 
  63.  
  64. stop() { 
  65. echo "Stopping mongoDB daemon" 
  66. echo $prog 
  67. start-stop-daemon --stop --pidfile $pidfile --retry 10 \ 
  68. --exec $exec 
  69.  
  70. retval=$? 
  71.  
  72. if [ $retval -eq 0 ] && rm -f $lockfile 
  73. then 
  74. echo 0 
  75. else 
  76. echo 1 
  77. fi 
  78. rm -f $pidfile 
  79. return $retval 
  80.  
  81. restart() { 
  82. stop 
  83. start 
  84.  
  85. reload() { 
  86. restart 
  87.  
  88. # See how we were called. 
  89. case "$1" in 
  90. start) 
  91. $1 
  92. ;; 
  93. stop) 
  94. $1 
  95. ;; 
  96. restart) 
  97. $1 
  98. ;; 
  99. reload) 
  100. $1 
  101. ;; 
  102. *) 
  103. echo "Usage: $0 {start|stop|restart|reload}" 
  104. exit 2 
  105. esac 
  106.  
  107. exit $? 

2,下载自己需要的版本,我这用的是mongodb-linux-x86_64-0.9.2.tgz

 

  
  
  
  
  1. # cd /tmp/                                                                
  2. # wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-0.9.2.tgz 
  3. # tar -xzf mongodb-linux-x86_64-0.9.2.tgz 

3,创建mongodb目录,和数据库目录。

 

  
  
  
  
  1. # mv mongodb-linux-x86_64-0.9.2 /opt/mongodb 
  2. # mkdir -p /data/mongodb

4,增加mongodb用户

 

  
  
  
  
  1. # useradd mongod -s /bin/false 
  2. # chown -R mongod:mongod /data/mongodb 

5,编写配置文件

 

  
  
  
  
  1. # mkdir /etc/mongodb 
  2. # cat << EOF > /etc/mongodb/mongodb.conf 
  3. MONGO_USER="mongod" 
  4. MONGO_OPTS="--dbpath /data/mongodb/" 
  5. EOF 

 

你可能感兴趣的:(mongodb,安装,职场,休闲)