ubuntu nodejs+mongodb环境配置

来源:互联网 发布:网络语 打脸 什么意思 编辑:程序博客网 时间:2024/05/14 12:16

安装nodejs

# apt-get update  # apt-get install -y python-software-properties software-properties-common  # add-apt-repository ppa:chris-lea/node.js  # apt-get update  # apt-get install nodejs  

安装npm

# apt-get install npm

安装pm2

# npm install -g pm2

设置pm2为自启动

# pm2 startup upstart

安装mongodb

# apt-get install mongodb

启动/停止

/etc/init.d/mongodb start/etc/init.d/mongodb stop

确认是否启动成功

netstat -antup cat /var/log/mongodb/mongodb.log

修改路径

vi /etc/mongodb.conf dbpath=/www/mongodbvi /etc/init.d/mongodb DATA=/www/mongodbmkdir /www/mongodb/ chown -R mongodb:nogroup /www/mongodb/

后台自启动

服务后台自动启动进入/usr/bin/下输入以下命令./mongod --dbpath /var/lib/mongodb/ --logpath /var/log/mongodb/mongodb.log --logappend &后台运行程序

设置数据库连接密码

重新启动服务    $ mongod –auth  创建连接用户    $ mongo    > use admin    switched to db admin    > db.addUser("root","1983")  关闭服务(直接在 mongod 启动的命令窗口 “ctrl + C”)  重启服务:    $: mongod –auth  查看是否开始验证:、    $ mongo    MongoDB shell version: 2.0.4    connecting to: test    > use admin    switched to db admin    > show collections    Fri Mar 14 09:07:08 uncaught exception: error: {    "$err" : "unauthorized db:admin lock type:-1 client:127.0.0.1",    "code" : 10057    }  有提示 链接错误。  进行用户验证:    > db.auth("root","1983")    1  重新查看就可以查看数据集    > show collections    system.indexes    system.users

安装git

# apt-get install git# apt-get install git-core
0 0
原创粉丝点击