您的位置:首页 > 数据库 > Mongodb

安装mongoDB与配置系统服务

2020-08-11 18:00 1056 查看
官网下载安装介质:https://www.mongodb.com/download-center,选择适当的版本,这 里以 linux 版本 mongodb-linux-x86_64-4.0.4 为例;   https://www.mongodb.org/dl/linux/x86_64   tar zxvf mongodb-linux-x86_64-4.0.4.tgz   mv mongodb-linux-x86_64-4.0.4 mongodb   mkdir -p mongodb/{data/db,log,conf}   vi mongodb/conf/mgdb.conf     https://docs.mongodb.com/v2.4/reference/configuration-options/   dbpath=/soft/mongodb/data/db #数据文件存放目录 logpath=/soft/mongodb/log/mongodb.log #日志文件存放目录 port=27017 #端口,默认 27017,可以自定义 logappend=true #开启日志追加添加日志 fork=true #以守护程序的方式启用,即在后台运行 bind_ip=0.0.0.0 #本地监听 IP,0.0.0.0 表示本地所有 IP auth=false #是否需要验证权限登录(用户名和密码)

 

修改环境变量 vi /etc/profile export MONGODB_HOME=/soft/mongodb (解压的目录) export PATH=$PATH:$MONGODB_HOME/bin source /etc/profile       配置开机启动,如下 vi /usr/lib/systemd/system/mongodb.service


[Unit] 
Description=mongodb 
After=network.target remote-fs.target nss-lookup.target 

[Service] 
Type=forking 
RuntimeDirectory=mongodb
PIDFile=/usr/local/soft/mongodb/data/db/mongod.lock 
ExecStart=/usr/local/soft/mongodb/bin/mongod --config /usr/local/soft/mongodb/conf/mgdb.conf

ExecStop=/usr/local/soft/mongodb/bin/mongod --shutdown --config /usr/local/soft/mongodb/conf/mgdb.conf 
PrivateTmp=true 

[Install]
WantedBy=multi-user.target

 

注意: /usr/local/soft/mongodb/ 改成自己的解压路径

systemctl daemon-reload systemctl start mongodb systemctl enable mongodb  

 

启动 mongodb service mongodb stop service mongodb start   注:设置了,就可以到处用mongo启动了   https://docs.mongodb.com/v4.0/reference/configuration-options/#storage.dbPath   storage: dbPath: "/soft/mongodb/data/db" systemLog: destination: file path: "/soft/mongodb/log/mongodb.log" net: bindIp: 0.0.0.0 port: 27017 processManagement: fork: true setParameter: enableLocalhostAuthBypass: false   启动自带的客户端链接,在安装目录下的/bin下,直接输入mongo        注:要有配置环境变量才能直接mongo     成功,开始撸吧.  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: