• Linux-Centos7.7安装部署MongoDB3.4


    MongoDB:
        简介:
            MongoDB是一款跨平台、面向文档的数据库。
        优点:
            1.可以实现高可用、高性能,并且能够轻松扩展
            2.支持丰富的查询表达式
            3.支持各种编程语言
        适用领域:
            可以为web应用提供可扩展的高性能数据存储解决方案,主要的适用领域有:网站数据、分布式场景、数据缓存和JSON文档格式存储,适合大数据量、高并发、弱事务的互联网应用
        安装MongoDB:
            MongoDB官方下载路径:https://www.mongodb.com/try/download/community
            本次安装的MongoDB版本为3.4.20
            1.安装支持软件和MongoDB
                [root@localhost ~]# yum install openssl-devel
                [root@localhost ~]# tar xf mongodb-linux-x86_64-rhel70-3.4.24.tgz
                [root@localhost ~]# mv mongodb-linux-x86_64-rhel70-3.4.24 /usr/local/mongodb
            2.创建MongoDB的数据存储目录/data/mongodb1,日志存储目录为/data/logs
                [root@localhost ~]# mkdir -p /data/mongodb1
                [root@localhost ~]# mkdir -p /data/logs/mongodb
                [root@localhost ~]# touch /data/logs/mongodb/mongodb1.log
                [root@localhost ~]# chmod 777 -R /data/logs/mongodb/mongodb1.log
            3.当MongoDB处于频繁访问的状态,如果shell启动进程所占用的资源设置过低,将会产生错误导致无法连接MongoDB实例,需要设置ulimit -n和ulimit -u的值大于20000
                [root@localhost ~]# ulimit -n 25000
                [root@localhost ~]# ulimit -u 25000
        MongoDB的运行控制:
            1.创建MongoDB的配置文件和启动参数
                [root@localhost ~]# cd /usr/local/mongodb/bin/
                [root@localhost bin]# vim mongodb1.conf         # 添加以下内容
                    port=27017                         # 默认服务器端口号
                    dbpath=/data/mongodb1               # 数据存储目录
                    logpath=/data/logs/mongodb/mongodb1.log         # 日志文件
                    logappend=true              # 使用追加方式写日志
                    fork=true               # 后台运行
                    maxConns=5000               # 最大同时连接数,默认为2000
                    storageEngine=mmapv1           # 指定存储为内存映射文件
            2.设置内核参数
                当某个节点可用内存不足时,系统会从其他节点分配内存
                [root@localhost bin]# echo 0 > /proc/sys/vm/zone_reclaim_mode
                [root@localhost bin]# sysctl -w vm.zone_reclaim_mode=0              # 永久配置
                    vm.zone_reclaim_mode = 0
                [root@localhost bin]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
                [root@localhost bin]# echo never > /sys/kernel/mm/transparent_hugepage/defrag
        启动和停止MongoDB:
            1.启动MongoDB
                [root@localhost ~]# /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongodb1.conf
                about to fork child process, waiting until server is ready for connections.
                forked process: 5576
                child process started successfully, parent exiting
                或
                [root@localhost ~]# /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb1.conf
                about to fork child process, waiting until server is ready for connections.
                forked process: 5658
                child process started successfully, parent exiting
                注:
                    简言之就是将-f选项替换为--config
                验证:
                [root@localhost ~]# netstat -anpt | grep mongod
                tcp         0        0 0.0.0.0:27017        0.0.0.0:*       LISTEN      5576/mongod
            2.停止MongoDB
                [root@localhost ~]# /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb1.conf --shutdown
                killing process with pid: 5576
                或
                [root@localhost ~]# ps aux | grep mongodb
                root       5658  0.4  3.6 1255016 67400 ?       Sl   10:56   0:00 /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb1.conf
                root       5692  0.0  0.0 112648   956 pts/1    S+   10:59   0:00 grep --color=auto mongodb
                [root@localhost ~]# kill -2 5658
            3.配置开机自动启动
                [root@localhost ~]# vim /etc/rc.local       # 在文件末尾添加以下两行内容
                    rm -rf /data/mongodb/mongod.lock
                    /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb1.conf
            4.连接并访问MongoDB
                启动MongoDB后就可以通过MongoDB的客户端工具连接数据库了
                    [root@localhost ~]# /usr/local/mongodb/bin/mongo
                    > use admin
                    switched to db admin
        启动MongoDB多实例:
            [root@localhost ~]# cd /usr/local/mongodb/bin/
            [root@localhost bin]# cp mongodb1.conf mongodb2.conf
            [root@localhost bin]# vim !$
            vim mongodb2.conf       # 添加以下内容
            port=27018
            dbpath=/data/mongodb2
            logpath=/data/logs/mongodb/mongodb2.log
            logappend=true
            fork=true
            maxConns=5000
            storageEngine=mmapv1
            [root@localhost bin]# mkdir /data/mongodb2
            [root@localhost bin]# touch /data/logs/mongodb/mongodb2.log
            [root@localhost bin]# chmod -R 777 !$
            chmod -R 777 /data/logs/mongodb/mongodb2.log
            [root@localhost bin]# ./mongod -f ./mongodb2.conf
            about to fork child process, waiting until server is ready for connections.
            forked process: 5971
            child process started successfully, parent exiting
            [root@localhost bin]#

  • 相关阅读:
    Python之正则表达式模块
    Python之装饰器复习
    Django请求生命周期之响应内容
    网络编程
    Django实现验证码
    JSONP跨域请求
    原生Ajax(XMLHttpRequest)
    JavaScript函数与面向对象
    JavaScript作用域
    Django之Model操作
  • 原文地址:https://www.cnblogs.com/Vampire-MIn/p/13269736.html
Copyright © 2020-2023  润新知