二进制部署很简单
创建存放软件目录下载解压
存放数据和日志及配置文件路径需要手工进行创建
mkdir -p /application/tools/ cd /application/tools/ wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.7.tgz tar xf mongodb-linux-x86_64-rhel70-4.2.7.tgz -C /application/ mv /application/mongodb-linux-x86_64-rhel70-4.2.7 /application/mongodb-4.2.7 ln -sv /application/mongodb-4.2.7/ /application/mongodb mkdir -p /application/mongodb/{data,logs,conf} echo 'export PATH=/application/mongodb/bin:$PATH' >>/etc/profile source /etc/profile
使用systemd进行管理
cat >/usr/lib/systemd/system/mongodb.service <<EOF [Unit] Description=mongodb After=network.target [Service] Type=forking PIDFile=/tmp/mongod.pid RuntimeDirectory=mongodb RuntimeDirectoryMode=0751 ExecStart=/application/mongodb/bin/mongod --config /application/mongodb/conf/mongodb.conf ExecStop=/application/mongodb/bin/mongod --shutdown --config /application/mongodb/conf/mongodb.conf PrivateTmp=false [Install] WantedBy=multi-user.target EOF
增加执行权限设置开机自启
systemctl daemon-reload chmod +x /usr/lib/systemd/system/mongod.service systemctl start mongod.service systemctl stop mongod.service systemctl restart mongod.service systemctl enable mongod.service
MongoDB常用命令
查看当前库下的用户 use admin db.system.users.find().pretty() 查看当前数据库版本 db.version() 切换数据库 use test 查询所有数据库 show dbs; 查看smile数据库当前状态 use admin db.stats() 查看当前数据库的连接机器地址 db.getMongo()