Alibaba Linux-mongodb服务部署笔记

173 阅读1分钟
cd 对应目录
tar -zxvf 压缩包名
  • 配置环境变量:
vim /etc/profile

拉到文件最后添加

export MONGODB_HOME=/路径/mongodb文件夹
export PATH=$MONGODB_HOME/bin:$PATH
  • 让环境变量配置生效
source /etc/profile
  • /etc 中创建mongodb系统配置文件 mongo.conf
  • /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:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

# 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.


security:
  authorization: enabled

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

  • 端口可以自己定,在云服务器-安全组中开启端口

image.png

  • 不需要用户名密码就把配置文件中下面这段注释掉(不建议)
security:
  authorization: enabled
  • 授权配置文件中两个path路径,路径没有就创建
  • 还有这个:/var/run/mongodb 老规矩,没有就创建文件夹、授权
chmod 777 路径
  • 由于mongodb版本在4.0以上,缺个库,装一下
yum install compat-openssl10
  • 启动
mongod -f /etc/mongod.conf

有successfully就成了,报错了百度去

  • 校验:
netstat -tnlp | grep 配置文件中定义的端口号(27017
  • 进到mongo:
mongo
  • 创建管理员账号
use admin
db.createUser({user:"用户名",pwd:"密码",roles:[{role:"root",db:"admin"}]})
  • 校验是否创建成功
  • Ctrl C 退出,使用已创建用户登录
mongo --port 27017 -u 用户名 -p '密码' --authenticationDatabase 'admin'

  • 然后
use admin
db.getUsers()

带着 用户名密码、端口号、服务器公网ip 连mongo可视化工具去吧,验证数据库填admin