mongodb通过yum安装脚本
#!/bin/bash
echo "**************************************"
echo "***** *****"
echo "*** Mongodb 安装 ***"
echo "***** *****"
echo "**************************************"
# 配置MongoDB的yum源
echo "------------------------------配置mongodb的yum源------------------------------------------"
touch /etc/yum.repos.d/mongodb-org-3.4.repo
echo "[mongodb-org-3.4]" >> /etc/yum.repos.d/mongodb-org-3.4.repo
echo "name=MongoDB Repository" >> /etc/yum.repos.d/mongodb-org-3.4.repo
echo "baseurl=https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/3.4/x86_64/" >> /etc/yum.repos.d/mongodb-org-3.4.repo
echo "gpgcheck=1" >> /etc/yum.repos.d/mongodb-org-3.4.repo
echo "enabled=1" >> /etc/yum.repos.d/mongodb-org-3.4.repo
echo "gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc" >> /etc/yum.repos.d/mongodb-org-3.4.repo
# 安装
echo "------------------------------开始安装------------------------------"
yum -y install mongodb-org
# 设置开机启动
echo "------------------------------设置开机启动------------------------------"
systemctl enable mongod.service
# 开启远程连接
sed -i "s|bindIp: 127.0.0.1|# bindIp: 127.0.0.1|" /etc/mongod.conf
# 关闭防火墙
# systemctl stop firewalld.service
# systemctl disable firewalld.service
# 防火墙配置,开放端口
echo "------------------------------设置防火墙,开启27017端口------------------------------"
firewall-cmd --permanent --add-port=27017/tcp
echo "------------------------------重新加载防火墙------------------------------"
firewall-cmd --reload
echo "------------------------------mongodb启动------------------------------"
systemctl start mongod.service
echo "------------------------------查看启动状态------------------------------"
systemctl status mongod.service