Linux centos7安装Mongodb-4.0

1. 解压安装

解压:

tar -zxvf mongodb-linux-x86_64-4.0.19.tgz -C /usr/local

 移动:

mv mongodb-linux-x86_64-4.0.19 mongodb

2. 配置conf与目录

(1) 进入mongodb目录

cd /usr/local/mongodb

(2)创建日志文件

touch logs

(3)创建mongodb.conf文件

vim mongodb.conf

复制代码

#端口号
port=27017
#db目录
dbpath=/usr/local/mongodb/data
#日志目录
logpath=/usr/local/mongodb/logs
#后台
fork=true
#日志输出
logappend=true
#允许远程IP连接
bind_ip=0.0.0.0

3.启动测试

(1) 启动

./bin/mongod --config mongodb.conf

(2) 连接

./bin/mongo

4.如果需要主机连接虚拟机的centos, 关闭防火墙

systemctl stop firewalld.service #关闭防火墙
systemctl disable firewalld.service #禁止启动防火墙

5. 设置开机自启

在系统服务目录下新建 mongodb 的启动服务

cd /lib/systemd/system
vi mongodb.service

内容如下

[Unit]

Description=mongodb

After=network.target remote-fs.target nss-lookup.target 

[Service]

Type=forking

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

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/mongodb.conf

PrivateTmp=true

[Install]

WantedBy=multi-user.target

路径必须要写绝对路径

并给与 754 的权限

chmod 754 mongodb.service 

启动

systemctl start mongodb.service

关闭

systemctl stop mongodb.service

注册到开机启动

systemctl enable mongodb.service

重启机器验证

reboot

  

.

 

 

 

 

 

posted @ 2020-08-01 22:47  xykdmm  阅读(231)  评论(0)    收藏  举报