安装mongodb
...大约 1 分钟
安装
RedHat / CentOS 7.0 x64
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/6.0/x86_64/RPMS/mongodb-org-server-6.0.6-1.el7.x86_64.rpm
rpm -ivh mongodb-org-server-6.0.6-1.el7.x86_64.rpm
RedHat / CentOS 7.0 x64 二进制安装
# 安装依赖
yum install libcurl openssl
# 二进制下载
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-6.0.6.tgz
tar -zxvf mongodb-linux-x86_64-rhel70-6.0.6.tgz
mv mongodb-linux-x86_64-rhel70-6.0.6 /usr/local/mongodb6
# 配置环境变量
vi /etc/profile
## 贴入内容 开始
export PATH=/usr/local/mongodb6/bin:$PATH
## 贴入内容 结束
source /etc/profile
# 创建数据库目录(默认情况下,启动服务会自动创建)
mkdir /var/lib/mongo
mkdir /var/log/mongodb
# 设置当前用户有读写权限
chown `whoami` /var/lib/mongo
chown `whoami` /var/log/mongodb
# 启动命令
mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork
配置文件
vi /etc/mongod.conf
# 贴入内容 开始
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# wiredTiger:
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
# 贴入内容 结束
制作系统服务
vi /etc/systemd/system/mongod.service
# 贴入内容 开始
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target
[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"
Environment="MONGODB_CONFIG_OVERRIDE_NOFORK=1"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/local/mongodb6/bin/mongod $OPTIONS
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings
[Install]
WantedBy=multi-user.target
# 贴入内容 结束
启动/重启/停止服务(systemd)
# 启动
systemctl start mongod
# 停止
systemctl stop mongod
# 重启
systemctl restart mongod
# 设置开机自启
systemctl enable mongod
# 取消开机自启
systemctl disable mongod
# 查看状态
systemctl status mongod
Powered by Waline v2.15.5