cd /root/downfiles //进入下载目录
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-4.4.18.tgz //下载mongodb
tar -zxvf mongodb-linux-x86_64-rhel80-4.4.18.tgz //解压
mv mongodb-linux-x86_64-rhel80-4.4.18 /usr/software/mongodb //移动到另外一个目录下
cd /usr/software/mongodb //进入mongodb
mkdir data //创建数据目录 mkdir logs //创建日志目录 mkdir conf //创建配置目录
cd logs // 进入日志目录
touch mongo.log //新建日志文件
cd .. //返回一层
cd conf //进入配置文件
touch mongo.conf //创建配置文件
vi mongo.conf // 编辑
dbpath=/usr/software/mongodb/data
logpath=/usr/software/mongodb/logs/mongo.log
logappend=true
journal=true
quiet=true
port=27017
bind_ip=0.0.0.0
fork=true
firewall-cmd --add-port=27017/tcp --permanent //防火墙添加出入站规则
service firewalld restart // 重启防护墙
开机自启
vi /etc/rc.d/rc.local //编辑
/usr/software/mongodb/bin/mongod --config /usr/software/mongodb/conf/mongo.conf //最后一个插入
chmod +x /etc/rc.d/rc.local //赋予执行权限
开机自启方法二
cd /etc/init.d/ //进入该目录
touch mongodb.sh //新建
vim mongodb.sh //编辑
// 插入内容
#!/bin/sh
#chkconfig: 2345 80 90
#description: mongodb#!/bin/sh
#chkconfig: 2345 80 90
#description: mongodb
start() {
/usr/software/mongodb/bin/mongod --config /usr/software/mongodb/conf/mongo.conf
}
stop()
{
/usr/software/mongodb/bin/mongod --config /usr/software/mongodb/conf/mongo.conf --shutdown
}
case "$1" in
start)
start
echo "mongodb start"
;;
stop)
stop
echo "mongodb stop"
;;
restart)
stop
start
echo "mongodb restart"
;;
esac
// :wq保存
chmod +x mongodb.sh //赋予执行权限
chkconfig --add mongodb.sh //添加服务
chkconfig mongodb.sh on //自启

浙公网安备 33010602011771号