Installation MongoDB-6.0.2 on CentOS 8.3

一、Installation MongoDB-6.0.2 on CentOS 8.3

1 地址

2 wget 下载

cd /opt/software
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-6.0.2.tgz
wget https://downloads.mongodb.com/compass/mongodb-mongosh-1.6.0.x86_64.rpm

3 解压

tar -zxvf /opt/software/mongodb-linux-x86_64-rhel80-6.0.2.tgz -C /opt && cd /opt/mongodb-linux-x86_64-rhel80-6.0.2 && ll
mv /opt/mongodb-linux-x86_64-rhel80-6.0.2 /opt/mongodb-602

4 创建目录

启动之前需要先新建一些文件目录

创建存放配置文件目录

mkdir /opt/mongodb-602/conf

创建存放数据的目录

mkdir /opt/mongodb-602/data

常见存访日志的目录

mkdir /opt/mongodb-602/logs

创建日志记录文件

touch /opt/mongodb-602/logs/mongodb.log
tree /opt/mongodb-602

 

、配置环境变量

将 mongodb 服务加入环境变量

在文件中添加MongoDB 的安装路径下的bin 目录

vim /etc/profile
export PATH=$PATH:/opt/mongodb-602/bin/
# 使配置文件生效
source /etc/profile

# 
cp /opt/mongodb-602/bin/* /usr/local/bin/

 

三、后台启动

1 所谓的后台启动就是以守护进程的方式启动 MongoDB,命令中添加 --fork 即可。

mongod --dbpath /opt/mongdb-602/data --logpath /opt/mongdb-602/logs/mongodb.log --logappend --port 27017 --bind_ip 0.0.0.0 --fork

2 配置文件启动

新建 配置文件内容

vim /opt/mongodb-602/conf/mongodb.conf

# 数据文件存访目录
dbpath = /opt/mongodb-602/data
# 日志文件存访目录
logpath = /opt/mongodb-602/logs/mongodb.log
# 以追加的方式记录日志
logappend = true
# 端口默认为 27017
port = 27017
# 对访问 IP 地址不做限制,默认为本机地址
bind_ip = 0.0.0.0
# 以守护进程的方式启用,即在后台运行
fork = true
# 所有客户端都可以访问
bind_ip_all = true

3 启动命令

mongod -f /opt/mongodb-602/conf/mongodb.conf

4 安装 mongosh

[root@slave01 ~]# rpm -ivh /opt/software/mongodb-mongosh-1.6.0.x86_64.rpm 
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mongodb-mongosh-1.6.0-1.el8      ################################# [100%]
5 使用 mongosh 进入数据库,exit 退出
test> version()[root@master01 software]# mongosh 
Current Mongosh Log ID:	636b433c32a58c8a6ba3e838
Connecting to:		mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.6.0
Using MongoDB:		6.0.2
Using Mongosh:		1.6.0

For mongosh info see: https://docs.mongodb.com/mongodb-shell/


To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.

------
   The server generated these startup warnings when booting
   2022-11-09T14:05:27.175+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2022-11-09T14:05:27.175+08:00: You are running this process as the root user, which is not recommended
   2022-11-09T14:05:27.175+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
   2022-11-09T14:05:27.175+08:00: Soft rlimits for open file descriptors too low
------

------
   Enable MongoDB's free cloud-based monitoring service, which will then receive and display
   metrics about your deployment (disk utilization, CPU, operation statistics, etc).
   
   The monitoring data will be available on a MongoDB website with a unique URL accessible to you
   and anyone you share the URL with. MongoDB may use this information to make product
   improvements and to suggest MongoDB products and deployment options to you.
   
   To enable free monitoring, run the following command: db.enableFreeMonitoring()
   To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
------

test> version()
1.6.0

 

四、外部访问

1 开放防火墙端口,以便外部访问

# 关闭防火墙
systemctl stop firewalld

# 开放27017端口命令
firewall-cmd --zone=public --add-port=27017/tcp --permanent

# 配置立即生效
firewall-cmd --reload

2 云主机需配置安全组

在入方向规则,允许27017放行

Navicat 连接

 

X、One Step Success

systemctl stop firewalld

cd /opt/software
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-6.0.2.tgz
wget https://downloads.mongodb.com/compass/mongodb-mongosh-1.6.0.x86_64.rpm

tar -zxvf /opt/software/mongodb-linux-x86_64-rhel80-6.0.2.tgz -C /opt && cd /opt/mongodb-linux-x86_64-rhel80-6.0.2 && ll
mv /opt/mongodb-linux-x86_64-rhel80-6.0.2 /opt/mongodb-602
cp /opt/mongodb-602/bin/* /usr/local/bin/

mkdir /opt/mongodb-602/conf
mkdir /opt/mongodb-602/data
mkdir /opt/mongodb-602/logs
touch /opt/mongodb-602/logs/mongodb.log

cat > /opt/mongodb-602/conf/mongodb.conf << EOF
# 数据文件存访目录
dbpath = /opt/mongodb-602/data
# 日志文件存访目录
logpath = /opt/mongodb-602/logs/mongodb.log
# 以追加的方式记录日志
logappend = true
# 端口默认为 27017
port = 27017
# 对访问 IP 地址不做限制,默认为本机地址
bind_ip = 0.0.0.0
# 以守护进程的方式启用,即在后台运行
fork = true
# 所有客户端都可以访问
bind_ip_all = true
EOF

mongod -f /opt/mongodb-602/conf/mongodb.conf
rpm -ivh /opt/software/mongodb-mongosh-1.6.0.x86_64.rpm
mongosh

 

Y、Error message

 

Z、Related Links

 Installation MongoDB-5.0.13 on CentOS 7.9:https://www.cnblogs.com/huaxiayuyi/p/16758999.html

 

posted @ 2022-11-09 00:21  娇小赤雅  阅读(189)  评论(0编辑  收藏  举报