在rockylinux9.4环境中安装mongodb5.0.15
本次redis3.2.13版本集群搭建采用一台虚机,以192.168.190.151虚机为例
虚机配置:
机器IP | CPU&内存 | 系统盘 | 备注 |
192.168.190.151 hadoop1 | 2C4G | 50GB | 建议最低配置 |
https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-5.0.15-rc2.tgz 下载mongodb-linux-x86_64-rhel70-5.0.15-rc2.tgz安装包 |
或者在rockylinux9.4系统中直接输入指令
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-5.0.15-rc2.tgz |
需在下文的software目录下执行
Ps:解压之后,检查mongodb的依赖环境:ldd ./mongod 如果发现缺少libcrypto.so.10,需使用 wget https://vault.centos.org/centos/8/AppStream/x86_64/os/Packages/compat-openssl10-1.0.2o-3.el8.x86_64.rpm 命令安装依赖环境 安装完成之后执行:rpm -ivh compat-openssl10-1.0.2o-3.el8.x86_64.rpm |
cd /opt mkdir {software,module} cd /module mkdir MongoDB cd /MongoDB mkdir data log |
4、进入/software目录中,解压mongodb压缩包并解压至/MongoDB目录下:
cd /opt/software tar -zxvf mongodb-linux-x86_64-rhel70-5.0.15-rc2.tgz -C /opt/module/MongoDB |
mv mongodb-linux-x86_64-rhel70-5.0.15-rc2.tgz mongodbServer |
vi /opt/module/MongoDB/mongodbServer/bin/mongod.conf
内容:
storage: dbPath: "/opt/module/MongoDB/data" systemLog: destination: file path: "/opt/module/MongoDB/log/mongod.log" logAppend: true net: port: 27017 bindIpAll: true processManagement: fork: true pidFilePath: /var/run/mongodb/mongod.pid |
vi /etc/profile
内容:
export MONGODB_HOME=/usr/local/MongoDB/mongodbServer export PATH=$PATH:$MONGODB_HOME/bin export LD_LIBRARY_PATH=/usr/lib64/libcrypto.so.10/directory:$LD_LIBRARY_PATH |
source /etc/profile |
(安装完成之后,打开虚机初次使用,需先启动服务)
/opt/module/MongoDB/mongodbServer/bin/mongod --config /opt/module/MongoDB/mongodbServer/bin/mongod.conf |
vi /opt/module/MongoDB/mongodbServer/bin/mymongo |
内容:
#!/bin/bash start() { /opt/module/MongoDB/mongodbServer/bin/mongod --config /opt/module/MongoDB/mongodbServer/bin/mongod.conf }
stop() { /opt/module/MongoDB/mongodbServer/bin/mongod --config /opt/module/MongoDB/mongodbServer/bin/mongod.conf --shutdown } case "$1" in start) start ;;
stop) stop ;;
restart) stop start ;; *) echo $"Usage:$0 {start|stop|restart}" exit 1 esac |
/opt/module/MongoDB/mongodbServer/bin/mymongo stop |
/opt/module/MongoDB/mongodbServer/bin/mymongo start |
8、如果想使用systemctl start mongodb,可以先编写一个mongodb.service的配置文件
路径:vi /etc/systemd/system/mongodb.service
内容:
[Unit] Description=MongoDB Database Server After=network.target [Service] User=root Group=root ExecStart=/opt/module/MongoDB/mongodbServer/bin/mongod --config /opt/module/MongoDB/mongodbServer/bin/mongod.conf ExecStop=/bin/kill -15 $MAINPID PIDFile=/var/run/mongodb/mongod.pid [Install] WantedBy=multi-user.target |