[开发笔记] nodejs+mongodb服务器部署

1 篇文章 0 订阅
1 篇文章 0 订阅

nodejs:

安装nodejs参考:https://www.cnblogs.com/mao2080/p/9346018.html

centos/ubuntu:

软件地址:https://npm.taobao.org/mirrors/node/,需要其他版本的就把下面这些命令的版本名替换一下

执行命令:

cd 到需要保存的路径

wget https://npm.taobao.org/mirrors/node/v10.16.3/node-v10.16.3-linux-x64.tar.gz

mv node-v10.16.3-linux-x64 nodejs

设置一下环境变量:

vim /etc/profile

添加(因为我按照的路径是root/nodejs)
export NODE_HOME=/root/nodejs
export PATH=$PATH:$NODE_HOME/bin
export NODE_PATH=$NODE_HOME/lib/node_modules

保存后退出 执行 source /etc/profile

检查是否安装成功:node -v

正常会显示nodejs版本号

 

 

mongodb:

centos:

打开https://www.mongodb.com/download-center/community

选择server和os(ubuntu的应该要选择ubuntu,因为我在ubuntu安装的时候会报很多.os缺失的错)

复制下面的下载地址

cd 到需要保存的路径

执行命令curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-4.2.0.tgz

tar -zxvf mongodb-linux-x86_64-amazon-4.2.0.tgz

mv mongodb-linux-x86_64-amazon-4.2.0/ ./mongodb

cd mongodb

mkdir data

mkdir data/db

mkdir data/logs

启动:

在mongodb目录下运行(--fork是后台常住)
sudo ./bin/mongod --dbpath=./data/db  --fork --logpath=./data/logs

如果是需要配置文件的话(方便点,配置外网访问)

vim mongodb.conf

输入:

# mongodb.conf

# Where to store the data.
dbpath=/var/lib/mongodb

#where to log
logpath=/var/log/mongodb/mongodb.log

logappend=true

bind_ip = 0.0.0.0
#port = 27017

# Enable journaling, http://www.mongodb.org/display/DOCS/Journaling
journal=true

# Enables periodic logging of CPU utilization and I/O wait
#cpu = true

# Turn on/off security.  Off is currently the default
#noauth = true
#auth = true

# Verbose logging output.
#verbose = true

# Inspect all client data for validity on receipt (useful for
# developing drivers)
#objcheck = true

# Enable db quota management
#quota = true

# Set oplogging level where n is
#   0=off (default)
#   1=W
#   2=R
#   3=both
#   7=W+some reads
#oplog = 0

# Diagnostic/debugging option
#nocursors = true

# Ignore query hints
#nohints = true

# Disable the HTTP interface (Defaults to localhost:27018).
#nohttpinterface = true

# Turns off server-side scripting.  This will result in greatly limited
# functionality
#noscripting = true

# Turns off table scans.  Any query that would do a table scan fails.
#notablescan = true

# Disable data file preallocation.
#noprealloc = true

# Specify .ns file size for new databases.
# nssize = <size>

# Accout token for Mongo monitoring server.
#mms-token = <token>

# Server name for Mongo monitoring server.
#mms-name = <server-name>

# Ping interval for Mongo monitoring server.
#mms-interval = <seconds>

# Replication Options

# in replicated mongo databases, specify here whether this is a slave or master
#slave = true
#source = master.example.com
# Slave only: specify a single database to replicate
#only = master.example.com
# or
#master = true
#source = slave.example.com

# Address of a server to pair with.
#pairwith = <server:port>
# Address of arbiter server.
#arbiter = <server:port>
# Automatically resync if slave data is stale
#autoresync
# Custom size for replication operation log.
#oplogSize = <MB>
# Size limit for in-memory storage of op ids.
#opIdMem = <bytes>

# SSL options
# Enable SSL on normal ports
#sslOnNormalPorts = true
# SSL Key file and password
#sslPEMKeyFile = /etc/ssl/mongodb.pem
#sslPEMKeyPassword = pass

:wq保存

sudo ./bin/mongod --config ./mongodb.conf

 

ubuntu:

上面centos的方式会报错,因为我也没有选择ubuntu版本的mongodb

直接 sudo apt-get install mongodb,腾讯云服务器的版本是2.6,有点旧。。

正常安装的话会配置文件在/etc/mongdb.conf 

 

 

需要外网也能访问到mongodb需要把mongdb.conf 配置文件的bind_ip改成0.0.0.0

添加用户名密码配置参考:https://www.cnblogs.com/JennySchecter/p/8540832.html

在指定的数据库db.createUser添加读写权限的用户就行了,不用管admin。

使用账号密码连接:mongodb://user:pwd@localhost:27017/dbname

 

################################################################################

 

服务器部署:

使用git clone 把项目更新下来之后,root权限NPM全局安装(-g)仍会权限不够,添加 --unsafe-perm
npm install --unsafe-perm

使用pm2管理nodejs的服务器(后台的方式启动和停止服务器):https://www.jianshu.com/p/ee935729f49c ---> 四. 利用 nodejs pm2

启动:pm2 start xxx_server.js

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值