下载安装包
https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.19.tgz
关闭防火墙
[root@hadoop106 ~]# systemctl disable --now firewalld.service
[root@hadoop106 ~]# sed -i s/SELINUX=enforing/SELINUX=disabled/g /etc/selinux/config
创建用户
[root@hadoop106 ~]# useradd -r -M -s /sbin/nologin mongodb
解压
[root@hadoop106 ~]# cd /opt/software/mongodb/
[root@hadoop106 mongodb]# ls
mongodb-linux-x86_64-rhel70-4.2.6.tgz
[root@hadoop106 mongodb]# tar -xf mongodb-linux-x86_64-rhel70-4.2.19.tgz -C /usr/local
[root@hadoop106 mongodb]# cd /usr/local/
[root@hadoop106 local]# mv mongodb-linux-x86_64-rhel70-4.2.19 mongodb
创建存储数据、日志
[root@hadoop106 ~]# cd /usr/local/mongodb
[root@hadoop106 mogodb]# mkdir conf data logs
添加环境变量
[root@hadoop106 ~]#vi /etc/profile
export PATH=/usr/local/mongodb/bin:$PATH
source /etc/profile
修改配置文件
[root@hadoop106 ~]# vi /usr/local/mongodb/conf/mongodb.conf
port=27017
bind_ip=0.0.0.0
dbpath=/usr/local/mongodb/data
logpath=/usr/local/mongodb/logs/mongodb.log
oplogSize=20480
logappend=true
journal=true
fork=true
修改启动文件
[root@hadoop106 ~]# cat > /etc/systemd/system/mongodb.service << EOF
[Unit]
Description=mongodb
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb.conf
ExecStop=/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb.conf --shutdown
ExecReload=/bin/kill -HUP
[Install]
WantedBy=multi-user.target
EOF
启动
[root@hadoop106 ~]# systemctl daemon-reload
[root@hadoop106 ~]# systemctl start mongodb
为mongo做个软连接
[root@hadoop106 ~]# ln -s /usr/local/mongodb/bin/mongo /usr/bin/mongo
进入客户端
[root@hadoop106 ~]# mongo
查看有哪些数据库
> show dbs