centos7 rpm方式安装mongoDB
#下载三个rpm包 wget https://mirrors.tuna.tsinghua.edu.cn/mongodb/yum/el7-4.2/RPMS/mongodb-org-tools-4.2.8-1.el7.x86_64.rpm wget https://mirrors.tuna.tsinghua.edu.cn/mongodb/yum/el7-4.2/RPMS/mongodb-org-server-4.2.8-1.el7.x86_64.rpm wget https://mirrors.tuna.tsinghua.edu.cn/mongodb/yum/el7-4.2/RPMS/mongodb-org-shell-4.2.8-1.el7.x86_64.rpm #安装包 sudo rpm -ivh mongodb-org-server-4.2.8-1.el7.x86_64.rpm sudo rpm -ivh mongodb-org-shell-4.2.8-1.el7.x86_64.rpm sudo rpm -ivh mongodb-org-tools-4.2.8-1.el7.x86_64.rpm #修改配置文件,这样就可以远程连接 sudo vi /etc/mongod.conf 把bindIp: 127.0.0.1改成 bindIp: 0.0.0.0 #启动服务 service mongod start #设置开机自启动 systemctl enable mongod.service
新版本或者其他版本的rpm下载地址 https://www.mongodb.com/try/download/community
yum安装mongoDB
sudo yum -y check-update
cat << EOF | sudo tee -a /etc/yum.repos.d/mongodb-org-4.0.repo [mongodb-org-4.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc EOF
sudo yum install -y mongodb-org
sudo sed -i "s/^# engine:/ engine: mmapv1/" /etc/mongod.conf
sudo sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf
sudo systemctl enable mongod && sudo systemctl start mongod
mongo --eval "printjson(rs.initiate())"
卸载mongodb
mongodb的卸载很简单
1、停止服务
2、执行如下卸载命令
sudo yum erase $(rpm -qa | grep mongodb-org)
3、删除日志和db文件,对应/etc/mongod.conf中的systemLog.path和storage.dbPath路径