当前位置:Gxlcms > 数据库问题 > CentOS-6.4-minimal版中安装MongoDB-x86_64-3.0.2

CentOS-6.4-minimal版中安装MongoDB-x86_64-3.0.2

时间:2021-07-01 10:21:17 帮助过:24人阅读

  1. /**
  2. * CentOS-6.4-minimal版中安装MongoDB-x86_64-3.0.2
  3. * @see --------------------------------------------------------------------------------------------------------
  4. * @see 安装MongoDB
  5. * @see [Jadyer@CentOS64 ~]$ cd /app/software/
  6. * @see [Jadyer@CentOS64 software]$ tar zxvf mongodb-linux-x86_64-3.0.2.tgz
  7. * @see [Jadyer@CentOS64 software]$ mv mongodb-linux-x86_64-3.0.2 /app/mongodb-3.0.2
  8. * @see [root@CentOS64 ~]# vi /etc/profile
  9. * @see #Set MongoDB Environment Variable
  10. * @see MONGODB_HOME=/app/mongodb-3.0.2
  11. * @see PATH=$PATH:$MONGODB_HOME/bin
  12. * @see export MONGODB_HOME PATH
  13. * @see [root@CentOS64 ~]# source /etc/profile
  14. * @see [root@CentOS64 ~]# mongod -version
  15. * @see [Jadyer@CentOS64 ~]$ mongod -version
  16. * @see --------------------------------------------------------------------------------------------------------
  17. * @see 配置MongoDB
  18. * @see [Jadyer@CentOS64 ~]$ cd /app/mongodb-3.0.2/
  19. * @see [Jadyer@CentOS64 mongodb-3.0.2]$ mkdir data #创建MongoDB存放数据文件的目录
  20. * @see [Jadyer@CentOS64 mongodb-3.0.2]$ mkdir logs #创建MongoDB存放日志文件的目录
  21. * @see [Jadyer@CentOS64 mongodb-3.0.2]$ touch logs/mongodb.log #创建一个空的日志文件
  22. * @see [Jadyer@CentOS64 mongodb-3.0.2]$ cd bin
  23. * @see [Jadyer@CentOS64 bin]$ vi startup.sh
  24. * @see mongod --dbpath /app/mongodb-3.0.2/data --logpath /app/mongodb-3.0.2/logs/mongodb.log --logappend --fork --rest --httpinterface
  25. * @see [Jadyer@CentOS64 bin]$ chmod 755 startup.sh
  26. * @see [Jadyer@CentOS64 bin]$ vi shutdown.sh
  27. * @see mongod --dbpath /app/mongodb-3.0.2/data --shutdown
  28. * @see [Jadyer@CentOS64 bin]$ chmod 755 shutdown.sh
  29. * @see [Jadyer@CentOS64 bin]$ vi client.sh
  30. * @see mongo 127.0.0.1:27017/admin
  31. * @see [Jadyer@CentOS64 bin]$ chmod 755 client.sh
  32. * @see --------------------------------------------------------------------------------------------------------
  33. * @create 2015-6-3 下午8:05:59
  34. * @author 玄玉<http://blog.csdn.net/jadyer>
  35. */
  1. /**
  2. * @see --------------------------------------------------------------------------------------------------------
  3. * 启动MongoDB
  4. * @see 启动时,执行上面编写的startup.sh就可以了
  5. * @see 但启动之前,有4点需要注意
  6. * @see 1.用root启动时会有警告提示,可以为mongo单独创建一个用户来启动,以下简称"mongo用户"
  7. * @see 2.mongo用户的[ulimit -n]和[ulimit -u]要相同,否则也会有警告提示
  8. * @see 3.先要用root用户执行下面两个命令,否则启动后,客户端连接时会有警告提示
  9. * @see [root@CentOS64 Jadyer]# echo "never" > /sys/kernel/mm/transparent_hugepage/enabled
  10. * @see [root@CentOS64 Jadyer]# echo "never" > /sys/kernel/mm/transparent_hugepage/defrag
  11. * @see 4.使用wiredTiger引擎时,需要加上directoryperdb参数,让数据库分文件夹,不然小文件太多了
  12. * @see 比如:numactl --interleave=all /usr/local/mongodb/bin/mongod --fork --httpinterface --noauth --bind_ip=0.0.0.0 --port=27017 --storageEngine=wiredTiger --directoryperdb --dbpath=/data/mongodata/data/db1 --logpath=/data/mongodata/logs/mongodb.log --logappend
  13. * @see --------------------------------------------------------------------------------------------------------
  14. * @see 管理MongoDB
  15. * @see [Jadyer@CentOS64 ~]$ cd /app/mongodb-3.0.2/bin/
  16. * @see [Jadyer@CentOS64 bin]$ ./startup.sh
  17. * @see [Jadyer@CentOS64 bin]$ ./client.sh
  18. * @see MongoDB shell version: 3.0.2
  19. * @see connecting to: 127.0.0.1:27017/admin
  20. * @see > show dbs
  21. * @see local 0.078GB #此时是看不见admin的,但mongodb3.0中有一个能管理用户的userAdminAnyDatabase
  22. * @see > db.createUser({user:"xuanyu",pwd:"222222",roles:[{role:"userAdminAnyDatabase",db:"admin"}]})
  23. * @see > show users #查看刚才创建的用户
  24. * @see > db.system.users.find() #该命令也能查看创建的用户,而且信息更详细
  25. * @see > db.shutdownServer() #关闭数据库(也可用上面编写的shutdown.sh)
  26. * @see [Jadyer@CentOS64 bin]$ vi startup.sh #加入[--auth]参数
  27. * @see [Jadyer@CentOS64 bin]$ ./startup.sh
  28. * @see [Jadyer@CentOS64 bin]$ ./client.sh
  29. * @see MongoDB shell version: 3.0.2
  30. * @see connecting to: 127.0.0.1:27017/admin
  31. * @see > show dbs #此时会报告not authorized on admin to execute command { listDatabases: 1.0 }
  32. * @see > db.auth("xuanyu", "222222") #返回1表示认证通过
  33. * @see 1
  34. * @see > show dbs
  35. * @see admin 0.078GB
  36. * @see local 0.078GB
  37. * @see > show collections #这时也会报错not authorized on admin...(因为"xuanyu"用户只有用户管理的权限)
  38. * @see > cls #清屏
  39. * @see > use jishu
  40. * @see switched to db jishu
  41. * @see > db.createUser({user:"xuanyudev", pwd:"222222", roles:[{role:"readWrite",db:"jishu"},{role:"read",db:"jishu22"}]})
  42. * @see > show users #查看刚才创建的用户
  43. * @see > use admin
  44. * @see switched to db admin
  45. * @see > db.system.users.find() #查看数据库中的所有用户
  46. * @see > use jishu
  47. * @see switched to db jishu
  48. * @see > show collections #这时还会报告not authorized on admin...(因为没权限,先赋权)
  49. * @see > db.auth("xuanyudev", "222222")
  50. * @see 1
  51. * @see > show collections #如此便可以了
  52. * @see --------------------------------------------------------------------------------------------------------
  53. * @see 一些文章
  54. * @see MongoDB的真正性能-实战百万用户一-一亿的道具
  55. * @see http://www.cnblogs.com/crazylights/archive/2013/05/08/3068098.html
  56. * @see MONGODB中OBJECTID的误区,以及引起的一系列问题
  57. * @see http://www.cnphp6.com/archives/64392
  58. * @see --------------------------------------------------------------------------------------------------------
  59. * @create 2015-6-3 下午8:11:34
  60. * @author 玄玉<http://blog.csdn.net/jadyer>
  61. */

CentOS-6.4-minimal版中安装MongoDB-x86_64-3.0.2

标签:linux   centos   nosql   mongodb   安装   

人气教程排行