目录
1、下载安装包并解压
bash
cd /energy/apps-local/lib
wget -O mongodb-linux-x86_64-rhel70-7.0.15.tgz https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-7.0.15.tgz
tar -zxvf mongodb-linux-x86_64-rhel70-7.0.15.tgz
mv mongodb-linux-x86_64-rhel70-7.0.15 mongodb
2、下载Tools工具包并解压
bash
cd /energy/apps-local/lib
wget -O mongodb-database-tools-rhel70-x86_64-100.10.0.tgz https://fastdl.mongodb.org/tools/db/mongodb-database-tools-rhel70-x86_64-100.10.0.tgz
tar -zxvf mongodb-database-tools-rhel70-x86_64-100.10.0.tgz
mv mongodb-database-tools-rhel70-x86_64-100.10.0/bin/* ./mongodb/bin/
rm -rf ./mongodb-database-tools-rhel70-x86_64-100.10.0
3、设置环境变量
# 将以下代码加入/etc/profile末尾
# MongoDB
export PATH=/energy/apps-local/lib/mongodb/bin:$PATH
4、刷新环境变量
source /etc/profile
5、创建配置文件
创建/energy/apps-local/lib/mongodb/mongod.conf并写入以下内容
bash
systemLog:
destination: file
logAppend: true
path: /energy/apps-local/logs/mongodb/mongod.log
storage:
engine: wiredTiger
directoryPerDB: true
dbPath: /energy/apps-local/data/mongodb
wiredTiger:
engineConfig:
configString: cache_size=40G
processManagement:
pidFilePath: /energy/apps-local/data/mongodb/mongod.pid
timeZoneInfo: /usr/share/zoneinfo
net:
port: 27017
bindIp: 0.0.0.0
6、打开防火墙
firewall-cmd --zone=drop --add-port=27017/tcp --permanent
firewall-cmd --reload
7、赋予安装目录可执行权限
chown -R root:root /energy/apps-local/lib/mongodb
chmod -R 700 /energy/apps-local/lib/mongodb
8、创建数据目录和日志目录
创建数据目录与日志目录并创建日志文件,地址与配置文件中对应
mkdir -p /energy/apps-local/data/mongodb
mkdir -p /energy/apps-local/logs/mongodb
touch /energy/apps-local/logs/mongodb/mongod.conf
9、创建服务启动脚本(ststemctl)
创建/usr/lib/systemd/system/mongod.service并写入以下内容
bash
[Unit]
Description=mongod
After=network.target
[Service]
LimitNOFILE=500000
User=root
PrivateTmp=true
Restart=always
ExecStart=/energy/apps-local/lib/mongodb/bin/mongod -f /energy/apps-local/lib/mongodb/mongod.conf
[Install]
WantedBy=multi-user.target
10、启动服务并将启动脚本加入开机自启动
systemctl enable --now mongod
11、查看服务状态
systemctl status mongod