ubuntu16.04 下安装mongodb3.4.4
来源:互联网 发布:中古欧洲民谣知乎 编辑:程序博客网 时间:2024/06/05 21:51
环境:
ideal@ideal-PowerEdge-R730xd:~$ cat /etc/issueUbuntu 16.04.2 LTS \n \l
看看本机是否有mongodb,有则删除
ideal@ideal-PowerEdge-R730xd:~$ sudo apt-get autoremove --purge mongodbReading package lists... DoneBuilding dependency tree Reading state information... DonePackage 'mongodb' is not installed, so not removedThe following packages will be REMOVED: javascript-common* libboost-program-options1.58.0* libboost-thread1.58.0* libexpat1-dev* libgoogle-perftools4* libjs-jquery* libmysqlclient20* libpcrecpp0v5* libpython-all-dev* libpython-dev* libpython2.7-dev* libsnappy1v5* libtcmalloc-minimal4* libv8-3.14.5* libyaml-cpp0.5v5* mongodb-clients* mongodb-server* mysql-common* python-django-common* python-pip-whl* python2.7-dev*0 upgraded, 0 newly installed, 21 to remove and 88 not upgraded.After this operation, 259 MB disk space will be freed.Do you want to continue? [Y/n] y # 这里输入“y”(Reading database ... 216448 files and directories currently installed.)……
接下来就开始安装
1. 导入MongoDB公共GPG密钥sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
2. 创建/etc/apt/sources.list.d/mongodb3.4-org 名单列表文件echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
3. 重新加载本地包数据库sudo apt-get update
4. 安装MongoDB包 sudo apt-get install -y mongodb-org
5. 我们需要简单配置下,编辑/etc/mongod.conf
ideal@ideal-PowerEdge-R730xd:~$ sudo vim /etc/mongod.conf
mongod.conf 文件如下:
# mongod.conf# for documentation of all options, see:# http://docs.mongodb.org/manual/reference/configuration-options/# Where and how to store data.storage: dbPath: /var/lib/mongodb # mongodb的数据存放目录 journal: enabled: true# engine:# mmapv1:# wiredTiger:# where to write logging data.systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log # 日志存放目录# network interfacesnet: port: 27017 # 设置访问端口,默认27017 bindIp: 192.168.255.1 # 绑定ip,默认127.0.0.1#processManagement:#security:#operationProfiling:#replication:#sharding:## Enterprise-Only Options:#auditLog:#snmp:
编辑完之后source 一下
ideal@ideal-PowerEdge-R730xd:~$ source /etc/mongod.conf
现在我们的mongodb已经安装成功了, 我们来启动下
ideal@ideal-PowerEdge-R730xd:~$ sudo service mongod start
接着我们看看是否可以打开mongodb shell 客户端:
ideal@ideal-PowerEdge-R730xd:~$ mongo 192.168.255.1:27017MongoDB shell version v3.4.4connecting to: 192.168.255.1:27017MongoDB server version: 3.4.4Server has startup warnings: 2017-06-08T10:19:16.241+0800 I CONTROL [initandlisten] 2017-06-08T10:19:16.241+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.2017-06-08T10:19:16.241+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.2017-06-08T10:19:16.241+0800 I CONTROL [initandlisten] 2017-06-08T10:19:16.242+0800 I CONTROL [initandlisten] 2017-06-08T10:19:16.242+0800 I CONTROL [initandlisten] ** WARNING: You are running on a NUMA machine.2017-06-08T10:19:16.242+0800 I CONTROL [initandlisten] ** We suggest launching mongod like this to avoid performance problems:2017-06-08T10:19:16.242+0800 I CONTROL [initandlisten] ** numactl --interleave=all mongod [other options]2017-06-08T10:19:16.242+0800 I CONTROL [initandlisten] 2017-06-08T10:19:16.242+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.2017-06-08T10:19:16.242+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'2017-06-08T10:19:16.242+0800 I CONTROL [initandlisten] > show dbsadmin 0.078GBlocal 0.078GB>
shell 客户端还可以这样启动:
ideal@ideal-PowerEdge-R730xd:~$ mongo -host 192.168.255.1 -port 27017
介绍几个管理命令吧:
启动mongod 服务:
sudo service mongod start
查看mongod 服务状态:
sudo service mongod status
停止mongod 服务:
sudo service mongod stop
重启mongod 服务:
sudo service mongod restart
卸载mongodb:
sudo apt-get purge mongodb-org*sudo rm -r /var/log/mongodbsudo rm -r /var/lib/mongodb
这里没有配置帐户和密码,而且只搭了一台,也可以搭一个mongodb集群,设置主从,支持切片操作。这里有以前写的数据导出文章点击此处。本文只是作为笔记。。。
记录一个centos下mongodb的错误:
错误原因是因为我用kill -9 xxxx”杀死了mongodb的进程;重新启动会报如下错误:
[root@crawl ~]# mongod -f /etc/mongod.conf &[1] 3056[root@crawl ~]# about to fork child process, waiting until server is ready for connections.forked process: 3058ERROR: child process failed, exited with error number 100
我的解决办法就是删除mongod.lock 文件
[root@crawl ~]# locate mongod.lock/var/lib/mongo/mongod.lock[root@crawl ~]# cd /var/lib/mongo/[root@crawl mongo]# lsjournal local.0 local.ns mongod.lock SinaComment3.0 SinaComment3.1 SinaComment3.ns storage.bson[root@crawl mongo]# rm mongod.lock rm: remove regular file 'mongod.lock'? y[root@crawl mongo]#
然后重启mongod
[root@crawl mongo]# mongod -f /etc/mongod.conf &[1] 13140[root@crawl mongo]# about to fork child process, waiting until server is ready for connections.forked process: 13143child process started successfully, parent exiting^C[1]+ Done mongod -f /etc/mongod.conf[root@crawl mongo]#
问题以解决,打开mongo shell看看
[root@crawl mongo]# mongo 192.168.255.151:27017MongoDB shell version: 3.0.14connecting to: 192.168.100.151:27017/testServer has startup warnings: 2017-06-15T10:15:01.737+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.2017-06-15T10:15:01.737+0800 I CONTROL [initandlisten] 2017-06-15T10:15:01.737+0800 I CONTROL [initandlisten] 2017-06-15T10:15:01.737+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.2017-06-15T10:15:01.737+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'2017-06-15T10:15:01.737+0800 I CONTROL [initandlisten] 2017-06-15T10:15:01.737+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.2017-06-15T10:15:01.737+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'2017-06-15T10:15:01.737+0800 I CONTROL [initandlisten] 2017-06-15T10:15:01.737+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 200153 processes, 1024000 files. Number of processes should be at least 512000 : 0.5 times number of files.2017-06-15T10:15:01.737+0800 I CONTROL [initandlisten] > show dbsSinaComment3 0.203GBlocal 0.078GB> exitbye[root@crawl mongo]
正常关闭mongodb如下:
先通过shell连上服务器:
mongo
use admin
db.shutdownServer()
这种方法必须是有用户认证,否则会报错
或者直接kill -15 ,注意kill -9 可能会导致数据文件损坏
参考文章https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
如有疑问请加qq群:526855734
- ubuntu16.04 下安装mongodb3.4.4
- ubuntu14.04安装mongodb3.4.4
- Centos7 安装mongodb3.4.4
- Centos7 安装mongodb3.4.4
- Linux下安装Mongodb3.0
- linux下安装mongodb3.2.4
- Linux下安装MongoDB3.2.5
- Linux下MongoDB3.2.9安装
- lunix 下安装mongodb3.4
- ubuntu16.04下安装mariadb
- Ubuntu16.04下安装Matlab
- Ubuntu16.04下openface安装
- Ubuntu16.04下安装matlab2014a
- ubuntu16.04下安装caffe
- ubuntu16.04下安装mysql
- ubuntu16.04下安装opencv
- ubuntu16.04下安装xgboost
- ubuntu16.04下安装docker
- Android案例《新闻客户端》
- 【视频开发】【电子电路技术】监控球机PTZ的功能介绍
- 神经网络中 BP 算法的原理与 PYTHON 实现源码解析
- WordPress主题制作全过程(三):HTML静态模板制作
- 使用Genymotion替代Android Studio开发调试
- ubuntu16.04 下安装mongodb3.4.4
- Android 让 WebView 响应下载点击事件
- Nginx代理服务和负载均衡
- CSS清除浮动
- Visual Studio中的环境变量(以Visual Studio 2013为例)
- 终端连接oschina 生成SSH公钥
- Android 6.0 运行时权限处理
- MAC OS X10.10WiFi连接问题的修复方法:
- Android中的sp和wp指针