Linux安装Mongodb4.2
1.下载mongodb安装版本至linux服务器,我这边是/usr/local/src下面
2.解压安装包,将安装包里面的内容移动至/usr/local/mongodb下面
# tar zxvf mongodb-linux-x86_64-rhel70-4.2.0.tgz # mkdir /usr/local/mongodb # mv mongodb-linux-x86_64-rhel70-4.2.0/* /usr/local/mongodb/
3.切换至/usr/local/mongodb下,新建data文件夹,log文件夹
# cd mongodb/ # mkdir data # mkdir log
4.vim编辑mongodb.conf文件
bind_ip=0.0.0.0 port=27017 dbpath=/usr/local/mongodb/data/ logpath=/usr/local/mongodb/log/mongodb.log pidfilepath =/usr/local/mongodb/run/mongodb.pid logappend=true fork=true journal=true maxConns=2000 auth = true
5.执行vim /etc/profile命令后按i键编辑,在文件末尾加上如下配置
export PATH=/usr/local/mongodb/bin:$PATH
保存退出后执行:source /etc/profile 重启配置文件
6.设置mongodb.service启动服务
cd /lib/systemd/system
vi mongodb.service
[Unit] Description=MongoDB Database Server Documentation=https://docs.mongodb.org/manual After=network.target remote-fs.target nss-lookup.target [Service] Type=forking User=root Group=root ExecStart=/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/mongodb.conf ExecStop=/usr/local/mongodb/bin/mongod --shutdown -f /usr/local/mongodb/mongodb.conf [Install] WantedBy=multi-user.target
mongodb.service服务权限修改
chmod 754 mongodb.service
系统mongodb.service操作命令
#启动服务
systemctl start mongodb.service
#关闭服务
systemctl stop mongodb.service
#开机启动
systemctl enable mongodb.service