美文网首页个人学习
【MongoDB】1.0 centos7安装mongdb

【MongoDB】1.0 centos7安装mongdb

作者: bobokaka | 来源:发表于2020-05-17 17:26 被阅读0次
    1.0 下载

    https://www.mongodb.com/download-center/community

    image.png
    wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.5.tgz
    
    2.0 解压
     tar -zxvf mongodb-linux-x86_64-rhel70-4.4.5.tgz
    

    重命名。

    mv mongodb-linux-x86_64-rhel70-4.4.5 mongodb
    mv mongodb ../company_program/mongodb
    

    配置环境变量
    vim /etc/profile

    export JAVA_HOME=/data/company/company_program/java8
    export JRE_HOME=/data/company/company_program/java8/jre
    export NGINX_HOME=/usr/local/nginx/sbin
    export MYSQL_HOME=/data/company/company_program/mysql-5.7.34
    export MONGODB_HOME=/data/company/company_program/mongodb
    export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib:$NGINX_HOME:$MYSQL_HOME/lib
    export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$NGINX_HOME:$MYSQL_HOME/bin:$MONGODB_HOME/bin
    

    保存退出

    esc :wq 
    

    更新一下

    source /etc/profile
    

    创建两个文件夹 主要是存在数据跟日志


    image.png

    配置配置文件

    /data/company/company_program/mongodb/bin/mongodb.conf

    # mongodb 配置文件
    port=27017 #端口
    bind_ip=0.0.0.0 #默认是127.0.0.1
    dbpath=/data/company/company_program/mongodb/data #数据库存放
    logpath=/data/company/company_program/mongodb/log/mongodb.log #日志文件
    fork=true #设置后台运行
    #auth=true #开启认证
    

    启动

    mongod -f /data/company/company_program/mongodb/bin/mongodb.conf 
    
    image.png

    本机连接测试

    mongo
    
    image.png

    数据插入

    db.pigs.insert({'a':'b'})
    

    数据查找

    db.pigs.find()
    
    image.png

    到此mongodb配置成功。

    设置开机自启动

    创建用于启动mongodb的配置文件

    [root@localhost ~]# touch /usr/lib/systemd/system/mongodb.service
    [root@localhost ~]# cd /usr/lib/systemd/system
    

    vim mongodb.service

    [Unit]
    Description=mongodb Server
    After=network.target remote-fs.target nss-lookup.target 
    
    [Install]
    WantedBy=multi-user.target
    
    [Service]
    Type=forking 
    ExecStart=/data/company/company_program/mongodb/bin/mongod --config  /data/company/company_program/mongodb/bin/mongodb.conf
    ExecReload=/bin/kill -s HUP $MAINPID 
    ExecStop=/data/company/company_program/mongodb/bin/mongod --shutdown --config  /data/company/company_program/mongodb/bin/mongodb.conf
    PrivateTmp=true 
    
    修改mongodb.service所属用户组,保持和配置文件一致
    chown -R mysql:mysql mongodb.service
    
    启动服务
    systemctl start mongodb.service   
    
    关闭服务
    systemctl stop mongodb.service   
    
    开机启动
    systemctl enable mongodb.service  
    
    image.png
    重启
    reboot
    
    image.png

    查看mongodb是否自启动

    ps -ef|grep mongodb
    
    启动mongodb:
    mongo
    
    image.png image.png

    相关文章

      网友评论

        本文标题:【MongoDB】1.0 centos7安装mongdb

        本文链接:https://www.haomeiwen.com/subject/pcmsohtx.html