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

posted on 2020-04-22 17:26  QQ10053660  阅读(883)  评论(0编辑  收藏  举报