Mongodb的yum安装方式
YUM方式安装
配置YUM源
cat > /etc/yum.repos.d/MongoDB.repo <<EOF
[mngodb-org]
name=MongoDB Repository
baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/4.0/x86_64/
gpgcheck=0
enabled=1
EOF
安装
yum clean all
yum makecache
yum -y install mongodb-org
创建数据目录
mkdir -p /var/lib/mongo
mkdir -p /var/log/mongodb
修改目录权限(默认使用mongod执行)
chown -R mongod.mongod /var/lib/mongo
chown -R mongod.mongod /var/log/mongodb
修改配置文件
cat > /etc/mongod.conf <<EOF
systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log storage: dbPath: /var/lib/mongo journal: enabled: true processManagement: fork: true pidFilePath: /var/run/mongodb/mongod.pid timeZoneInfo: /usr/share/zoneinfo net: port: 27017 bindIp: 193.168.1.101
EOF
启动、停止服务
启动mongodb :systemctl start mongod.service
停止mongodb :systemctl stop mongod.service
/usr/bin/mongod -f /etc/mongod.conf --fork