建成学校网站,上海搬家公司哪家好,免费刷赞网站推广qq免费,中山好的网站建设公司文章目录 说明1. 下载安装包2. 安装数据库3. 配置 systemctl4. 创建 root 用户 说明
本篇文章介绍 MongoDB 二进制安装的步骤#xff0c;整个过程还是比较简单。
1. 下载安装包
进入 MongoDB 官网#xff0c;获取安装包的下载链接#xff1a; https://www.mongodb.com/tr… 文章目录 说明1. 下载安装包2. 安装数据库3. 配置 systemctl4. 创建 root 用户 说明
本篇文章介绍 MongoDB 二进制安装的步骤整个过程还是比较简单。
1. 下载安装包
进入 MongoDB 官网获取安装包的下载链接 https://www.mongodb.com/try/download/community 以下载 5.0.23 版本为例
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-5.0.23.tgz2. 安装数据库
解压缩包
tar -zxvf mongodb-linux-x86_64-rhel70-5.0.23.tgz drwxr-xr-x 2 root root 70 12月 19 10:21 bin -rw-r–r-- 1 root root 30608 11月 20 23:29 LICENSE-Community.txt -rw-r–r-- 1 root root 16726 11月 20 23:29 MPL-2 -rw-r–r-- 1 root root 1977 11月 20 23:29 README -rw-r–r-- 1 root root 77913 11月 20 23:29 THIRD-PARTY-NOTICES mv mongodb-linux-x86_64-rhel70-5.0.23 /usr/local/mongodb创建配置文件
touch /usr/local/mongodb/mongod.conf创建数据目录
mkdir -p /data/mongodb/{data,logs,run}创建 mongod 用户
groupadd mongod
useradd -g mongod -s /sbin/nologin -r mongod修改文件属组
chown -R mongod:mongod /usr/local/mongodb/
chown -R mongod:mongod /data/mongodb/配置环境变量
echo export PATH\$PATH:/usr/local/mongodb/bin /etc/profile
source /etc/profile写入配置文件 vi /usr/local/mongodb/mongod.conf # where to write logging data.
systemLog:destination: filelogAppend: truepath: /data/mongodb/logs/mongod.log
# Where and how to store data.
storage:dbPath: /data/mongodb/datajournal:enabled: true# how the process runs
processManagement:fork: true # fork and run in backgroundpidFilePath: /data/mongodb/run/mongod.pid # location of pidfile# network interfaces
net:port: 27017bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
security: authorization: enabled启动 MongoDB PS可以不用启动直接配置 systemctl : /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/mongod.confabout to fork child process, waiting until server is ready for connections. forked process: 28580 child process started successfully, parent exiting 关闭 MongoDB
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/mongod.conf --shutdown3. 配置 systemctl
配置前需要把刚启动的 MongoDB 手动关闭掉否则测试会报错。
vi /usr/lib/systemd/system/mongod.service将下面内容写入 mongod.service 中。
[Unit]
DescriptionMongoDB Database Server
Documentationhttps://docs.mongodb.org/manual
Afternetwork-online.target
Wantsnetwork-online.target[Service]
Usermongod
Groupmongod
EnvironmentOPTIONS-f /usr/local/mongodb/mongod.conf
ExecStart/usr/local/mongodb/bin/mongod $OPTIONS
PermissionsStartOnlytrue
PIDFile/data/mongodb/run/mongod.pid
Typeforking
# file size
LimitFSIZEinfinity
# cpu time
LimitCPUinfinity
# virtual memory size
LimitASinfinity
# open files
LimitNOFILE64000
# processes/threads
LimitNPROC64000
# locked memory
LimitMEMLOCKinfinity
# total threads (userkernel)
TasksMaxinfinity
TasksAccountingfalse
# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings[Install]
WantedBymulti-user.target重新加载配置
systemctl daemon-reload# 启动
systemctl start mongod
# 查看状态
systemctl status mongod
# 设置开机自启
systemctl enable mysqldPS如果使用 systemctl 启动失败通常是目录授权问题或者是未删除 mongod.lock 找到它并删除再重试。 4. 创建 root 用户
配置文件中开启了授权所以进入 MongoDB 后需要先创建 root 高权限账号。
use admin
db.createUser ( {user: root,pwd: admin123,roles: [{role: root, db: admin}]})