Centos7.x 下安装mongodb4.2


 

1、切换的src目录,下载包文件解压后,改名并迁移到 /usr/local/mongodb ,

创建运行mongodb的用户、组,创建存放数据、日、运行pid的目录,并改成所属用户、组为mongodb

cd /usr/local/src
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.0.tgz
tar xvzf mongodb-linux-x86_64-rhel70-4.2.0.tgz
mv mongodb-linux-x86_64-rhel70-4.2.0 /usr/local/mongodb
cd /usr/local/mongodb
groupadd mongodb
useradd -s /sbin/nologin -g mongodb -M mongodb
mkdir data log run
chown -R mongodb:mongodb data log run

2、在/usr/local/mongodb 里面创建一个配置文件 mongodb.conf 

vi 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
maxConns=5000
noauth = true
3、注册服务 vi /usr/lib/systemd/system/mongodb.service

[Unit]

  
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
  
[Service]
Type=forking
LimitNOFILE=64000
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
 


4、这是开机启动,并启动。

systemctl daemon-reload
systemctl enable mongodb
systemctl start mongodb
如果需要停止,就执行:  

systemctl stop mongodb
查看状态:

systemctl status mongodb
5、配置mongodb为环境变量,方便直接在shell中操作

vi /etc/profile
在/etc/profile文件末尾添加一行: 

export PATH=/usr/local/mongodb/bin:$PATH
让其生效:

source /etc/profile


6、查看当前mongodb的版本:

mongod --version


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM