MongoDB的两种安装方式
一、使用yum在线安装MongoDB
下载地址:https://repo.mongodb.com/yum/redhat/7/mongodb-enterprise/4.2/x86_64
校验:https://repo.mongodb.com/yum/redhat/7/mongodb-enterprise/4.2/x86_64
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# vim mongodb.repo
[[email protected] ~]# yum install -y mongodb-enterprise
[[email protected] ~]# rpm -aq | grep mongodb*
mongodb-enterprise-4.2.8-1.el7.x86_64
mongodb-enterprise-cryptd-4.2.8-1.el7.x86_64
mongodb-enterprise-tools-4.2.8-1.el7.x86_64
mongodb-enterprise-shell-4.2.8-1.el7.x86_64
mongodb-enterprise-mongos-4.2.8-1.el7.x86_64
mongodb-enterprise-server-4.2.8-1.el7.x86_64
[[email protected] ~]# systemctl start mongod
登录:
[r[email protected] ~]# mongo
[[email protected] ~]# rpm -aq | grep mongodb*
mongodb-enterprise-4.2.8-1.el7.x86_64
mongodb-enterprise-cryptd-4.2.8-1.el7.x86_64
mongodb-enterprise-tools-4.2.8-1.el7.x86_64
mongodb-enterprise-shell-4.2.8-1.el7.x86_64
mongodb-enterprise-mongos-4.2.8-1.el7.x86_64
mongodb-enterprise-server-4.2.8-1.el7.x86_64
二、源码安装MongoDB并配置服务脚本
解压:[[email protected] ~]# tar xf mongodb-linux-x86_64-rhel70-4.2.8.tgz -C /usr/local/
创建数据目录:[[email protected] ~]# mkdir -p /data/db
[[email protected] ~]# cd /usr/local/
[[email protected] local]# ln -sv mongodb-linux-x86_64-rhel70-4.2.8/ mongodb"mongodb" -> "mongodb-linux-x86_64-rhel70-4.2.8/"
[[email protected] local]# echo "export PATH=$PATH:/usr/local/mongodb/bin" > /etc/profile.d/mongo.sh
[[email protected] local]# source /etc/profile.d/mongo.sh
启动:
[email protected] local]# mongod --dbpath /data/db/ &
检查:
[[email protected] ~]# ps -ef | grep mongod root 2146 2042 1 16:02 pts/0 00:00:00 mongod --dbpath /data/db/
[[email protected] ~]# netstat -lnupt | grep 27017 tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 2146/mongod
创建配置文件:
[[email protected] ~]# vim /usr/local/mongodb/bin/mongod.conf
创建存放目录:
[[email protected] ~]# mkdir -p /usr/local/mongodb/{data,log}
配置mongodb.service文件
[[email protected] ~]# vim /usr/lib/systemd/system/mongodb.service
[[email protected] ~]# kill `pidof mongod`
[[email protected] ~]# systemctl start mongodb