一、上传部署包
1.1上传mongodb包进入/usr/local目录,将mongodb-linux-x86_64-rhel70-4.2.25.tgz包传到该目录下。
cd /usr/local |
二、安装
2.1解压
tar zxvf mongodb-linux-x86_64-rhel70-4.2.25.tgz |
2.2修改名称
mv mongodb-linux-x86_64-rhel70-4.2.25/ mongodb |
2.3 配置环境变量
vim /etc/profile # mongodb export PATH=$PATH:/usr/local/mongodb/bin |
2.4 更新环境变量
source /etc/profile |
2.5创建配置文件
touch /usr/local/mongodb/mongod.conf |
2.6创建数据目录
mkdir -p /data/mongodb/{data,logs,run} |
2.7创建 mongod 用户
groupadd mongod useradd -g mongod -s /sbin/nologin -r mongod |
2.8修改文件属组
chown -R mongod:mongod /usr/local/mongodb/ chown -R mongod:mongod /data/mongodb/ |
2.9 写入配置文件
vim /usr/local/mongodb/mongod.conf |
# where to write logging data. systemLog: destination: file logAppend: true path: /data/mongodb/logs/mongod.log # Where and how to store data. storage: dbPath: /data/mongodb/data journal: enabled: true # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /data/mongodb/run/mongod.pid # location of pidfile # network interfaces net: port: 27017 bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting. maxIncomingConnections: 2000 # 最大连接数 security: authorization: enabled |
security.authorization:指定是否启用身份验证。默认为disabled,表示不启用身份验证。在生产环境中,建议将该选项设置为enabled,并配置合适的用户和角色权限。
2.10 启动MongoDB
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/mongod.conf |
查看是否启动成功
ps -ef|grep mongodb |
2.11 关闭 MongoDB
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/mongod.conf --shutdown |
2.12开放端口方便windows远程访问
firewall-cmd --zone=public --add-port=27017/tcp --permanent firewall-cmd --reload |