[root@oracledb ~]# tar xf mongodb-linux-x86_64-rhel70-5.0.5.tgz -C /usr/local/ [root@oracledb ~]# cd /usr/local/## 重命名[root@oracledb local]# mv mongodb-linux-x86_64-rhel70-5.0.5/ mongodb[root@oracledb local]# ls
bin games jdk lib64 mongodb openresty sbin src
etc include lib libexec mysql redis share tomcat9
2.配置环境变量
[root@oracledb ~]# vim /etc/profileexportMONGO_HOME=/usr/local/mongodb
exportPATH=$PATH:$MONGO_HOME/bin
[root@oracledb ~]# vim /etc/profile[root@oracledb ~]# mongo
mongo mongod mongos
[root@oracledb data]# vim /usr/local/mongodb/mongodb.conf
dbpath = /data/mongodb/db
logpath = /data/mongodb/logs/mongodb.log
port =27017
fork =true
bind_ip =192.168.18.132
auth =truewiredTigerCacheSizeGB=2##启动服务[root@oracledb data]# mongod --config /usr/local/mongodb/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 2114
child process started successfully, parent exiting
[root@oracledb data]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0128 *:22 *:*
LISTEN 0100127.0.0.1:25 *:*
LISTEN 0128192.168.18.132:27017 *:*
LISTEN 0128[::]:22 [::]:*
LISTEN 0100[::1]:25 [::]:*
[root@oracledb data]# mongo --host 192.168.18.132 --port 27017
MongoDB shell version v5.0.5
connecting to: mongodb://192.168.18.132:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session {"id": UUID("05341d37-e12d-4b60-a7f7-2d07d2cafa1b")}
MongoDB server version: 5.0.5
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
Welcome to the MongoDB shell.
For interactive help, type"help".
For more comprehensive documentation, see
https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
https://community.mongodb.com
>##创建用户> use admin
switched to db admin
> db.createUser({user:"root",pwd:"123456",roles:[{role:"root",db:"admin"}]})
Successfully added user: {"user":"root",
"roles":[{"role":"root",
"db":"admin"}]}>
5.创建服务控制文件
[root@oracledb bin]# vim /usr/lib/systemd/system/mongodb.service [Unit]Description=Mongodb server daemon
After=network.target sshd-keygen.target
[Service]Type=forking
ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongodb.conf
ExecReload=/bin/kill -HUP $MAINPIDExecStop=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongodb.conf --shutdown
[Install]WantedBy=multi-user.target
[root@oracledb data]# systemctl daemon-reload [root@oracledb bin]# systemctl start mongodb [root@oracledb bin]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0128 *:22 *:*
LISTEN 0100127.0.0.1:25 *:*
LISTEN 0128192.168.18.132:27017 *:*
LISTEN 0128[::]:22 [::]:*
LISTEN 0100[::1]:25 [::]:*
[root@oracledb bin]# systemctl stop mongodb [root@oracledb bin]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0128 *:22 *:*
LISTEN 0100127.0.0.1:25 *:*
LISTEN 0128[::]:22 [::]:*
LISTEN 0100[::1]:25 [::]:*
##设置开机自启 [root@oracledb bin]# systemctl enable --now mongodb
Created symlink from /etc/systemd/system/multi-user.target.wants/mongodb.service to /usr/lib/systemd/system/mongodb.service.