• Linux安装MongoDB超详细


    Linux端安装

    我们从MonDB官网下载Linux端的安装包,建议下载4.0版本

    打开虚拟机,在虚拟机上安装传输工具lrzsz,将下载好的.tgz包拖到虚拟机当中,拖到/usr/local/mongoDB目录下,  

    1. [root@server ~]# yum install -y lrzsz
    2. [root@server ~]# cd /usr/local/
    3. [root@server local]# mkdir mongoDB
    4. [root@server local]# cd mongoDB/
    5. [root@server mongoDB]# rz -E
    6. rz waiting to receive.
    7. [root@server mongoDB]# ll
    8. total 102556
    9. -rw-r--r--. 1 root root 105017141 Apr 24 14:35 mongodb-linux-x86_64-rhel80-4.0.28.tgz

     

    使用tar命令进行解压缩  

    1. [root@server mongoDB]# tar -xvf mongodb-linux-x86_64-rhel80-4.0.28.tgz
    2. mongodb-linux-x86_64-rhel80-4.0.28/THIRD-PARTY-NOTICES.gotools
    3. mongodb-linux-x86_64-rhel80-4.0.28/README
    4. mongodb-linux-x86_64-rhel80-4.0.28/THIRD-PARTY-NOTICES
    5. mongodb-linux-x86_64-rhel80-4.0.28/MPL-2
    6. mongodb-linux-x86_64-rhel80-4.0.28/LICENSE-Community.txt
    7. mongodb-linux-x86_64-rhel80-4.0.28/bin/mongodump
    8. mongodb-linux-x86_64-rhel80-4.0.28/bin/mongorestore
    9. mongodb-linux-x86_64-rhel80-4.0.28/bin/mongoexport
    10. mongodb-linux-x86_64-rhel80-4.0.28/bin/mongoimport
    11. mongodb-linux-x86_64-rhel80-4.0.28/bin/mongostat
    12. mongodb-linux-x86_64-rhel80-4.0.28/bin/mongotop
    13. mongodb-linux-x86_64-rhel80-4.0.28/bin/bsondump
    14. mongodb-linux-x86_64-rhel80-4.0.28/bin/mongofiles
    15. mongodb-linux-x86_64-rhel80-4.0.28/bin/mongoreplay
    16. mongodb-linux-x86_64-rhel80-4.0.28/bin/mongod
    17. mongodb-linux-x86_64-rhel80-4.0.28/bin/mongos
    18. mongodb-linux-x86_64-rhel80-4.0.28/bin/mongo
    19. mongodb-linux-x86_64-rhel80-4.0.28/bin/install_compass
    20. [root@server mongoDB]# ll
    21. total 102556
    22. drwxr-xr-x. 3 root root 135 Apr 24 14:43 mongodb-linux-x86_64-rhel80-4.0.28
    23. -rw-r--r--. 1 root root 105017141 Apr 24 14:35 mongodb-linux-x86_64-rhel80-4.0.28.tgz

     将mongodb-linux-x86_64-rhel80-4.0.28传入到mondodbserver下

    1. [root@server mongoDB]# mv mongodb-linux-x86_64-rhel80-4.0.28 mongodbserver
    2. [root@server mongoDB]# ll
    3. total 102556
    4. -rw-r--r--. 1 root root 105017141 Apr 24 14:35 mongodb-linux-x86_64-rhel80-4.0.28.tgz
    5. drwxr-xr-x. 3 root root 135 Apr 24 14:43 mongodbserver
    6. [root@server mongoDB]# cd mongodbserver/

     创建使用数据库时数据的存放路径和日志

    1. root@server mongodbserver]# mkdir data
    2. [root@server mongodbserver]# mkdir log
    3. [root@server mongodbserver]# mkdir etc
    4. [root@server mongodbserver]# mkdir conf

    进入到/etc目录下,编辑mongodb.conf配置文件

    1. [root@server mongodbserver]# cd etc
    2. [root@server etc]# vim mongodb.conf
    3. dbpath=/usr/local/mongoDB/mongodbserver/data
    4. logpath=/usr/local/mongoDB/mongodbserver/log/mongodb.log
    5. bind_ip=0.0.0.0
    6. port=27017
    7. fork=true
    8. journal=false
    9. storageEngine=mmapv1

     执行mongo命令时出现报错

    1. [root@server bin]# ./mongod --config /usr/local/mongoDB/mongodbserver/etc/mongodb.conf
    2. ./mongod: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory

     解决方案

    1. [root@server bin]# yum install -y libcrypto.so.*
    2. #出现以下信息就说明安装成功了
    3. [root@server bin]# mongo
    4. MongoDB shell version v4.0.28
    5. connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
    6. 2024-04-24T15:13:01.329+0800 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
    7. connect@src/mongo/shell/mongo.js:356:17
    8. @(connect):2:6
    9. exception: connect failed

    启动MonDB

    1. [root@server bin]# cat /sys/kernel/mm/transparent_hugepage/defrag
    2. always defer defer+madvise [madvise] never
    3. [root@server bin]# cat /sys/kernel/mm/transparent_hugepage/enabled
    4. [always] madvise never

    将以下脚本添加到/etc/rc.local

    1. [root@server etc]# vim /etc/rc.local
    2. if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
    3. echo never > /sys/kernel/mm/transparent_hugepage/enabled
    4. fi
    5. if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
    6. echo never > /sys/kernel/mm/transparent_hugepage/defrag
    7. fi

     创建mongo普通用户,给mongod用户赋权

    1. [root@server bin]# useradd mongod
    2. [root@server bin]# passwd mongod
    3. Changing password for user mongod.
    4. New password:
    5. BAD PASSWORD: The password is shorter than 8 characters
    6. Retype new password:
    7. passwd: all authentication tokens updated successfully.
    8. [root@server mongodbserver]# chown -R mongod:mongod /usr/local/mongoDB/mongodbserver

     添加环境变量/etc/profile

    export PATH=/usr/local/mongoDB/mongodbserver/bin:$PATH

     进入普通用户mongod,输入mongo启动完成

    1. [mongod@server ~]$ mongod --dbpath=/usr/local/mongoDB/mongodbserver/data --logpath=/usr/local/mongoDB/mongodbserver/log/mongodb.log --port=27017 --logappend --fork
    2. [mongod@server ~]$ mongo
    3. MongoDB shell version v4.0.28
    4. connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
    5. Implicit session: session { "id" : UUID("64c64085-4ccc-4b3c-bce2-7579afb56920") }
    6. MongoDB server version: 4.0.28
    7. Welcome to the MongoDB shell.
    8. For interactive help, type "help".
    9. For more comprehensive documentation, see
    10. http://docs.mongodb.org/
    11. Questions? Try the support group
    12. http://groups.google.com/group/mongodb-user
    13. Server has startup warnings:
    14. 2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten]
    15. 2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
    16. 2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
    17. 2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten]
    18. 2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
    19. 2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
    20. 2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip
      to specify which IP
    21. 2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
    22. 2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
    23. 2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
    24. 2024-04-24T15:28:36.501+0800 I CONTROL [initandlisten]
    25. 2024-04-24T15:28:36.502+0800 I CONTROL [initandlisten]
    26. 2024-04-24T15:28:36.502+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
    27. 2024-04-24T15:28:36.502+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
    28. 2024-04-24T15:28:36.502+0800 I CONTROL [initandlisten]
    29. ---
    30. Enable MongoDB's free cloud-based monitoring service, which will then receive and display
    31. metrics about your deployment (disk utilization, CPU, operation statistics, etc).
    32. The monitoring data will be available on a MongoDB website with a unique URL accessible to you
    33. and anyone you share the URL with. MongoDB may use this information to make product
    34. improvements and to suggest MongoDB products and deployment options to you.
    35. To enable free monitoring, run the following command: db.enableFreeMonitoring()
    36. To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
    37. ---
    38. > > show databases;
    39. admin 0.000GB
    40. config 0.000GB
    41. local 0.000GB

  • 相关阅读:
    【flink-sql实战】flink 主键声明与upsert功能实战
    Java如何实现消费数据隔离?
    双基证券:游戏版号发放整体趋势的向好将持续优化供给端
    springcloud搭建 初级人员的使用搭建。sentinel使用官网有详细的使用方法
    在Plesk中如何开启https
    基于Echarts实现可视化数据大屏物流云大数据看板页面HTML模板
    netty面试题及答案
    初学UE5 C++②
    “ObservationAndApproach“ app Tech Support(URL
    什么是生成器 — 一篇文章让你看懂
  • 原文地址:https://blog.csdn.net/m0_66011019/article/details/138161969