1.下载
最后采用的是4.4.17 ,因为最新的版本中mongo命令被单独移出去了
2. 上传到
/opt/servers/mongodb下,并解压
tar -zxvf mongodb-linux-x86_64-rhel70-4.4.17.tgz
mv mongodb-linux-x86_64-rhel70-6.0.2 mongodb-4.4.17
cd mongodb-4.4.17 && mkdir data && mkdir logs && mkdir pid
cd data && mkdir logs && mkdir db
cd conf && vi mongodb.conf
#数据库存储
dbpath=/opt/servers/mongodb/mongodb-4.4.17/data/db/
#日志保存路径
logpath=/opt/servers/mongodb/mongodb-4.4.17/data/logs/mongdb.log
#进程描述文件
pidfilepath=/opt/servers/mongodb/mongodb-6.0.2/pid/mongo.pid
#日志追加写入
logappend=true
bind_ip_all=true
#mongo默认端口
port=27017
#操作日志容量
oplogSize=10000
#操作日志容量
fork=true
#需要登录认证
#auth=true
修改环境变量
vi ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/opt/servers/mongodb/mongodb-6.0.2/bin
export PATH
生效 source ~/.bash_profile
查看mongodb 版本
[root@node4 conf]# mongod --version
db version v6.0.2
Build Info: {
"version": "6.0.2",
"gitVersion": "94fb7dfc8b974f1f5343e7ea394d0d9deedba50e",
"openSSLVersion": "OpenSSL 1.0.1e-fips 11 Feb 2013",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "rhel70",
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
2.启动
–fork 表示后台运行
[root@node4 mongodb-6.0.2]# mongod --f /opt/servers/mongodb/mongodb-6.0.2/conf/mongodb.conf --fork
Error parsing command line: unrecognised option '--f'
try 'mongod --help' for more information
[root@node4 mongodb-6.0.2]# mongod -f /opt/servers/mongodb/mongodb-6.0.2/conf/mongodb.conf --fork
about to fork child process, waiting until server is ready for connections.
forked process: 11516
child process started successfully, parent exiting
停止服务
采用mongo命令登录到服务上,停止服务即可
输入 mongo,默认登录到当前机器的mongodb服务上
输入
> db.shutdownServer();
> shutdown command only works with the admin database; try 'use admin'
> use admin
switched to db admin
> db.shutdownServer();
server should be down...
> exit 退出
检查发现,mongo进程已经停止了
[root@node4 ~]# ps -ef |grep mongo
root 15048 10008 0 16:53 pts/2 00:00:00 grep --color=auto mongo
[root@node4 ~]#