• mongodb安装到配置问题


    一、所有问题

    Xshell 连接不上

    报错类型:Could not connect to '192.168.122.1' (port 22): Connection failed.
    原因:IP地址未生成
    解决方法:重新生成ip地址 service network restart,在ifconfig -a 查看inet后虚拟机IP

    Xshell 上传文件到服务器 : rz

    Xshell从服务器下载文件 : rz 文件名

    解压文件 
    tar -zxvf filename.tar.gz #解压到当前目录,保留原文件
    tar -zxvf filename.tar.gz -C dir #解压到dir目录,保留原文件
    压缩 tar czvf kernel.tgz linux-2.6.29

    centos下创建删除等用户权限不够时执行

    su root
    chown -R hk:hk /dir
    (ll /usr 查看结果,增加的权限在/usr)

    由于以上操作导致/usr下root权限改为了用户组,报以下错误

    [hk@hk ~]$ sudo root passwd
    sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
    [hk@hk ~]$ su root
    Password: 
    su: Authentication failure

    解决方式:
    1、切换到root用户下将权限改回,chown root:root /usr/* -R
    2、root用户下执行
    chmod u+s /usr/bin/sudo
    chmod u+s /usr/bin/su

    vim命令
    删除所有内容gg dG

    端口号27017被占用报48错误

    Failed to set up listener: SocketException: Address already in use

    解决方式:

    lsof -i :27017 #pid
    kill - 9 pid

    二、安装及运行

    安装版本为MongoDB 4.0,官网下载

    cd /usr/local
    tar -zxvf  mongodb-linux-x86_64-4.0.0.tgz
    mkdir mongodb
    mv mongodb-linux-x86_64-4.0.0/*  mongodb
    rm -rf mongodb-linux-x86_64-4.0.0.tgz
    rm -rf mongodb-linux-x86_64-4.0.0
    
    cd mongodb
    mkdir db
    mkdir  logs
    touch logs/mongodb.log
    cd /usr/local/mongodb
    touch mongodb.conf

    修改启动文件:vim mongodb.conf

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

    添加mongodb的环境变量:vim /etc/profile

    export MONGODB_HOME=/usr/local/mongodb  
    export PATH=$PATH:$MONGODB_HOME/bin
    

      

    修改保存后要重启系统配置,执行命令 : source /etc/profile  

    运行启动数据库

    /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongodb.conf
    

    开机自启动

    vim /etc/rc.d/rc.local
    /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongodb.conf

    防火墙设置

    vim /etc/sysconfig/iptables
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT
    systemctl start iptables.service

     

    防火墙设置过程中报错:

    The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

    关闭firewalld:

    systemctl stop firewalld
    systemctl mask firewalld
    yum install iptables-services
    
    #开放443端口(HTTPS)
    iptables -A INPUT -p tcp --dport 443 -j ACCEPT
     
    #保存上述规则
    service iptables save
     
    #开启服务
    systemctl restart iptables.service
    
    systemctl enable iptables
    
    systemctl restart iptables
    
    service iptables save

    访问数据库:bin目录下运行mongo能正常运行还是会报警告信息

     错误分析:

    WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.We suggest setting it to 'never'

    WARNING: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted.

    WARNING: You are running this process as the root user, which is not recommended.

    1、/etc/rc.local文件设置(transparent_hugepage)的问题。

    vim /etc/rc.local

    if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
        echo never > /sys/kernel/mm/transparent_hugepage/enabled
    fi
    
    if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
        echo never > /sys/kernel/mm/transparent_hugepage/defrag
    fi

    修改后重启。

    2、将配置文件mongodb.conf auth 认证打开。

    3、不推荐使用root用户。

    修改后再次启动:

  • 相关阅读:
    E. You Are Given Some Strings...
    神奇函数
    AC自动机再加强版
    AC自动机2
    AC自动机
    three arrays
    permutation 2
    string matching
    permutation 1
    equation
  • 原文地址:https://www.cnblogs.com/hqczsh/p/12150634.html
Copyright © 2020-2023  润新知